Skip to content

Commit

Permalink
added confirmation dialog if any of the file is not uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Apr 2, 2024
1 parent f2ca3a3 commit e36ac01
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 40 deletions.
2 changes: 0 additions & 2 deletions browse/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
<string name="text_filter_option">Filteroption %s</string>
<string name="workflows_account_not_configured">Workflows sind für diesen Account nicht aktiviert.</string>

<string name="title_content_in_queue">Warnung</string>
<string name="message_content_in_queue">Das Hochladen von Dateien ist in Bearbeitung. Tippen Sie auf Bestätigen, um ohne laufende Dateien fortzufahren.</string>
<string name="approve">Genehmigen</string>
<string name="reject">Ablehnen</string>
<string name="text_send_approval_again">Erneut zur Genehmigung senden</string>
Expand Down
2 changes: 0 additions & 2 deletions browse/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@

<string name="workflows_unavailable_title">Flujos de trabajo no disponibles</string>
<string name="workflow_unavailable_message">Los flujos de trabajo aparecerán aquí cuando sean creados</string>
<string name="title_content_in_queue">Advertencia</string>
<string name="message_content_in_queue">La carga de ficheros está en curso. Toque Confirmar para continuar sin los ficheros en curso.</string>
<string name="approve">Aprobar</string>
<string name="reject">Rechazar</string>
<string name="text_send_approval_again">Enviar para aprobación otra vez</string>
Expand Down
2 changes: 0 additions & 2 deletions browse/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
<string name="text_filter_option">Option de filtre %s</string>
<string name="workflows_account_not_configured">Les workflows ne sont pas activées pour ce compte.</string>

<string name="title_content_in_queue">Avertissement</string>
<string name="message_content_in_queue">Le téléchargement des fichiers est en cours. Tapez sur Confirmer pour continuer sans fichiers en cours.</string>
<string name="approve">Approuver</string>
<string name="reject">Rejeter</string>
<string name="text_send_approval_again">Envoyer à nouveau pour approbation</string>
Expand Down
2 changes: 0 additions & 2 deletions browse/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
<string name="text_filter_option">Opzione di filtro %s</string>
<string name="workflows_account_not_configured">I workflow non sono abilitati per questo account.</string>

<string name="title_content_in_queue">Avviso</string>
<string name="message_content_in_queue">Il caricamento dei file è in corso. Toccare su Conferma per continuare senza questi file.</string>
<string name="approve">Approva</string>
<string name="reject">Respingi</string>
<string name="text_send_approval_again">Invia di nuovo per approvazione</string>
Expand Down
2 changes: 0 additions & 2 deletions browse/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@

<string name="workflows_unavailable_title">Workflows niet beschikbaar!</string>
<string name="workflow_unavailable_message">Wanneer workflows zijn gemaakt, worden deze hier weergegeven.</string>
<string name="title_content_in_queue">Waarschuwing</string>
<string name="message_content_in_queue">Er worden bestanden geüpload. Tik om te bevestigen dat u wilt doorgaan zonder de bestanden in uitvoering.</string>
<string name="approve">Goedkeuren</string>
<string name="reject">Afwijzen</string>
<string name="text_send_approval_again">Nogmaals verzenden voor goedkeuring</string>
Expand Down
2 changes: 0 additions & 2 deletions browse/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
<string name="text_filter_option">Filter Option %s</string>
<string name="workflows_account_not_configured">Workflows are not enabled for this account.</string>

<string name="title_content_in_queue">Warning</string>
<string name="message_content_in_queue">Files uploading is in progress. Tap on Confirm to continue without in-progress files.</string>
<string name="approve">Approve</string>
<string name="reject">Reject</string>
<string name="text_send_approval_again">Send for Approval Again</string>
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
<string name="dialog_negative_button_task">Abbrechen</string>
<string name="dialog_positive_button_task">Bestätigen</string>
<string name="text_complete">Abgeschlossen</string>
<string name="title_content_in_queue">Warnung</string>
<string name="message_content_in_queue">Das Hochladen von Dateien ist in Bearbeitung. Tippen Sie auf Bestätigen, um ohne laufende Dateien fortzufahren.</string>
</resources>
2 changes: 2 additions & 0 deletions common/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
<string name="dialog_negative_button_task">Cancelar</string>
<string name="dialog_positive_button_task">Confirmar</string>
<string name="text_complete">Por completar</string>
<string name="title_content_in_queue">Advertencia</string>
<string name="message_content_in_queue">La carga de ficheros está en curso. Toque Confirmar para continuar sin los ficheros en curso.</string>
</resources>
3 changes: 2 additions & 1 deletion common/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
<string name="dialog_negative_button_task">Annuler</string>
<string name="dialog_positive_button_task">Confirmer</string>
<string name="text_complete">Terminé</string>

<string name="title_content_in_queue">Avertissement</string>
<string name="message_content_in_queue">Le téléchargement des fichiers est en cours. Tapez sur Confirmer pour continuer sans fichiers en cours.</string>
</resources>
2 changes: 2 additions & 0 deletions common/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
<string name="dialog_title_discard_task">Ignora</string>
<string name="dialog_message_discard_task">Vuoi ignorare le modifiche?</string>
<string name="text_complete">Completato</string>
<string name="title_content_in_queue">Avviso</string>
<string name="message_content_in_queue">Il caricamento dei file è in corso. Toccare su Conferma per continuare senza questi file.</string>
</resources>
2 changes: 2 additions & 0 deletions common/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
<string name="dialog_negative_button_task">Annuleren</string>
<string name="dialog_positive_button_task">Bevestigen</string>
<string name="text_complete">Voltooien</string>
<string name="title_content_in_queue">Waarschuwing</string>
<string name="message_content_in_queue">Er worden bestanden geüpload. Tik om te bevestigen dat u wilt doorgaan zonder de bestanden in uitvoering.</string>
</resources>
4 changes: 3 additions & 1 deletion common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@
<string name="dialog_title_delete_content">Delete a file?</string>
<string name="dialog_negative_button_task">Cancel</string>
<string name="dialog_positive_button_task">Confirm</string>
<string name="text_complete">Complete</string>
<string name="text_complete">Complete</string><string name="title_content_in_queue">Warning</string>
<string name="message_content_in_queue">Files uploading is in progress. Tap on Confirm to continue without in-progress files.</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,44 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.airbnb.mvrx.compose.collectAsState
import com.alfresco.content.component.ComponentBuilder
import com.alfresco.content.component.ComponentData
import com.alfresco.content.data.OptionsModel
import com.alfresco.content.process.R
import com.alfresco.content.process.ui.fragments.FormViewModel
import com.alfresco.content.process.ui.fragments.ProcessFragment

@Composable
fun FloatingActionButton(outcomes: List<OptionsModel>, enabledOutcomes: Boolean, viewModel: FormViewModel) {
fun FloatingActionButton(outcomes: List<OptionsModel>, fragment: ProcessFragment, viewModel: FormViewModel) {
val context = LocalContext.current
val state by viewModel.collectAsState()

ExtendedFloatingActionButton(
onClick = {
if (enabledOutcomes) {
if (state.enabledOutcomes) {
val componentData = ComponentData.with(
outcomes,
"",
"",
)
ComponentBuilder(context, componentData)
.onApply { name, query, _ ->

viewModel.performOutcomes(
OptionsModel(
id = query,
name = name,
),
)
val entry = state.listContents.find { it.isUpload }
if (entry != null) {
viewModel.optionsModel = OptionsModel(id = query, name = name)
fragment.confirmContentQueuePrompt()
} else {
viewModel.performOutcomes(
OptionsModel(
id = query,
name = name,
),
)
}
}
.onReset { name, query, _ ->
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.airbnb.mvrx.compose.collectAsState
import com.alfresco.content.data.OptionsModel
import com.alfresco.content.process.ui.fragments.FormViewModel
import com.alfresco.content.process.ui.fragments.ProcessFragment

@Composable
fun Outcomes(outcomes: List<OptionsModel>, enabledOutcomes: Boolean, viewModel: FormViewModel) {
fun Outcomes(outcomes: List<OptionsModel>, viewModel: FormViewModel, fragment: ProcessFragment) {
val state by viewModel.collectAsState()
outcomes.forEach {
Button(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 4.dp),
onClick = {
viewModel.performOutcomes(it)
val entry = state.listContents.find { it.isUpload }
if (entry != null) {
viewModel.optionsModel = it
fragment.confirmContentQueuePrompt()
} else {
viewModel.performOutcomes(it)
}
},
shape = RoundedCornerShape(6.dp),
enabled = enabledOutcomes,
enabled = state.enabledOutcomes,
colors = ButtonDefaults.buttonColors(
contentColor = Color.White,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -17,16 +18,19 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.airbnb.mvrx.compose.collectAsState
import com.alfresco.content.data.OptionsModel
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.process.ui.components.Outcomes
import com.alfresco.content.process.ui.fragments.FormViewModel
import com.alfresco.content.process.ui.fragments.FormViewState
import com.alfresco.content.process.ui.fragments.ProcessFragment

@SuppressLint("MutableCollectionMutableState")
@Composable
fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel, outcomes: List<OptionsModel>, navController: NavController) {
fun FormDetailScreen(viewModel: FormViewModel, outcomes: List<OptionsModel>, navController: NavController, fragment: ProcessFragment) {
val keyboardController = LocalSoftwareKeyboardController.current
val state by viewModel.collectAsState()
val focusManager = LocalFocusManager.current

Column(
Expand Down Expand Up @@ -61,7 +65,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel, outcomes: L
.fillMaxWidth()
.align(alignment = Alignment.CenterHorizontally),
) {
Outcomes(outcomes = outcomes, state.enabledOutcomes, viewModel)
Outcomes(outcomes = outcomes, viewModel, fragment)
}
}
}
Expand All @@ -72,13 +76,13 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel, outcomes: L
fun PreviewProcessDetailScreen() {
val state = FormViewState()
FormDetailScreen(
state,
FormViewModel(
state,
LocalContext.current,
TaskRepository(),
),
emptyList(),
rememberNavController(),
ProcessFragment(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ import com.alfresco.content.process.R
import com.alfresco.content.process.ui.components.FloatingActionButton
import com.alfresco.content.process.ui.fragments.FormViewModel
import com.alfresco.content.process.ui.fragments.FormViewState
import com.alfresco.content.process.ui.fragments.ProcessFragment

@Composable
fun FormScreen(navController: NavController, viewModel: FormViewModel) {
fun FormScreen(navController: NavController, viewModel: FormViewModel, fragment: ProcessFragment) {
val state by viewModel.collectAsState()

val customOutcomes = when {
state.formFields.isNotEmpty() && state.processOutcomes.isEmpty() -> {
defaultOutcomes(state)
}

else -> {
customOutcomes(state)
}
state.formFields.isNotEmpty() && state.processOutcomes.isEmpty() -> defaultOutcomes(state)
else -> customOutcomes(state)
}

when {
Expand All @@ -43,14 +39,14 @@ fun FormScreen(navController: NavController, viewModel: FormViewModel) {
color = colorScheme.background,
contentColor = colorScheme.onBackground,
) {
FormDetailScreen(state, viewModel, customOutcomes, navController)
FormDetailScreen(viewModel, customOutcomes, navController, fragment)
}
}
}

else -> {
Scaffold(
floatingActionButton = { FloatingActionButton(customOutcomes, state.enabledOutcomes, viewModel) },
floatingActionButton = { FloatingActionButton(customOutcomes, fragment, viewModel) },
floatingActionButtonPosition = FabPosition.End,
) { padding ->
val colorScheme = MaterialTheme.colorScheme
Expand All @@ -61,7 +57,7 @@ fun FormScreen(navController: NavController, viewModel: FormViewModel) {
color = colorScheme.background,
contentColor = colorScheme.onBackground,
) {
FormDetailScreen(state, viewModel, emptyList(), navController)
FormDetailScreen(viewModel, emptyList(), navController, fragment)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FormViewModel(
var observerID: String = ""
var folderFieldId = ""
private var entryListener: EntryListener? = null
var optionsModel: OptionsModel? = null

init {
observerID = UUID.randomUUID().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.core.view.isVisible
Expand All @@ -27,13 +28,16 @@ import com.alfresco.content.process.databinding.FragmentProcessBinding
import com.alfresco.content.process.ui.components.updateProcessList
import com.alfresco.content.process.ui.composeviews.FormScreen
import com.alfresco.content.process.ui.theme.AlfrescoBaseTheme
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.lang.ref.WeakReference

class ProcessFragment : Fragment(), MavericksView, EntryListener {

val viewModel: FormViewModel by activityViewModel()
lateinit var binding: FragmentProcessBinding
private var viewLayout: View? = null
private var menu: Menu? = null
private var confirmContentQueueDialog = WeakReference<AlertDialog>(null)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -97,6 +101,7 @@ class ProcessFragment : Fragment(), MavericksView, EntryListener {
FormScreen(
navController = findNavController(),
viewModel = viewModel,
this@ProcessFragment,
)
}
}
Expand Down Expand Up @@ -126,4 +131,26 @@ class ProcessFragment : Fragment(), MavericksView, EntryListener {
viewModel.folderFieldId = ""
}
}

/**
* It will prompt if user trying to start workflow and if any of content file is in uploaded
*/
fun confirmContentQueuePrompt() {
val oldDialog = confirmContentQueueDialog.get()
if (oldDialog != null && oldDialog.isShowing) return
val dialog = MaterialAlertDialogBuilder(requireContext())
.setCancelable(false)
.setTitle(getString(R.string.title_content_in_queue))
.setMessage(getString(R.string.message_content_in_queue))
.setNegativeButton(getString(R.string.dialog_negative_button_task), null)
.setPositiveButton(getString(R.string.dialog_positive_button_task)) { _, _ ->
viewModel.optionsModel?.let {
viewModel.performOutcomes(
it,
)
}
}
.show()
confirmContentQueueDialog = WeakReference(dialog)
}
}

0 comments on commit e36ac01

Please sign in to comment.