Skip to content

Commit

Permalink
added action for start process and also added required options on she…
Browse files Browse the repository at this point in the history
…et in multi-action (#279)
  • Loading branch information
aman-alfresco authored Jul 26, 2023
1 parent d49cbcf commit 3ade100
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.alfresco.content.data.ParentEntry
*/
data class ActionStartProcess(
override val entry: Entry,
override val entries: List<Entry> = emptyList(),
override val icon: Int = R.drawable.ic_start_workflow,
override val title: Int = R.string.action_start_workflow,
override val eventName: EventName = EventName.StartWorkflow,
Expand All @@ -20,9 +21,14 @@ data class ActionStartProcess(
return entry
}

override suspend fun executeMulti(context: Context): Pair<ParentEntry, List<Entry>> {
return Pair(entry, entries)
}

override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry)

override fun showToast(view: View, anchorView: View?) =
override fun copy(_entries: List<Entry>): Action = copy(entries = _entries)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_workflow_started)
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ class ContextualActionsSheet : BottomSheetDialogFragment(), MavericksView {
withState(viewModel) { newState ->
if (!newState.isMultiSelection) {
viewModel.execute(it)
} else if (it is ActionDelete || it is ActionRestore || it is ActionDeleteForever ||
it is ActionMoveFilesFolders || it is ActionAddOffline || it is ActionRemoveOffline ||
it is ActionAddFavorite || it is ActionRemoveFavorite
) {
viewModel.executeMulti(it)
MultiSelection.multiSelectionChangedFlow.tryEmit(MultiSelectionData(isMultiSelectionEnabled = false))
} else {
viewModel.executeMulti(it)
MultiSelection.multiSelectionChangedFlow.tryEmit(MultiSelectionData(isMultiSelectionEnabled = false))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class ContextualActionsViewModel(

private fun buildModelForMultiSelection() = withState { state ->
// If entry is partial and not in the offline tab
setState { copy(entries = state.entries, actions = makeMultiActions(getFilteredEntries(state.entries), state), topActions = emptyList()) }
setState { copy(entries = state.entries, actions = makeMultiActions(state), topActions = emptyList()) }
}

private fun updateState(action: Action) {
setState {
val entry = action.entry as Entry
ContextualActionsState(
entries = if (isMultiSelection) action.entries else listOf(entry),
actions = if (isMultiSelection) makeMultiActions(action.entries, this) else makeActions(entry),
actions = if (isMultiSelection) makeMultiActions(this) else makeActions(entry),
topActions = makeTopActions(entry),
)
}
Expand Down Expand Up @@ -106,7 +106,7 @@ class ContextualActionsViewModel(
}
}

fun makeMultiActions(filteredEntries: List<Entry>, state: ContextualActionsState): List<Action> {
fun makeMultiActions(state: ContextualActionsState): List<Action> {
val actions = mutableListOf<Action>()
val entry = Entry.withSelectedEntries(state.entries)

Expand All @@ -117,40 +117,44 @@ class ContextualActionsViewModel(
}

state.entries.all { it.hasOfflineStatus } -> {
actions.add(offlineMultiActionFor(entry, state.entries))
processMultiActionFor(entry, state.entries)?.let { action ->
actions.add(action)
}
// Added Favorite Action
actions.addAll(sharedActions(entry, state.entries))
}

else -> {
// Added Favorite Action
if (filteredEntries.any { !it.isFavorite }) {
actions.add(ActionAddFavorite(entry, state.entries))
} else {
actions.add(ActionRemoveFavorite(entry, state.entries))
}
actions.addAll(sharedActions(entry, state.entries))
}
}

// Added Start Process Action
processMultiActionFor(entry, filteredEntries)?.let { action ->
actions.add(action)
}
return actions
}

// Added Move Action
if (isMoveDeleteAllowed(filteredEntries)) {
actions.add(ActionMoveFilesFolders(entry, state.entries))
}
private fun sharedActions(entry: Entry, entries: List<Entry>): List<Action> {
val actions = mutableListOf<Action>()
// Added Favorite Action
if (entries.any { !it.isFavorite }) {
actions.add(ActionAddFavorite(entry, entries))
} else {
actions.add(ActionRemoveFavorite(entry, entries))
}

// Added Offline Action
actions.add(offlineMultiActionFor(entry, state.entries))
// Added Start Process Action
processMultiActionFor(entry, entries)?.let { action ->
actions.add(action)
}

// Added Delete Action
if (isMoveDeleteAllowed(filteredEntries)) {
actions.add((ActionDelete(entry, state.entries)))
}
}
// Added Move Action
if (isMoveDeleteAllowed(entries)) {
actions.add(ActionMoveFilesFolders(entry, entries))
}

// Added Offline Action
actions.add(offlineMultiActionFor(entry, entries))

// Added Delete Action
if (isMoveDeleteAllowed(entries)) {
actions.add((ActionDelete(entry, entries)))
}
return actions
}

Expand Down Expand Up @@ -179,7 +183,7 @@ class ContextualActionsViewModel(

private fun processMultiActionFor(entry: Entry, entries: List<Entry>): Action? {
if (settings.isProcessEnabled && (entries.isNotEmpty() && entries.all { it.isFile })) {
return ActionStartProcess(entry)
return ActionStartProcess(entry, entries)
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {
}
}

override fun onProcessStart(entry: ParentEntry) {
override fun onProcessStart(entries: List<ParentEntry>) {
if (isAdded && isVisible) {
ProcessDefinitionsSheet.with(entry as Entry).show(parentFragmentManager, null)
ProcessDefinitionsSheet.with(entries.map { it as Entry }).show(parentFragmentManager, null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ class OfflineFragment : ListFragment<OfflineViewModel, OfflineViewState>() {
}
}

override fun onProcessStart(entry: ParentEntry) {
override fun onProcessStart(entries: List<ParentEntry>) {
if (isAdded && isVisible) {
ProcessDefinitionsSheet.with(entry as Entry).show(parentFragmentManager, null)
ProcessDefinitionsSheet.with(entries.map { it as Entry }).show(parentFragmentManager, null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.alfresco.events.on
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.util.UUID
import java.util.*

/**
* Marked as ProcessDetailViewModel
Expand All @@ -39,6 +39,7 @@ class ProcessDetailViewModel(
private var observeUploadsJob: Job? = null
var entryListener: EntryListener? = null
var observerID: String = ""
private var isExecuted = false

init {
observerID = UUID.randomUUID().toString()
Expand Down Expand Up @@ -220,8 +221,9 @@ class ProcessDetailViewModel(
is Loading -> copy(requestProfile = Loading())
is Fail -> copy(requestProfile = Fail(it.error))
is Success -> {
repository.saveProcessUserDetails(it())
copy(requestProfile = Success(it()))
val response = it()
repository.saveProcessUserDetails(response)
copy(requestProfile = Success(response))
}

else -> {
Expand All @@ -239,12 +241,17 @@ class ProcessDetailViewModel(
is Loading -> copy(requestAccountInfo = Loading())
is Fail -> copy(requestAccountInfo = Fail(it.error))
is Success -> {
repository.saveSourceName(it().listAccounts.first())
val sourceName = it().listAccounts.first().sourceName
state.parent?.defaultEntry?.let { entry ->
linkContentToProcess(entry, sourceName)
val response = it()

repository.saveSourceName(response.listAccounts.first())
val sourceName = response.listAccounts.first().sourceName
if (!isExecuted) {
isExecuted = true
state.parent?.defaultEntries?.map { entry ->
linkContentToProcess(entry, sourceName)
}
}
copy(requestAccountInfo = Success(it()))
copy(requestAccountInfo = Success(response))
}

else -> {
Expand All @@ -265,7 +272,8 @@ class ProcessDetailViewModel(
is Loading -> copy(requestTasks = Loading())
is Fail -> copy(requestTasks = Fail(it.error))
is Success -> {
updateTasks(it()).copy(requestTasks = Success(it()))
val response = it()
updateTasks(response).copy(requestTasks = Success(response))
}

else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ data class ProcessDetailViewState(
if (entry == null) {
return this
}
return copy(baseEntries = listOf(entry), listContents = listOf(entry))
println("data == 1 :: $entry")
println("data == 2 :: ${listContents.size}")

val list: List<Entry>
if (listContents.isNotEmpty()) {
list = listContents.toMutableList()
list.add(entry)
} else {
list = listOf(entry)
}

return copy(baseEntries = listOf(entry), listContents = list.distinct())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView {
id(it.id)
processDefinition(it)
clickListener { model, _, _, _ ->
val processEntry = ProcessEntry.with(model.processDefinition(), state.entry)
val processEntry = ProcessEntry.with(model.processDefinition(), state.entries)
startActivity(
Intent(requireActivity(), ProcessDetailActivity::class.java)
.putExtra(Mavericks.KEY_ARG, processEntry),
Expand All @@ -98,8 +98,8 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView {
/**
* returns the instance of ProcessDefinitionsSheet with attached entry as bundle
*/
fun with(entry: Entry? = null) = ProcessDefinitionsSheet().apply {
arguments = bundleOf(Mavericks.KEY_ARG to entry)
fun with(entrie: List<Entry> = emptyList()) = ProcessDefinitionsSheet().apply {
arguments = bundleOf(Mavericks.KEY_ARG to entrie)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.alfresco.content.data.RuntimeProcessDefinitionDataEntry
* Marked as ProcessDefinitionsState
*/
data class ProcessDefinitionsState(
val entry: Entry? = null,
val entries: List<Entry> = emptyList(),
val listProcessDefinitions: List<RuntimeProcessDefinitionDataEntry>? = null,
) : MavericksState {
constructor(target: Entry) : this(entry = target)
constructor(target: List<Entry>) : this(entries = target)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ internal class ProcessDefinitionsViewModel(
when (it) {
is Success -> {
ProcessDefinitionsState(
entry = state.entry,
entries = state.entries,
listProcessDefinitions = it().listRuntimeProcessDefinitions,
)
}

else -> {
ProcessDefinitionsState(
entry = state.entry,
entries = state.entries,
listProcessDefinitions = null,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class ProcessEntry(
val suspended: Boolean? = null,
var priority: Int = 0,
val formattedDueDate: String? = null,
val defaultEntry: Entry? = null,
val defaultEntries: List<Entry> = emptyList(),
val reviewerType: ReviewerType = ReviewerType.OTHER,
) : ParentEntry(), Parcelable {

Expand Down Expand Up @@ -66,12 +66,12 @@ data class ProcessEntry(
/**
* return the ProcessEntry using RuntimeProcessDefinitionDataEntry
*/
fun with(data: RuntimeProcessDefinitionDataEntry, entry: Entry?): ProcessEntry {
fun with(data: RuntimeProcessDefinitionDataEntry, entries: List<Entry>): ProcessEntry {
return ProcessEntry(
id = data.id?.toString() ?: "",
name = data.name ?: "",
description = data.description ?: "",
defaultEntry = entry,
defaultEntries = entries,
)
}

Expand All @@ -86,7 +86,7 @@ data class ProcessEntry(
startFormDefined = dataObj.hasStartForm,
processDefinitionKey = dataObj.key,
tenantId = dataObj.tenantId,
defaultEntry = processEntry?.defaultEntry,
defaultEntries = processEntry?.defaultEntries ?: emptyList(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ interface EntryListener {
/**
* It will get called on tap of start workflow on the option list
*/
fun onProcessStart(entry: ParentEntry) {}
fun onProcessStart(entry: List<ParentEntry>) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ abstract class ListViewModel<S : ListViewState>(
viewModelScope.on<ActionAddOffline> { updateActionEntries(it.entry, it.entries) }
viewModelScope.on<ActionRemoveOffline> { updateActionEntries(it.entry, it.entries) }
viewModelScope.on<ActionMoveFilesFolders> { onMove(it) }
viewModelScope.on<ActionStartProcess> { onStartProcess(it.entry) }
viewModelScope.on<ActionStartProcess> { onStartProcess(it.entries.ifEmpty { listOf(it.entry) }) }
}

private fun onStartProcess(entry: Entry) = entry.run {
if (entry.isFile) {
folderListener?.onProcessStart(entry)
private fun onStartProcess(entries: List<Entry>) = entries.run {
if (entries.all { it.isFile }) {
folderListener?.onProcessStart(entries)
}
}

Expand Down

0 comments on commit 3ade100

Please sign in to comment.