From 6b80457da5c4920a993c14b8a85a04b65f9c8e74 Mon Sep 17 00:00:00 2001 From: jay-tux Date: Tue, 29 Apr 2025 14:28:46 +0200 Subject: [PATCH] UI change: show group member role in peer evaluation view --- .../kotlin/com/jaytux/grader/ui/Assignments.kt | 17 +++++++++++++++-- .../com/jaytux/grader/viewmodel/DbState.kt | 13 +++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Assignments.kt b/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Assignments.kt index 3010eed..9132253 100644 --- a/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Assignments.kt +++ b/composeApp/src/desktopMain/kotlin/com/jaytux/grader/ui/Assignments.kt @@ -26,6 +26,7 @@ import com.jaytux.grader.viewmodel.SoloAssignmentState import com.mohamedrejeb.richeditor.model.rememberRichTextState import com.mohamedrejeb.richeditor.ui.material3.OutlinedRichTextEditor import kotlinx.datetime.LocalDateTime +import org.jetbrains.exposed.sql.transactions.inTopLevelTransaction @Composable fun GroupAssignmentView(state: GroupAssignmentState) { @@ -585,9 +586,21 @@ fun PeerEvaluationView(state: PeerEvaluationState) { } MeasuredLazyColumn(key = idx) { measuredItem { HLine() } - items(current.students) { (from, glob, map) -> + items(current.students) { (from, role, glob, map) -> Row(Modifier.height(cellSize)) { - Text(from.name, Modifier.width(textLenMeasured.dp).align(Alignment.CenterVertically)) + Column(Modifier.width(textLenMeasured.dp).align(Alignment.CenterVertically)) { + Text(from.name, Modifier.width(textLenMeasured.dp)) + role?.let { r -> + Row { + Spacer(Modifier.width(10.dp)) + Text( + r, + style = MaterialTheme.typography.bodySmall, + fontStyle = FontStyle.Italic + ) + } + } + } LazyRow(state = horScroll) { item { VLine() } items(map) { (to, entry) -> 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 be48be2..0ad0483 100644 --- a/composeApp/src/desktopMain/kotlin/com/jaytux/grader/viewmodel/DbState.kt +++ b/composeApp/src/desktopMain/kotlin/com/jaytux/grader/viewmodel/DbState.kt @@ -722,7 +722,7 @@ class SoloAssignmentState(val assignment: SoloAssignment) { class PeerEvaluationState(val evaluation: PeerEvaluation) { data class Student2StudentEntry(val grade: String, val feedback: String) - data class StudentEntry(val student: Student, val global: Student2StudentEntry?, val others: List>) + data class StudentEntry(val student: Student, val role: String?, val global: Student2StudentEntry?, val others: List>) data class GroupEntry(val group: Group, val content: String, val students: List) val editionCourse = transaction { evaluation.edition.course to evaluation.edition } private val _name = mutableStateOf(evaluation.name); val name = _name.immutable() @@ -739,6 +739,9 @@ class PeerEvaluationState(val evaluation: PeerEvaluation) { } val students = group.students.map { from -> + val role = GroupStudents.selectAll().where { (GroupStudents.studentId eq from.id) and (GroupStudents.groupId eq group.id) }.firstOrNull()?.let { + it[GroupStudents.role] + } val s2g = StudentToGroupEvaluation.selectAll().where { (StudentToGroupEvaluation.peerEvaluationId eq evaluation.id) and (StudentToGroupEvaluation.studentId eq from.id) @@ -758,7 +761,7 @@ class PeerEvaluationState(val evaluation: PeerEvaluation) { other to eval } - StudentEntry(from, s2g, others) + StudentEntry(from, role, s2g, others) } GroupEntry(group, globalNotes ?: "", students) @@ -767,7 +770,6 @@ class PeerEvaluationState(val evaluation: PeerEvaluation) { fun upsertGroupFeedback(group: Group, feedback: String) { transaction { - println("Upserting group-level notes for ${group.name} (${evaluation.name})") PeerEvaluationContents.upsert { it[peerEvaluationId] = evaluation.id it[groupId] = group.id @@ -780,7 +782,6 @@ class PeerEvaluationState(val evaluation: PeerEvaluation) { fun upsertIndividualFeedback(from: Student, to: Student?, grade: String, feedback: String) { transaction { to?.let { - println("Upserting individual feedback for ${from.name} -> ${to.name} (${evaluation.name})") StudentToStudentEvaluation.upsert { it[peerEvaluationId] = evaluation.id it[studentIdFrom] = from.id @@ -794,10 +795,6 @@ class PeerEvaluationState(val evaluation: PeerEvaluation) { it[this.grade] = grade it[this.note] = feedback } - - if(to == null) { - println("Upserting group-level feedback for ${from.name} ${from.id.value} (${evaluation.name} ${evaluation.id.value})") - } } contents.refresh() }