Fixed today view
Build and Test App / Build-and-test-App (push) Successful in 33s
Details
Build and Test App / Build-and-test-App (push) Successful in 33s
Details
This commit is contained in:
parent
4349e4f2c3
commit
4cec4b8328
|
@ -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<string, Entry | null> {
|
||||
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<string, Entry | null> = {}
|
||||
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) {
|
|||
<!-- Desk Number: -->
|
||||
<td v-if="assignedDesks" v-text="student.deskNumber"></td>
|
||||
<!-- A cell for each entry in the table's date range: -->
|
||||
<EntryTableCell v-for="(entry, date) in selectedView === TableView.FULL ? student.entries : []" :key="date"
|
||||
<EntryTableCell v-for="(entry, date) in getVisibleStudentEntries(student)" :key="date"
|
||||
v-model="student.entries[date]" :date-str="date" :last-save-state-timestamp="lastSaveStateTimestamp" />
|
||||
<!-- Score cell: -->
|
||||
<StudentScoreCell :score="student.score" v-if="selectedView !== TableView.WHITEBOARD" />
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue