mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-05-18 14:34:12 +02:00
feat(connector): implement save for Action
This commit is contained in:
parent
07b3cfdb26
commit
f498c8c0c0
@ -93,7 +93,7 @@ class Actions (dbActions: List<Action>) : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
footer(navigator, viewModel)
|
footer(navigator, viewModel, screenModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ class Actions (dbActions: List<Action>) : Screen {
|
|||||||
Column (
|
Column (
|
||||||
verticalArrangement = Arrangement.spacedBy(itemPadding)
|
verticalArrangement = Arrangement.spacedBy(itemPadding)
|
||||||
) {
|
) {
|
||||||
Text(text = "Action ${item.id}")
|
Text(text = "Action ${item.step + 1}")
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
Modifier.fillMaxWidth(),
|
Modifier.fillMaxWidth(),
|
||||||
@ -132,7 +132,7 @@ class Actions (dbActions: List<Action>) : Screen {
|
|||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
modifier = Modifier.fillMaxWidth(0.6f),
|
modifier = Modifier.fillMaxWidth(0.6f),
|
||||||
value = item.type,
|
value = item.type,
|
||||||
onValueChange = { inputs[item.id] = inputs[item.id].copy(type = it) },
|
onValueChange = { inputs[item.id - 1] = inputs[item.id - 1].copy(type = it) },
|
||||||
label = { Text("Dataref Name") },
|
label = { Text("Dataref Name") },
|
||||||
singleLine = true
|
singleLine = true
|
||||||
)
|
)
|
||||||
@ -140,7 +140,7 @@ class Actions (dbActions: List<Action>) : Screen {
|
|||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = item.goal,
|
value = item.goal,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
onValueChange = { inputs[item.id] = inputs[item.id].copy(goal = it) },
|
onValueChange = { inputs[item.id - 1] = inputs[item.id - 1].copy(goal = it) },
|
||||||
label = { Text("Desired State") },
|
label = { Text("Desired State") },
|
||||||
singleLine = true
|
singleLine = true
|
||||||
)
|
)
|
||||||
@ -152,16 +152,16 @@ class Actions (dbActions: List<Action>) : Screen {
|
|||||||
|
|
||||||
@OptIn(ExperimentalResourceApi::class)
|
@OptIn(ExperimentalResourceApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun footer(navigator: Navigator, viewModel: InterfaceState) {
|
private fun footer(navigator: Navigator, viewModel: InterfaceState, screenModel: ActionsScreenModel) {
|
||||||
Row (
|
Row (
|
||||||
Modifier.fillMaxWidth(),
|
Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
) {
|
) {
|
||||||
// Add Step
|
// Add Step
|
||||||
|
// TODO add menu to choose multiple types of items
|
||||||
FilledTonalButton(
|
FilledTonalButton(
|
||||||
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
||||||
onClick = {
|
onClick = {
|
||||||
// TODO make this a proper data array for each item in checklist
|
|
||||||
val procedureId = viewModel.procedureId
|
val procedureId = viewModel.procedureId
|
||||||
if (procedureId != null) {
|
if (procedureId != null) {
|
||||||
inputs += createEmptyAction(procedureId)
|
inputs += createEmptyAction(procedureId)
|
||||||
@ -181,7 +181,7 @@ class Actions (dbActions: List<Action>) : Screen {
|
|||||||
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
||||||
onClick = {
|
onClick = {
|
||||||
// TODO make checks
|
// TODO make checks
|
||||||
// TODO save to database
|
screenModel.saveActions(inputs)
|
||||||
navigator.pop()
|
navigator.pop()
|
||||||
viewModel.procedureId = null
|
viewModel.procedureId = null
|
||||||
}
|
}
|
||||||
@ -197,12 +197,12 @@ class Actions (dbActions: List<Action>) : Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createEmptyAction(procedureId: Int): Action {
|
private fun createEmptyAction(procedureId: Int): Action {
|
||||||
val index = inputs.size
|
val index = inputs.size + 1
|
||||||
|
|
||||||
val action = Action(
|
val action = Action(
|
||||||
id = index,
|
id = index,
|
||||||
procedureId = procedureId,
|
procedureId = procedureId,
|
||||||
step = index,
|
step = index - 1,
|
||||||
type = "",
|
type = "",
|
||||||
goal = ""
|
goal = ""
|
||||||
)
|
)
|
||||||
|
@ -26,6 +26,18 @@ class ActionsScreenModel (
|
|||||||
fun loadedActions() {
|
fun loadedActions() {
|
||||||
mutableState.value = ActionsState.Idle
|
mutableState.value = ActionsState.Idle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveActions(actions: List<Action>) {
|
||||||
|
screenModelScope.launch {
|
||||||
|
val procedureId = interfaceState.procedureId ?: return@launch
|
||||||
|
|
||||||
|
// Delete all previous items of the actions from the database
|
||||||
|
db.deleteActionByProcedure(procedureId = procedureId)
|
||||||
|
|
||||||
|
// Add the new actions to the database
|
||||||
|
db.createActionFromList(actions = actions)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class ActionsState {
|
sealed class ActionsState {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user