mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-07-07 15:31:01 +02:00
feat(connector): add ability to create procedures
This commit is contained in:
parent
168c0ad18f
commit
f0295a9ada
@ -12,6 +12,7 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cafe.adriel.voyager.core.screen.Screen
|
import cafe.adriel.voyager.core.screen.Screen
|
||||||
|
import cafe.adriel.voyager.koin.getScreenModel
|
||||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ class CreateProcedure : Screen {
|
|||||||
@Composable
|
@Composable
|
||||||
override fun Content() {
|
override fun Content() {
|
||||||
val navigator = LocalNavigator.currentOrThrow
|
val navigator = LocalNavigator.currentOrThrow
|
||||||
|
val screenModel = getScreenModel<ProcedureScreenModel>()
|
||||||
val columnPadding = 24.dp
|
val columnPadding = 24.dp
|
||||||
|
|
||||||
// Information
|
// Information
|
||||||
@ -153,8 +155,20 @@ class CreateProcedure : Screen {
|
|||||||
Button(
|
Button(
|
||||||
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
|
||||||
onClick = {
|
onClick = {
|
||||||
// TODO save new procedure and make sure it redirects to list page
|
if (
|
||||||
navigator.pop()
|
procedureName.isNotBlank() and
|
||||||
|
procedureType.isNotBlank() and
|
||||||
|
procedureDescription.isNotBlank()
|
||||||
|
// TODO add checks for actions
|
||||||
|
) {
|
||||||
|
screenModel.createProcedure(
|
||||||
|
procedureName = procedureName,
|
||||||
|
procedureType = procedureType,
|
||||||
|
procedureDescription = procedureDescription,
|
||||||
|
)
|
||||||
|
|
||||||
|
navigator.pop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Icon(Icons.Outlined.Add, "Create Procedure", modifier = Modifier.size(18.dp))
|
Icon(Icons.Outlined.Add, "Create Procedure", modifier = Modifier.size(18.dp))
|
||||||
|
@ -28,6 +28,24 @@ class ProcedureScreenModel (
|
|||||||
|
|
||||||
return procedures
|
return procedures
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createProcedure(
|
||||||
|
procedureName: String,
|
||||||
|
procedureType: String,
|
||||||
|
procedureDescription: String
|
||||||
|
) {
|
||||||
|
screenModelScope.launch {
|
||||||
|
mutableState.value = ProcedureState.Loading
|
||||||
|
|
||||||
|
// Add procedure to the database
|
||||||
|
db.createProcedure(procedureName, procedureType, procedureDescription)
|
||||||
|
|
||||||
|
// Load new procedures
|
||||||
|
val procedures = getProcedures()
|
||||||
|
mutableState.value = ProcedureState.Result(procedures)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class ProcedureState {
|
sealed class ProcedureState {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user