Added support for deletion (limited)
This commit is contained in:
parent
97fe7a8139
commit
0bfef36559
|
@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
import androidx.compose.material.icons.filled.Edit
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
@ -13,9 +14,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.DpSize
|
import androidx.compose.ui.unit.DpSize
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.DialogWindow
|
import androidx.compose.ui.window.*
|
||||||
import androidx.compose.ui.window.WindowPosition
|
|
||||||
import androidx.compose.ui.window.rememberDialogState
|
|
||||||
import com.jaytux.grader.data.*
|
import com.jaytux.grader.data.*
|
||||||
import com.jaytux.grader.viewmodel.EditionState
|
import com.jaytux.grader.viewmodel.EditionState
|
||||||
import com.jaytux.grader.viewmodel.GroupAssignmentState
|
import com.jaytux.grader.viewmodel.GroupAssignmentState
|
||||||
|
@ -68,6 +67,7 @@ fun EditionView(state: EditionState) = Row(Modifier.padding(0.dp)) {
|
||||||
Box(Modifier.weight(0.5f)) {
|
Box(Modifier.weight(0.5f)) {
|
||||||
GroupAssignmentsWidget(
|
GroupAssignmentsWidget(
|
||||||
state.course, state.edition, groupAs, idx.groupAsIdx(), { toggle(it, Panel.GroupAs) },
|
state.course, state.edition, groupAs, idx.groupAsIdx(), { toggle(it, Panel.GroupAs) },
|
||||||
|
{ state.delete(it) },
|
||||||
{ state.newGroupAssignment(it) }) { assignment, title ->
|
{ state.newGroupAssignment(it) }) { assignment, title ->
|
||||||
state.setGroupAssignmentTitle(
|
state.setGroupAssignmentTitle(
|
||||||
assignment,
|
assignment,
|
||||||
|
@ -117,11 +117,13 @@ fun <T> EditionSideWidget(
|
||||||
data: List<T>, selected: Int?, onSelect: (Int) -> Unit,
|
data: List<T>, selected: Int?, onSelect: (Int) -> Unit,
|
||||||
singleWidget: @Composable (T) -> Unit,
|
singleWidget: @Composable (T) -> Unit,
|
||||||
editDialog: @Composable ((current: T, onExit: () -> Unit) -> Unit)? = null,
|
editDialog: @Composable ((current: T, onExit: () -> Unit) -> Unit)? = null,
|
||||||
|
deleter: ((T) -> Unit)? = null,
|
||||||
dialog: @Composable (onExit: () -> Unit) -> Unit
|
dialog: @Composable (onExit: () -> Unit) -> Unit
|
||||||
) = Column(Modifier.padding(10.dp)) {
|
) = Column(Modifier.padding(10.dp)) {
|
||||||
Text(header, style = MaterialTheme.typography.headlineMedium)
|
Text(header, style = MaterialTheme.typography.headlineMedium)
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
var current by remember { mutableStateOf<T?>(null) }
|
var current by remember { mutableStateOf<T?>(null) }
|
||||||
|
var deleting by remember { mutableStateOf<T?>(null) }
|
||||||
|
|
||||||
ListOrEmpty(
|
ListOrEmpty(
|
||||||
data,
|
data,
|
||||||
|
@ -141,6 +143,11 @@ fun <T> EditionSideWidget(
|
||||||
Icon(Icons.Default.Edit, "Edit")
|
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 <T> EditionSideWidget(
|
||||||
d(c) { current = null }
|
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
|
@Composable
|
||||||
|
@ -290,11 +315,12 @@ fun AssignmentsWidget(
|
||||||
@Composable
|
@Composable
|
||||||
fun GroupAssignmentsWidget(
|
fun GroupAssignmentsWidget(
|
||||||
course: Course, edition: Edition, assignments: List<GroupAssignment>, selected: Int?,
|
course: Course, edition: Edition, assignments: List<GroupAssignment>, 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(
|
) = EditionSideWidget(
|
||||||
course, edition, "Group assignment list", "group assignments", "an assignment", assignments, selected, onSelect,
|
course, edition, "Group assignment list", "group assignments", "an assignment", assignments, selected, onSelect,
|
||||||
{ Text(it.name, Modifier.padding(5.dp)) },
|
{ 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 ->
|
) { onExit ->
|
||||||
AddStringDialog("Assignment title", assignments.map { it.name }, onExit) { onAdd(it) }
|
AddStringDialog("Assignment title", assignments.map { it.name }, onExit) { onAdd(it) }
|
||||||
}
|
}
|
|
@ -138,6 +138,15 @@ class EditionState(val edition: Edition) {
|
||||||
}
|
}
|
||||||
groupAs.refresh()
|
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) {
|
class StudentState(val student: Student, edition: Edition) {
|
||||||
|
|
Loading…
Reference in New Issue