Skip to content

Commit

Permalink
fixed claim button issue
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed May 7, 2024
1 parent 5a5f91b commit 573925d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data class OptionsModel(
enum class DefaultOutcomesID {
DEFAULT_START_WORKFLOW,
DEFAULT_SAVE,
DEFAULT_CLAIM,
DEFAULT_COMPLETE,
;
fun value() = name.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<OptionsModel>, fragment: ProcessFragment, viewModel: FormViewModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data class FormViewState(
val requestContent: Async<Entry> = Uninitialized,
val requestAccountInfo: Async<ResponseAccountInfo> = Uninitialized,
val requestProfile: Async<ProfileData> = Uninitialized,
val requestClaimRelease: Async<Response<Unit>> = Uninitialized,
) : MavericksState {
constructor(target: ProcessEntry) : this(parent = target)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 573925d

Please sign in to comment.