diff --git a/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Editions.kt b/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Editions.kt index 3cf0a8c..83ef4e9 100644 --- a/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Editions.kt +++ b/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Editions.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Delete import androidx.compose.material.icons.filled.Edit import androidx.compose.material3.* import androidx.compose.runtime.* @@ -13,9 +14,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp -import androidx.compose.ui.window.DialogWindow -import androidx.compose.ui.window.WindowPosition -import androidx.compose.ui.window.rememberDialogState +import androidx.compose.ui.window.* import com.jaytux.grader.data.* import com.jaytux.grader.viewmodel.EditionState import com.jaytux.grader.viewmodel.GroupAssignmentState @@ -68,6 +67,7 @@ fun EditionView(state: EditionState) = Row(Modifier.padding(0.dp)) { Box(Modifier.weight(0.5f)) { GroupAssignmentsWidget( state.course, state.edition, groupAs, idx.groupAsIdx(), { toggle(it, Panel.GroupAs) }, + { state.delete(it) }, { state.newGroupAssignment(it) }) { assignment, title -> state.setGroupAssignmentTitle( assignment, @@ -117,11 +117,13 @@ fun EditionSideWidget( data: List, selected: Int?, onSelect: (Int) -> Unit, singleWidget: @Composable (T) -> Unit, editDialog: @Composable ((current: T, onExit: () -> Unit) -> Unit)? = null, + deleter: ((T) -> Unit)? = null, dialog: @Composable (onExit: () -> Unit) -> Unit ) = Column(Modifier.padding(10.dp)) { Text(header, style = MaterialTheme.typography.headlineMedium) var showDialog by remember { mutableStateOf(false) } var current by remember { mutableStateOf(null) } + var deleting by remember { mutableStateOf(null) } ListOrEmpty( data, @@ -141,6 +143,11 @@ fun EditionSideWidget( Icon(Icons.Default.Edit, "Edit") } } + deleter?.let { d -> + IconButton({ deleting = it }, Modifier.align(Alignment.CenterVertically)) { + Icon(Icons.Default.Delete, "Delete") + } + } } } } @@ -151,6 +158,24 @@ fun EditionSideWidget( d(c) { current = null } } } + deleter?.let { d -> + deleting?.let { x -> + Dialog({ deleting = null }, DialogProperties()) { + Surface(Modifier.width(400.dp).height(300.dp), tonalElevation = 5.dp) { + Box(Modifier.fillMaxSize().padding(10.dp)) { + Column(Modifier.align(Alignment.Center)) { + Text("You are about to delete $addX.", Modifier.padding(10.dp)) + singleWidget(x) + CancelSaveRow(true, { deleting = null }, "Cancel", "Delete") { + d(x) + deleting = null + } + } + } + } + } + } + } } @Composable @@ -290,11 +315,12 @@ fun AssignmentsWidget( @Composable fun GroupAssignmentsWidget( course: Course, edition: Edition, assignments: List, selected: Int?, - onSelect: (Int) -> Unit, onAdd: (name: String) -> Unit, onUpdate: (GroupAssignment, String) -> Unit + onSelect: (Int) -> Unit, deleter: (GroupAssignment) -> Unit, onAdd: (name: String) -> Unit, onUpdate: (GroupAssignment, String) -> Unit ) = EditionSideWidget( course, edition, "Group assignment list", "group assignments", "an assignment", assignments, selected, onSelect, { Text(it.name, Modifier.padding(5.dp)) }, - { current, onExit -> AddStringDialog("Assignment title", assignments.map { it.name }, onExit, current.name) { onUpdate(current, it) } } + { current, onExit -> AddStringDialog("Assignment title", assignments.map { it.name }, onExit, current.name) { onUpdate(current, it) } }, + deleter ) { onExit -> AddStringDialog("Assignment title", assignments.map { it.name }, onExit) { onAdd(it) } } \ No newline at end of file diff --git a/composeApp/src/desktopMain/kotlin/com/jaytux/grader/viewmodel/DbState.kt b/composeApp/src/desktopMain/kotlin/com/jaytux/grader/viewmodel/DbState.kt index 2a8fa32..1e906bd 100644 --- a/composeApp/src/desktopMain/kotlin/com/jaytux/grader/viewmodel/DbState.kt +++ b/composeApp/src/desktopMain/kotlin/com/jaytux/grader/viewmodel/DbState.kt @@ -138,6 +138,15 @@ class EditionState(val edition: Edition) { } groupAs.refresh() } + + fun delete(ga: GroupAssignment) { + transaction { + GroupFeedbacks.deleteWhere { groupAssignmentId eq ga.id } + IndividualFeedbacks.deleteWhere { groupAssignmentId eq ga.id } + ga.delete() + } + groupAs.refresh() + } } class StudentState(val student: Student, edition: Edition) {