mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2026-01-01 17:28:47 +01:00
feat(connector): add selecting projects
This commit is contained in:
@@ -17,7 +17,6 @@ import cafe.adriel.voyager.navigator.tab.Tab
|
|||||||
import cafe.adriel.voyager.navigator.tab.TabNavigator
|
import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
|
||||||
import org.jetbrains.compose.ui.tooling.preview.Preview
|
import org.jetbrains.compose.ui.tooling.preview.Preview
|
||||||
import org.koin.compose.KoinContext
|
import org.koin.compose.KoinContext
|
||||||
import tab.About
|
import tab.About
|
||||||
@@ -41,7 +40,7 @@ fun AppScaffold() {
|
|||||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
TabNavigator(Projects()) {
|
TabNavigator(Projects) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopBar(drawerState, scope)
|
TopBar(drawerState, scope)
|
||||||
@@ -108,7 +107,6 @@ fun TopBar(
|
|||||||
/**
|
/**
|
||||||
* Navigation drawer from the left side
|
* Navigation drawer from the left side
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalResourceApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NavigationDrawer(
|
fun NavigationDrawer(
|
||||||
drawerState: DrawerState,
|
drawerState: DrawerState,
|
||||||
@@ -120,11 +118,11 @@ fun NavigationDrawer(
|
|||||||
ModalDrawerSheet {
|
ModalDrawerSheet {
|
||||||
Column(modifier = Modifier.verticalScroll(rememberScrollState()) ) {
|
Column(modifier = Modifier.verticalScroll(rememberScrollState()) ) {
|
||||||
Text("Project Name...", modifier = Modifier.padding(16.dp))
|
Text("Project Name...", modifier = Modifier.padding(16.dp))
|
||||||
TabNavigationItem(Projects())
|
TabNavigationItem(Projects)
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
|
|
||||||
Text("Tester", modifier = Modifier.padding(16.dp))
|
Text("Tester", modifier = Modifier.padding(16.dp))
|
||||||
TabNavigationItem(Procedures())
|
TabNavigationItem(Procedures)
|
||||||
TabNavigationItem(SimulatorTest())
|
TabNavigationItem(SimulatorTest())
|
||||||
TabNavigationItem(TestResults())
|
TabNavigationItem(TestResults())
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
class InterfaceState {
|
import org.koin.core.component.KoinComponent
|
||||||
|
|
||||||
|
class InterfaceState : KoinComponent {
|
||||||
var simConnection: Boolean = false
|
var simConnection: Boolean = false
|
||||||
var projectId: Int? = null
|
var projectId: Int? = null
|
||||||
|
val projectSelected: Boolean
|
||||||
|
get() = projectId != null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ fun viewModelModule() = module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
single<ProcedureScreenModel> {
|
single<ProcedureScreenModel> {
|
||||||
ProcedureScreenModel(db = get())
|
ProcedureScreenModel(db = get(), interfaceState = get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package tab.procedure
|
package tab.procedure
|
||||||
|
|
||||||
|
import InterfaceState
|
||||||
import cafe.adriel.voyager.core.model.StateScreenModel
|
import cafe.adriel.voyager.core.model.StateScreenModel
|
||||||
import cafe.adriel.voyager.core.model.screenModelScope
|
import cafe.adriel.voyager.core.model.screenModelScope
|
||||||
import io.anthonyberg.connector.shared.ProcedureTransaction
|
import io.anthonyberg.connector.shared.ProcedureTransaction
|
||||||
@@ -7,15 +8,20 @@ import io.anthonyberg.connector.shared.entity.Procedure
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class ProcedureScreenModel (
|
class ProcedureScreenModel (
|
||||||
private val db: ProcedureTransaction
|
private val db: ProcedureTransaction,
|
||||||
|
private val interfaceState: InterfaceState
|
||||||
) : StateScreenModel<ProcedureState>(ProcedureState.Loading) {
|
) : StateScreenModel<ProcedureState>(ProcedureState.Loading) {
|
||||||
|
|
||||||
fun procedureExists() {
|
fun procedureExists() {
|
||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
val exists = db.proceduresExist()
|
mutableState.value = ProcedureState.Loading
|
||||||
|
|
||||||
|
val projectId = interfaceState.projectId ?: return@launch
|
||||||
|
|
||||||
|
val exists = db.proceduresExist(projectId)
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
val procedures = getProcedures()
|
val procedures = getProcedures(projectId)
|
||||||
mutableState.value = ProcedureState.Result(procedures = procedures)
|
mutableState.value = ProcedureState.Result(procedures = procedures)
|
||||||
} else {
|
} else {
|
||||||
mutableState.value = ProcedureState.Init
|
mutableState.value = ProcedureState.Init
|
||||||
@@ -23,8 +29,8 @@ class ProcedureScreenModel (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getProcedures(): List<Procedure> {
|
private fun getProcedures(projectId: Int): List<Procedure> {
|
||||||
val procedures = db.getProcedures()
|
val procedures = db.getProcedures(projectId)
|
||||||
|
|
||||||
return procedures
|
return procedures
|
||||||
}
|
}
|
||||||
@@ -37,11 +43,13 @@ class ProcedureScreenModel (
|
|||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
mutableState.value = ProcedureState.Loading
|
mutableState.value = ProcedureState.Loading
|
||||||
|
|
||||||
|
val projectId = interfaceState.projectId ?: return@launch
|
||||||
|
|
||||||
// Add procedure to the database
|
// Add procedure to the database
|
||||||
db.createProcedure(procedureName, procedureType, procedureDescription)
|
db.createProcedure(projectId, procedureName, procedureType, procedureDescription)
|
||||||
|
|
||||||
// Load new procedures
|
// Load new procedures
|
||||||
val procedures = getProcedures()
|
val procedures = getProcedures(projectId)
|
||||||
mutableState.value = ProcedureState.Result(procedures)
|
mutableState.value = ProcedureState.Result(procedures)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import cafe.adriel.voyager.navigator.Navigator
|
|||||||
import cafe.adriel.voyager.navigator.tab.Tab
|
import cafe.adriel.voyager.navigator.tab.Tab
|
||||||
import cafe.adriel.voyager.navigator.tab.TabOptions
|
import cafe.adriel.voyager.navigator.tab.TabOptions
|
||||||
|
|
||||||
class Procedures : Tab {
|
object Procedures : Tab {
|
||||||
|
private fun readResolve(): Any = Procedures
|
||||||
|
|
||||||
override val options: TabOptions
|
override val options: TabOptions
|
||||||
@Composable
|
@Composable
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package tab.project
|
package tab.project
|
||||||
|
|
||||||
|
import InterfaceState
|
||||||
import androidx.compose.foundation.VerticalScrollbar
|
import androidx.compose.foundation.VerticalScrollbar
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -20,14 +21,21 @@ import androidx.compose.ui.Modifier
|
|||||||
import cafe.adriel.voyager.core.screen.Screen
|
import cafe.adriel.voyager.core.screen.Screen
|
||||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||||
|
import cafe.adriel.voyager.navigator.tab.LocalTabNavigator
|
||||||
|
import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||||
import io.anthonyberg.connector.shared.entity.Project
|
import io.anthonyberg.connector.shared.entity.Project
|
||||||
|
import org.koin.compose.koinInject
|
||||||
|
import tab.procedure.Procedures
|
||||||
|
|
||||||
class ListProjects(private val projects: List<Project>) : Screen {
|
class ListProjects(private val projects: List<Project>) : Screen {
|
||||||
@Composable
|
@Composable
|
||||||
override fun Content() {
|
override fun Content() {
|
||||||
val navigator = LocalNavigator.currentOrThrow
|
val navigator = LocalNavigator.currentOrThrow
|
||||||
|
val tabNavigator = LocalTabNavigator.current
|
||||||
val state = rememberLazyListState(0)
|
val state = rememberLazyListState(0)
|
||||||
|
|
||||||
|
val viewModel = koinInject<InterfaceState>()
|
||||||
|
|
||||||
Scaffold (
|
Scaffold (
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
ExtendedFloatingActionButton(
|
ExtendedFloatingActionButton(
|
||||||
@@ -48,7 +56,7 @@ class ListProjects(private val projects: List<Project>) : Screen {
|
|||||||
) {
|
) {
|
||||||
LazyColumn(state = state) {
|
LazyColumn(state = state) {
|
||||||
items(projects) { project ->
|
items(projects) { project ->
|
||||||
projectItem(project)
|
projectItem(project, viewModel, tabNavigator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VerticalScrollbar(
|
VerticalScrollbar(
|
||||||
@@ -66,13 +74,16 @@ class ListProjects(private val projects: List<Project>) : Screen {
|
|||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun projectItem(project: Project) {
|
private fun projectItem(project: Project, viewModel: InterfaceState, tabNavigator: TabNavigator) {
|
||||||
ListItem(
|
ListItem(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable(
|
.clickable(
|
||||||
enabled = true,
|
enabled = true,
|
||||||
onClick = {
|
onClick = {
|
||||||
// TODO add loading project
|
viewModel.projectId = project.id
|
||||||
|
|
||||||
|
// Go to procedures page once project has been selected
|
||||||
|
tabNavigator.current = Procedures
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
overlineContent = { Text(project.aircraftType) },
|
overlineContent = { Text(project.aircraftType) },
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ import connector.composeapp.generated.resources.folder_24px
|
|||||||
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
||||||
import org.jetbrains.compose.resources.painterResource
|
import org.jetbrains.compose.resources.painterResource
|
||||||
|
|
||||||
class Projects : Tab {
|
object Projects : Tab {
|
||||||
|
private fun readResolve(): Any = Projects
|
||||||
|
|
||||||
@OptIn(ExperimentalResourceApi::class)
|
@OptIn(ExperimentalResourceApi::class)
|
||||||
override val options: TabOptions
|
override val options: TabOptions
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ class ProjectsContent : Screen {
|
|||||||
val state by screenModel.state.collectAsState()
|
val state by screenModel.state.collectAsState()
|
||||||
|
|
||||||
when (val s = state) {
|
when (val s = state) {
|
||||||
is ProjectState.Init -> NoProjects().Content()
|
|
||||||
is ProjectState.Loading -> LoadingScreen("Projects").Content()
|
is ProjectState.Loading -> LoadingScreen("Projects").Content()
|
||||||
|
is ProjectState.Init -> NoProjects().Content()
|
||||||
is ProjectState.Result -> ListProjects(s.projects).Content()
|
is ProjectState.Result -> ListProjects(s.projects).Content()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ class ProjectsScreenModel (
|
|||||||
|
|
||||||
fun projectExists() {
|
fun projectExists() {
|
||||||
screenModelScope.launch {
|
screenModelScope.launch {
|
||||||
|
mutableState.value = ProjectState.Loading
|
||||||
|
|
||||||
val exists = db.projectExists()
|
val exists = db.projectExists()
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ class ProcedureTransaction (driverFactory: DriverFactory) {
|
|||||||
/**
|
/**
|
||||||
* Creates a procedure for a project
|
* Creates a procedure for a project
|
||||||
*
|
*
|
||||||
|
* @param projectId ID of the selected Project
|
||||||
* @param name Name of the procedure
|
* @param name Name of the procedure
|
||||||
* @param type Procedure type (e.g. Normal, Emergency)
|
* @param type Procedure type (e.g. Normal, Emergency)
|
||||||
* @param description Description of what the procedure will do
|
* @param description Description of what the procedure will do
|
||||||
*/
|
*/
|
||||||
fun createProcedure(name: String, type: String, description: String) {
|
fun createProcedure(projectId: Int, name: String, type: String, description: String) {
|
||||||
// TODO add dynamic procedureId insertion
|
|
||||||
val projectId = 1
|
|
||||||
val currentTime = Clock.System.now().toString()
|
val currentTime = Clock.System.now().toString()
|
||||||
|
|
||||||
database.createProcedure(
|
database.createProcedure(
|
||||||
@@ -36,11 +35,10 @@ class ProcedureTransaction (driverFactory: DriverFactory) {
|
|||||||
/**
|
/**
|
||||||
* Gets all procedures in current project
|
* Gets all procedures in current project
|
||||||
*
|
*
|
||||||
|
* @param projectId ID of the selected Project
|
||||||
* @return List of [Procedure] in current project
|
* @return List of [Procedure] in current project
|
||||||
*/
|
*/
|
||||||
fun getProcedures(): List<Procedure> {
|
fun getProcedures(projectId: Int): List<Procedure> {
|
||||||
// TODO add dynamic procedureId insertion
|
|
||||||
val projectId = 1
|
|
||||||
|
|
||||||
val procedures = database.getAllProcedures(projectId = projectId)
|
val procedures = database.getAllProcedures(projectId = projectId)
|
||||||
|
|
||||||
@@ -62,24 +60,20 @@ class ProcedureTransaction (driverFactory: DriverFactory) {
|
|||||||
/**
|
/**
|
||||||
* Counts the amount of procedures that exist based on the current project
|
* Counts the amount of procedures that exist based on the current project
|
||||||
*
|
*
|
||||||
|
* @param projectId ID of current Project
|
||||||
* @return Number of procedures in the database
|
* @return Number of procedures in the database
|
||||||
*/
|
*/
|
||||||
fun countProcedures(): Long {
|
fun countProcedures(projectId: Int): Long {
|
||||||
// TODO add dynamic procedureId insertion
|
|
||||||
val projectId = 1
|
|
||||||
|
|
||||||
return database.countProcedures(projectId = projectId)
|
return database.countProcedures(projectId = projectId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there are procedures on the database for the current project
|
* Checks if there are procedures on the database for the current project
|
||||||
*
|
*
|
||||||
|
* @param projectId ID of current Project
|
||||||
* @return `true` if procedures exist for project
|
* @return `true` if procedures exist for project
|
||||||
*/
|
*/
|
||||||
fun proceduresExist(): Boolean {
|
fun proceduresExist(projectId: Int): Boolean {
|
||||||
// TODO add dynamic procedureId insertion
|
|
||||||
val projectId = 1
|
|
||||||
|
|
||||||
return database.countProcedures(projectId = projectId) > 0
|
return database.countProcedures(projectId = projectId) > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user