diff --git a/app/src/apps/classroom_compliance/EntriesTable.vue b/app/src/apps/classroom_compliance/EntriesTable.vue index cdd46d1..3c2210f 100644 --- a/app/src/apps/classroom_compliance/EntriesTable.vue +++ b/app/src/apps/classroom_compliance/EntriesTable.vue @@ -5,6 +5,7 @@ import { type EntriesPayload, type EntriesPayloadStudent, type EntriesResponseStudent, + type Entry, } from '@/api/classroom_compliance' import { useAuthStore } from '@/stores/auth' import { computed, onMounted, ref, watch, type Ref } from 'vue' @@ -187,17 +188,27 @@ async function saveEdits() { async function discardEdits() { if (lastSaveState.value) { students.value = JSON.parse(lastSaveState.value) + // The user's preferred sorting might have changed while editing, so we should preserve that. + if (sortingChoice.value === 'name') { + students.value.sort(sortEntriesByName) + } else if (sortingChoice.value === 'desk') { + students.value.sort(sortEntriesByDeskNumber) + } } else { await loadEntries() } } +function getTodayISOStr(): string { + const today = new Date() + today.setUTCHours(0, 0, 0, 0) + return today.toISOString().substring(0, 10) +} + function getVisibleDates(): string[] { if (selectedView.value === TableView.FULL) return dates.value if (selectedView.value === TableView.TODAY) { - const today = new Date() - today.setUTCHours(0, 0, 0, 0) - const todayStr = today.toISOString().substring(0, 10) + const todayStr = getTodayISOStr() for (const date of dates.value) { if (date === todayStr) return [date] } @@ -205,6 +216,18 @@ function getVisibleDates(): string[] { return [] } +function getVisibleStudentEntries(student: EntriesResponseStudent): Record { + if (selectedView.value === TableView.FULL) return student.entries + if (selectedView.value === TableView.TODAY) { + // Only show today's date, if we have it, or null otherwise. + const todayStr = getTodayISOStr() + const obj: Record = {} + obj[todayStr] = student.entries[todayStr] + return obj + } + return {} +} + function addAllEntriesForDate(dateStr: string) { for (let i = 0; i < students.value.length; i++) { const student = students.value[i] @@ -262,7 +285,7 @@ function addAllEntriesForDate(dateStr: string) { - diff --git a/app/src/apps/classroom_compliance/entries_table/EntryTableCell.vue b/app/src/apps/classroom_compliance/entries_table/EntryTableCell.vue index 02c5097..8e39162 100644 --- a/app/src/apps/classroom_compliance/entries_table/EntryTableCell.vue +++ b/app/src/apps/classroom_compliance/entries_table/EntryTableCell.vue @@ -47,6 +47,7 @@ function toggleAbsence() { // If we have an initial entry known, restore data from that. if (initialEntryJson.value) { const initialEntry = JSON.parse(initialEntryJson.value) as Entry + if (initialEntry === null) return if (initialEntry.absent) return if (initialEntry.phoneCompliant) { model.value.phoneCompliant = initialEntry.phoneCompliant