Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADST-431 #344

Merged
merged 6 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.ViewModelContext
import com.alfresco.content.actions.Action
import com.alfresco.content.actions.ActionOpenWith
import com.alfresco.content.actions.ActionUpdateNameDescription
import com.alfresco.content.common.EntryListener
import com.alfresco.content.component.ComponentMetaData
import com.alfresco.content.data.Entry
Expand Down Expand Up @@ -48,9 +47,9 @@ class ProcessDetailViewModel(
entryListener?.onEntryCreated(it.entry)
}
}
viewModelScope.on<ActionUpdateNameDescription> {
setState { copy(parent = it.entry as ProcessEntry) }
}
// viewModelScope.on<ActionUpdateNameDescription> {
// setState { copy(parent = it.entry as ProcessEntry) }
// }

fetchUserProfile()
fetchAccountInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const val DATE_FORMAT_3 = "yyyy-MM-dd'T'hh:mm:ss.SSSZ"
const val DATE_FORMAT_3_1 = "yyyy-MM-dd'T'hh:mm:ssZ"
const val DATE_FORMAT_4 = "dd MMM yyyy"
const val DATE_FORMAT_4_1 = "dd MMM yyyy hh:mm a"
const val DATE_FORMAT_5 = "yyyy-MM-dd'T'HH:mm:ss'Z'"
const val DATE_FORMAT_5 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
const val DATE_FORMAT_6 = "yyyy-MM-dd'T'HH:mm:ss"
const val DATE_FORMAT_7 = "dd MMM,yyyy hh:mm:ss a"
const val DATE_FORMAT_8 = "dd-MM-yyyy hh:mm:ss a"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ data class DatePickerBuilder(
if (fieldsData?.type == FieldType.DATETIME.value()) {
stringDateTime = getFormatDate(date)
timePicker.show(fragmentManager, DatePickerBuilder::class.java.name)
} else if (fieldsData?.type == FieldType.DATE.value()) {
} else {
onSuccess?.invoke(getFormatDate(date))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ data class TaskEntry(
processDefinitionId = data.processDefinitionId,
processInstanceStartUserId = data.processInstanceStartUserId,
memberOfCandidateGroup = data.memberOfCandidateGroup,
formattedDueDate = data.dueDate?.toLocalDate()?.toString(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ fun convertModelToMapValues(data: UserGroupDetails?) =
}

fun convertModelToMapValues(data: FieldsData): Map<String, Any?> {
if (data.value == null) {
return mapOf()
}
val id = data.options.find { it.name == data.value }?.id
requireNotNull(id)
return mapOf<String, Any?>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ data class FieldsData(
return userGroupDetails
}

fun getDate(serverFormat: String, localFormat: String): Pair<String, String> {
val dateTime = value as? String ?: ""

if (dateTime.isNotEmpty() && dateTime.contains("T")) {
return Pair(dateTime.split("T").firstOrNull() ?: "", serverFormat)
}

return Pair(dateTime, localFormat)
}

companion object {
/**
* returns the FieldsData obj by using Fields obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ fun DateTimeField(

when (fieldsData.type.lowercase()) {
FieldType.DATE.value() -> {
if (dateTime.isNotEmpty() && dateTime.contains("T")) {
val date = dateTime.split("T").firstOrNull() ?: ""
if (date.isNotEmpty()) {
val dateFormat = updateDateFormat(fieldsData.params?.field?.dateDisplayFormat) ?: DATE_FORMAT_2_1
dateTime = date.getLocalFormattedDate(DATE_FORMAT_1, dateFormat)
}
val date = fieldsData.getDate(DATE_FORMAT_1, DATE_FORMAT_2_1)
if (date.first.isNotEmpty()) {
val dateFormat = updateDateFormat(fieldsData.params?.field?.dateDisplayFormat) ?: DATE_FORMAT_2_1
dateTime = date.first.getLocalFormattedDate(date.second, dateFormat)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.alfresco.content.process.ui.components.ReadOnlyField
import com.alfresco.content.process.ui.components.SingleLineInputField
import com.alfresco.content.process.ui.fragments.FormViewModel
import com.alfresco.content.process.ui.fragments.FormViewState
import com.alfresco.content.process.ui.utils.actionsReadOnlyField
import com.alfresco.content.process.ui.utils.amountInputError
import com.alfresco.content.process.ui.utils.booleanInputError
import com.alfresco.content.process.ui.utils.dateTimeInputError
Expand Down Expand Up @@ -183,21 +184,7 @@ fun FormScrollContent(field: FieldsData, viewModel: FormViewModel, state: FormVi
viewModel = viewModel,
fieldsData = field,
onUserTap = {
if (it && field.value is List<*> && (field.value as List<*>).isNotEmpty()) {
val bundle = Bundle().apply {
putParcelable(
Mavericks.KEY_ARG,
UploadData(
field = field,
process = state.parent,
),
)
}
navController.navigate(
R.id.action_nav_process_form_to_nav_attach_files,
bundle,
)
}
actionsReadOnlyField(it, field, navController, state, context)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.ViewModelContext
import com.alfresco.content.DATE_FORMAT_1
import com.alfresco.content.DATE_FORMAT_2_1
import com.alfresco.content.DATE_FORMAT_4_1
import com.alfresco.content.DATE_FORMAT_5
Expand Down Expand Up @@ -495,7 +496,7 @@ class FormViewModel(
FieldType.PEOPLE.value(), FieldType.FUNCTIONAL_GROUP.value() -> {
when {
field.value != null -> {
values[field.id] = convertModelToMapValues(field.value as? UserGroupDetails)
values[field.id] = convertModelToMapValues(field.getUserGroupDetails(getAPSUser()))
}

else -> {
Expand All @@ -510,7 +511,8 @@ class FormViewModel(
}

FieldType.DATE.value() -> {
val convertedDate = (field.value as? String)?.getFormattedDate(DATE_FORMAT_2_1, DATE_FORMAT_5)
val date = field.getDate(DATE_FORMAT_1, DATE_FORMAT_2_1)
val convertedDate = date.first.takeIf { it.isNotEmpty() }?.getFormattedDate(date.second, DATE_FORMAT_5) ?: ""
values[field.id] = convertedDate
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ class ProcessFragment : Fragment(), MavericksView, EntryListener {
private var menu: Menu? = null
private var isExecuted = false
private var confirmContentQueueDialog = WeakReference<AlertDialog>(null)
private var oldSnackbar: Snackbar? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}

fun showSnackBar(message: String) {
Snackbar.make(binding.root, message, Snackbar.LENGTH_SHORT).show()
private fun showSnackBar(message: String) {
val snackbar = Snackbar.make(binding.flComposeParent, message, Snackbar.LENGTH_SHORT)
if (oldSnackbar == null || oldSnackbar?.isShownOrQueued == false) {
oldSnackbar?.dismiss()
snackbar.show()
oldSnackbar = snackbar
}
}

override fun onCreateView(
Expand Down Expand Up @@ -166,9 +172,13 @@ class ProcessFragment : Fragment(), MavericksView, EntryListener {
state.requestForm is Success -> {
val hasUploadField = state.formFields.any { it.type == FieldType.UPLOAD.value() }

if (hasUploadField && state.parent.defaultEntries.isNotEmpty()) {
viewModel.fetchUserProfile()
viewModel.fetchAccountInfo()
if (state.parent.defaultEntries.isNotEmpty()) {
if (hasUploadField) {
viewModel.fetchUserProfile()
viewModel.fetchAccountInfo()
} else {
showSnackBar(getString(R.string.error_no_upload_fields))
}
}

if (hasUploadField) {
Expand Down Expand Up @@ -218,9 +228,6 @@ class ProcessFragment : Fragment(), MavericksView, EntryListener {

override fun onAttachFiles(field: FieldsData) = withState(viewModel) { state ->
if (isAdded && field.type == FieldType.UPLOAD.value()) {
// val serverUploads = field.getContentList().filter { it.uploadServer == UploadServerType.UPLOAD_TO_PROCESS }
// .filterNot { item -> deletedFiles.any { it.value.id == item.id } }

val listContents = mergeInUploads(field.getContentList(state.parent.processDefinitionId), viewModel.getContents(state, field.id))
val isError = field.required && listContents.isEmpty()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.alfresco.content.process.ui.utils

import android.content.Context
import android.os.Bundle
import androidx.navigation.NavController
import com.airbnb.mvrx.Mavericks
import com.alfresco.content.component.ComponentBuilder
import com.alfresco.content.component.ComponentData
import com.alfresco.content.component.ComponentType
import com.alfresco.content.data.payloads.FieldType
import com.alfresco.content.data.payloads.FieldsData
import com.alfresco.content.data.payloads.UploadData
import com.alfresco.content.process.R
import com.alfresco.content.process.ui.fragments.FormViewState

fun actionsReadOnlyField(
isTapped: Boolean,
field: FieldsData,
navController: NavController,
state: FormViewState,
context: Context,
) {
when (field.params?.field?.type?.lowercase()) {
FieldType.UPLOAD.value() -> {
if (isTapped && field.value is List<*> && (field.value as List<*>).isNotEmpty()) {
val bundle = Bundle().apply {
putParcelable(
Mavericks.KEY_ARG,
UploadData(
field = field,
process = state.parent,
),
)
}
navController.navigate(
R.id.action_nav_process_form_to_nav_attach_files,
bundle,
)
}
}

FieldType.TEXT.value(), FieldType.MULTI_LINE_TEXT.value() -> {
ComponentBuilder(
context,
ComponentData(
name = field.name,
query = "",
value = field.value as? String ?: "",
selector = ComponentType.VIEW_TEXT.value,
),
)
.onApply { name, query, _ ->
}
.onReset { name, query, _ ->
}
.onCancel {
}
.show()
}
}
}
1 change: 1 addition & 0 deletions process-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<string name="file_empty_message">Looks like you haven’t\nadded any files yet.</string>
<string name="title_search_folder">Search Folder</string>
<string name="error_hyperlink_invalid_url">%1$s has Invalid URL</string>
<string name="error_no_upload_fields">Not able to attach the selected content in this form.</string>
</resources>
Loading