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

MOBILEAPPS-1734 #240

Merged
merged 3 commits into from
May 5, 2023
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ lint/reports/
/content/
/gradle/libs.versions1.toml
/process/
/auth-alfresco/
/auth-alfresco/
/build_api.gradle
/build_app.gradle
/gradle/libs.versions_api.toml
/gradle/libs.versions_app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ProcessDetailFragment : BaseDetailFragment(), MavericksView {
}

override fun invalidate() = withState(viewModel) { state ->
binding.loading.isVisible = false
binding.loading.isVisible = state.listContents.isEmpty()
setData(state)
updateUI(state)
epoxyAttachmentController.requestModelBuild()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.alfresco.content.browse.processes.details

import android.content.Context
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success
Expand All @@ -14,9 +16,13 @@ import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.data.UploadServerType
import com.alfresco.content.data.UserGroupDetails
import com.alfresco.content.data.payloads.LinkContentPayload
import com.alfresco.coroutines.asFlow
import com.alfresco.events.on
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.zip
import kotlinx.coroutines.launch

/**
* Marked as ProcessDetailViewModel
Expand All @@ -30,10 +36,29 @@ class ProcessDetailViewModel(
private var observeUploadsJob: Job? = null

init {
state.parent?.let { processEntry ->
processEntry.defaultEntry?.let { entry ->
viewModelScope.launch {
linkContentToProcess(entry).zip(singleProcessDefinition(processEntry.id)) { content, singleProcess ->
Pair(content, singleProcess)
}.execute {
when (it) {
is Success -> {
val processData = ProcessEntry.with(it().second.listProcessDefinitions.first(), it().first)
getStartForm(processData.id)
updateContentAndProcessDefinition(it().first, processData)
}
else -> {
this
}
}
}
}
}
}
viewModelScope.on<ActionUpdateNameDescription> {
setState { copy(parent = it.entry as ProcessEntry) }
}
updateDefaultEntry(state.parent?.defaultEntry)
observeUploads(state)
}

Expand All @@ -47,8 +72,6 @@ class ProcessDetailViewModel(
}
}

private fun updateDefaultEntry(entry: Entry?) = setState { copy(baseEntries = if (entry != null) listOf(entry) else emptyList()) }

/**
* update the formatted date in the existing ProcessEntry obj and update the UI.
*/
Expand Down Expand Up @@ -91,21 +114,41 @@ class ProcessDetailViewModel(
observeUploadsJob = repo.observeUploads(state.parent.id, UploadServerType.UPLOAD_TO_PROCESS)
.execute {
if (it is Success) {
println("observer list ${it().size}")
updateUploads(it())
} else {
this
}
}
}

private fun getStartForm(processDefinitionId: String) = withState { state ->
viewModelScope.launch {
repository::startForm.asFlow(processDefinitionId).execute {
when (it) {
is Loading -> copy(requestStartForm = Loading())
is Fail -> copy(requestStartForm = Fail(it.error))
is Success -> {
updateFormFields(it()).copy(requestStartForm = Success(it()))
}
else -> {
this
}
}
}
}
}

/**
* delete content locally
*/
fun deleteAttachment(contentId: String) = stateFlow.execute {
deleteUploads(contentId)
}

private fun linkContentToProcess(entry: Entry) = repository::linkADWContentToProcess.asFlow(LinkContentPayload.with(entry))

private fun singleProcessDefinition(appDefinitionId: String) = repository::singleProcessDefinition.asFlow(appDefinitionId)

companion object : MavericksViewModelFactory<ProcessDetailViewModel, ProcessDetailViewState> {

override fun create(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.alfresco.content.browse.processes.details

import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.Uninitialized
import com.alfresco.content.data.Entry
import com.alfresco.content.data.OfflineStatus
import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.ResponseListStartForm
import com.alfresco.content.data.payloads.FieldsData

/**
* Marked as ProcessDetailViewState
Expand All @@ -12,11 +16,32 @@ data class ProcessDetailViewState(
val parent: ProcessEntry?,
val listContents: List<Entry> = emptyList(),
val baseEntries: List<Entry> = emptyList(),
val uploads: List<Entry> = emptyList()
val uploads: List<Entry> = emptyList(),
val formFields: List<FieldsData> = emptyList(),
val requestStartForm: Async<ResponseListStartForm> = Uninitialized
) : MavericksState {

constructor(target: ProcessEntry) : this(parent = target)

/**
* update ACS content and single definition data
*/
fun updateContentAndProcessDefinition(entry: Entry?, processEntry: ProcessEntry): ProcessDetailViewState {
if (entry == null)
return this

return copyIncludingUploads(listOf(entry), emptyList()).copy(processEntry)
}

/**
* update form fields data
*/
fun updateFormFields(response: ResponseListStartForm): ProcessDetailViewState {
requireNotNull(parent)
val formFields = response.fields.first().fields
return copy(formFields = formFields, parent = ProcessEntry.updateReviewerType(parent, formFields))
}

/**
* delete content locally and update UI
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.ViewModelContext
import com.alfresco.content.data.Entry
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.data.payloads.LinkContentPayload
import com.alfresco.coroutines.asFlow
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.zip
import kotlinx.coroutines.launch

internal class ProcessDefinitionsViewModel(
Expand All @@ -24,14 +21,12 @@ internal class ProcessDefinitionsViewModel(

private fun buildModel() = withState { state ->
viewModelScope.launch {
processDefinitions().zip(linkContentToProcess(state.entry)) { requestProcess, requestContent ->
Pair(requestProcess, requestContent)
}.execute {
processDefinitions().execute {
when (it) {
is Success -> {
ProcessDefinitionsState(
entry = it().second,
listProcessDefinitions = it().first.listRuntimeProcessDefinitions
entry = state.entry,
listProcessDefinitions = it().listRuntimeProcessDefinitions
)
}
else -> {
Expand All @@ -45,8 +40,6 @@ internal class ProcessDefinitionsViewModel(
}
}

private fun linkContentToProcess(entry: Entry) = TaskRepository()::linkADWContentToProcess.asFlow(LinkContentPayload.with(entry))

private fun processDefinitions() = TaskRepository()::processDefinitions.asFlow()

companion object : MavericksViewModelFactory<ProcessDefinitionsViewModel, ProcessDefinitionsState> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal typealias SearchUserComponentApplyCallback = (UserGroupDetails) -> Unit
internal typealias SearchUserComponentCancelCallback = () -> Unit

/**
* Builder for build the search user component sheet
* Builder for build the search user and group component sheet
*/
data class SearchUserGroupComponentBuilder(
val context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.alfresco.content.common.isValidEmail
import com.alfresco.content.component.databinding.SheetComponentSearchUserBinding
import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.ReviewerType
import com.alfresco.content.hideSoftInput
import com.alfresco.ui.BottomSheetDialogFragment
import com.alfresco.ui.getDrawableForAttribute
Expand Down Expand Up @@ -149,9 +151,21 @@ class SearchUserGroupComponentSheet : BottomSheetDialogFragment(), MavericksView
binding.loading.isVisible = state.requestUser is Loading

if (viewModel.canSearchGroups) {
binding.rgSelector.visibility = View.GONE
binding.searchView.queryHint = when ((state.parent as ProcessEntry).reviewerType) {
ReviewerType.FUNCTIONAL_GROUP -> {
viewModel.searchByNameOrIndividual = false
getString(R.string.search_group)
}
else -> {
viewModel.searchByNameOrIndividual = true
getString(R.string.search_user)
}
}
binding.searchByNameOrIndividual.text = getString(R.string.individual_title)
binding.searchByEmailOrGroups.text = getString(R.string.group_title)
} else {
binding.rgSelector.visibility = View.VISIBLE
binding.searchByNameOrIndividual.text = getString(R.string.text_by_name)
binding.searchByEmailOrGroups.text = getString(R.string.text_by_email)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.alfresco.content.data.APIEvent
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.ResponseUserGroupList
import com.alfresco.content.data.ReviewerType
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.data.UserGroupDetails
import java.util.concurrent.CancellationException
Expand Down Expand Up @@ -52,7 +53,11 @@ class SearchUserGroupComponentViewModel(

setState {
canSearchGroups = parent is ProcessEntry
copy(listUserGroup = listOf(getLoggedInUser()))
var listUserGroup: List<UserGroupDetails> = listOf()
if (parent is ProcessEntry && parent.reviewerType != ReviewerType.FUNCTIONAL_GROUP) {
listUserGroup = listOf(getLoggedInUser())
}
copy(listUserGroup = listUserGroup)
}

viewModelScope.launch {
Expand Down
2 changes: 2 additions & 0 deletions component/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@
<string name="text_by_email">By E-mail</string>
<string name="text_back_button">Back Button</string>
<string name="filter.option.all">All</string>
<string name="search_user">Search User</string>
<string name="search_group">Search Group</string>
</resources>
8 changes: 2 additions & 6 deletions data/objectbox-models/default.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@
"id": "27:4514687495334138822",
"name": "uploadServer",
"type": 9
},
{
"id": "28:949912739494302928",
"name": "isProcessService",
"type": 1
}
],
"relations": []
Expand All @@ -157,7 +152,8 @@
"retiredEntityUids": [],
"retiredIndexUids": [],
"retiredPropertyUids": [
84855644780396979
84855644780396979,
949912739494302928
],
"retiredRelationUids": [],
"version": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.alfresco.content.data

import android.os.Parcelable
import com.alfresco.process.models.ProcessDefinitionEntry
import kotlinx.parcelize.Parcelize

/**
* Marked as RuntimeProcessDefinitionDataEntry
*/
@Parcelize
data class ProcessDefinitionDataEntry(
val id: String? = null,
val name: String? = null,
val description: String? = null,
val key: String? = null,
val category: String? = null,
val version: Int? = null,
val deploymentId: String? = null,
val tenantId: String? = null,
val hasStartForm: Boolean? = null
) : ParentEntry(), Parcelable {
companion object {

/**
* return RuntimeProcessDefinitionDataEntry by using RuntimeProcessDefinitionEntry
*/
fun with(raw: ProcessDefinitionEntry): ProcessDefinitionDataEntry {
return ProcessDefinitionDataEntry(
id = raw.id,
name = raw.name,
description = raw.description,
key = raw.key,
category = raw.category,
version = raw.version,
deploymentId = raw.deploymentId,
tenantId = raw.tenantId,
hasStartForm = raw.hasStartForm
)
}
}
}
Loading