diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/tasks/detail/TaskDetailExtension.kt b/browse/src/main/kotlin/com/alfresco/content/browse/tasks/detail/TaskDetailExtension.kt index dc12c2c9..e11449db 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/tasks/detail/TaskDetailExtension.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/tasks/detail/TaskDetailExtension.kt @@ -100,7 +100,7 @@ internal fun TaskDetailFragment.setTaskDetailAfterResponse(dataObj: TaskEntry) = when (dataObj.memberOfCandidateGroup) { true -> { if (dataObj.assignee?.id == null || dataObj.assignee?.id == 0) { - makeClaimButton() +// makeClaimButton() } else if (viewModel.isAssigneeAndLoggedInSame(dataObj.assignee)) { menuDetail.findItem(R.id.action_release).isVisible = true // makeOutcomes() diff --git a/data/src/main/kotlin/com/alfresco/content/data/OptionsModel.kt b/data/src/main/kotlin/com/alfresco/content/data/OptionsModel.kt index 4250f353..eb6cef65 100644 --- a/data/src/main/kotlin/com/alfresco/content/data/OptionsModel.kt +++ b/data/src/main/kotlin/com/alfresco/content/data/OptionsModel.kt @@ -50,6 +50,7 @@ data class OptionsModel( enum class DefaultOutcomesID { DEFAULT_START_WORKFLOW, DEFAULT_SAVE, + DEFAULT_CLAIM, DEFAULT_COMPLETE, ; fun value() = name.lowercase() diff --git a/process-app/src/main/kotlin/com/alfresco/content/process/ui/components/FloatingActionButton.kt b/process-app/src/main/kotlin/com/alfresco/content/process/ui/components/FloatingActionButton.kt index a4663f00..d9c5bd37 100644 --- a/process-app/src/main/kotlin/com/alfresco/content/process/ui/components/FloatingActionButton.kt +++ b/process-app/src/main/kotlin/com/alfresco/content/process/ui/components/FloatingActionButton.kt @@ -2,7 +2,6 @@ package com.alfresco.content.process.ui.components import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.PlaylistAdd -import androidx.compose.material3.ColorScheme import androidx.compose.material3.ExtendedFloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme @@ -20,7 +19,6 @@ import com.alfresco.content.data.payloads.FieldType import com.alfresco.content.process.R import com.alfresco.content.process.ui.fragments.FormViewModel import com.alfresco.content.process.ui.fragments.ProcessFragment -import com.alfresco.content.process.ui.theme.White60 @Composable fun FloatingActionButton(outcomes: List, fragment: ProcessFragment, viewModel: FormViewModel) { diff --git a/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScreen.kt b/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScreen.kt index 4bf89aea..b3a6471a 100644 --- a/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScreen.kt +++ b/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScreen.kt @@ -28,9 +28,20 @@ fun FormScreen(navController: NavController, viewModel: FormViewModel, fragment: val state by viewModel.collectAsState() + val task = state.parent.taskEntry + val customOutcomes = when { state.formFields.isEmpty() -> emptyList() state.processOutcomes.isEmpty() -> defaultOutcomes(state) + task.assignee?.id == 0 -> { + listOf( + OptionsModel( + id = DefaultOutcomesID.DEFAULT_CLAIM.value(), + name = stringResource(id = R.string.action_menu_claim), + ), + ) + } + else -> customOutcomes(state) } diff --git a/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScrollContent.kt b/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScrollContent.kt index 007fd3be..ddf7c73b 100644 --- a/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScrollContent.kt +++ b/process-app/src/main/kotlin/com/alfresco/content/process/ui/composeviews/FormScrollContent.kt @@ -165,7 +165,7 @@ fun FormScrollContent(field: FieldsData, viewModel: FormViewModel, state: FormVi viewModel = viewModel, fieldsData = field, onUserTap = { - if (it && field.value is List<*>) { + if (it && field.value is List<*> && (field.value as List<*>).isNotEmpty()) { val bundle = Bundle().apply { putParcelable( Mavericks.KEY_ARG, diff --git a/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewModel.kt b/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewModel.kt index 0bf5da5c..cb451ef6 100644 --- a/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewModel.kt +++ b/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewModel.kt @@ -305,10 +305,36 @@ class FormViewModel( DefaultOutcomesID.DEFAULT_START_WORKFLOW.value() -> startWorkflow() DefaultOutcomesID.DEFAULT_COMPLETE.value() -> completeTask() DefaultOutcomesID.DEFAULT_SAVE.value() -> saveForm() + DefaultOutcomesID.DEFAULT_CLAIM.value() -> claimTask() else -> actionOutcome(optionsModel.outcome) } } + /** + * execute API to claim the task + */ + private fun claimTask() = withState { state -> + requireNotNull(state.parent) + viewModelScope.launch { + repository::claimTask.asFlow(state.parent.taskEntry.id).execute { + when (it) { + is Loading -> copy(requestClaimRelease = Loading()) + is Fail -> { + copy(requestClaimRelease = Fail(it.error)) + } + + is Success -> { + copy(requestClaimRelease = Success(it())) + } + + else -> { + this + } + } + } + } + } + private fun completeTask() = withState { state -> viewModelScope.launch { repository::actionCompleteOutcome.asFlow(state.parent.taskEntry.id, convertFieldsToValues(state.formFields)).execute { diff --git a/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewState.kt b/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewState.kt index 52b15f0a..27fd4a3a 100644 --- a/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewState.kt +++ b/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/FormViewState.kt @@ -30,6 +30,7 @@ data class FormViewState( val requestContent: Async = Uninitialized, val requestAccountInfo: Async = Uninitialized, val requestProfile: Async = Uninitialized, + val requestClaimRelease: Async> = Uninitialized, ) : MavericksState { constructor(target: ProcessEntry) : this(parent = target) diff --git a/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/ProcessFragment.kt b/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/ProcessFragment.kt index 8407f3e6..7f574704 100644 --- a/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/ProcessFragment.kt +++ b/process-app/src/main/kotlin/com/alfresco/content/process/ui/fragments/ProcessFragment.kt @@ -154,7 +154,8 @@ class ProcessFragment : Fragment(), MavericksView, EntryListener { state.requestAccountInfo is Loading || state.requestContent is Loading when { - state.requestStartWorkflow is Success || state.requestSaveForm is Success || state.requestOutcomes is Success -> { + state.requestStartWorkflow is Success || state.requestSaveForm is Success || + state.requestOutcomes is Success || state.requestClaimRelease is Success -> { viewModel.updateProcessList() requireActivity().finish() }