This commit is contained in:
Andrew Lalis 2024-12-28 09:00:12 -05:00
parent 3f47be9653
commit 7c92c600e6
3 changed files with 88 additions and 28 deletions

View File

@ -0,0 +1,54 @@
<script setup lang="ts">
import { computed } from 'vue';
const props = defineProps<{
dateStr: string
}>()
defineEmits<{
(e: 'addAllEntriesClicked'): void
}>()
const date = computed(() => getDate(props.dateStr))
const weekday = computed(() => getWeekday(date.value))
function getDate(dateStr: string): Date {
const year = parseInt(dateStr.substring(0, 4), 10)
const month = parseInt(dateStr.substring(5, 7), 10)
const day = parseInt(dateStr.substring(8, 10), 10)
return new Date(year, month - 1, day)
}
function getWeekday(date: Date): string {
const names = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
return names[date.getDay()]
}
</script>
<template>
<th>
<div class="date-header-container">
<div class="date-header-button">
<span title="Add All Entries" @click="$emit('addAllEntriesClicked')">+</span>
</div>
<div>
<span>{{ weekday }}</span>
<br>
<span>{{ date.toLocaleDateString() }}</span>
</div>
</div>
</th>
</template>
<style scoped>
.date-header-container {
padding-left: 0.5em;
padding-right: 0.5em;
}
.date-header-button {
float: right;
}
.date-header-button:hover {
cursor: pointer;
}
</style>

View File

@ -8,8 +8,10 @@ import {
} from '@/api/classroom_compliance' } from '@/api/classroom_compliance'
import { useAuthStore } from '@/stores/auth' import { useAuthStore } from '@/stores/auth'
import { computed, onMounted, ref, type Ref } from 'vue' import { computed, onMounted, ref, type Ref } from 'vue'
import EntryTableCell from './EntryTableCell.vue' import EntryTableCell from '@/apps/classroom_compliance/EntryTableCell.vue'
import { RouterLink } from 'vue-router' import { RouterLink } from 'vue-router'
import StudentScoreCell from '@/apps/classroom_compliance/StudentScoreCell.vue'
import DateHeaderCell from '@/apps/classroom_compliance/DateHeaderCell.vue'
const authStore = useAuthStore() const authStore = useAuthStore()
const props = defineProps<{ const props = defineProps<{
@ -65,16 +67,28 @@ async function showPreviousWeek() {
} }
async function showThisWeek() { async function showThisWeek() {
const today = new Date()
today.setHours(0, 0, 0, 0)
// First set the to-date to the next upcoming end-of-week (Friday). // First set the to-date to the next upcoming end-of-week (Friday).
toDate.value = new Date() toDate.value = new Date()
toDate.value.setHours(0, 0, 0, 0) toDate.value.setHours(0, 0, 0, 0)
while (toDate.value.getDay() < 5) { if (today.getDay() >= 1 && today.getDay() <= 5) {
toDate.value.setDate(toDate.value.getDate() + 1) // If we're anywhere in the week, shift up to Friday.
const dayDiff = 5 - today.getDay()
toDate.value.setDate(today.getDate() + dayDiff)
} else {
// If it's Saturday or Sunday, shift back to the previous Friday.
if (today.getDay() === 6) {
toDate.value.setDate(today.getDate() - 1)
} else {
toDate.value.setDate(today.getDate() - 2)
}
} }
// Then set the from-date to the Monday of that week. // Then set the from-date to the Monday of that week.
fromDate.value = new Date() fromDate.value = new Date()
fromDate.value.setHours(0, 0, 0, 0) fromDate.value.setHours(0, 0, 0, 0)
fromDate.value.setDate(fromDate.value.getDate() - 4) fromDate.value.setDate(toDate.value.getDate() - 4)
await loadEntries() await loadEntries()
} }
@ -118,18 +132,6 @@ async function discardEdits() {
} }
} }
function getDate(dateStr: string): Date {
const year = parseInt(dateStr.substring(0, 4), 10)
const month = parseInt(dateStr.substring(5, 7), 10)
const day = parseInt(dateStr.substring(8, 10), 10)
return new Date(year, month - 1, day)
}
function getWeekday(date: Date): string {
const names = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
return names[date.getDay()]
}
function addAllEntriesForDate(dateStr: string) { function addAllEntriesForDate(dateStr: string) {
for (let i = 0; i < students.value.length; i++) { for (let i = 0; i < students.value.length; i++) {
const student = students.value[i] const student = students.value[i]
@ -159,12 +161,8 @@ function addAllEntriesForDate(dateStr: string) {
<tr> <tr>
<th>Student</th> <th>Student</th>
<th v-if="assignedDesks">Desk</th> <th v-if="assignedDesks">Desk</th>
<th v-for="date in dates" :key="date"> <DateHeaderCell v-for="date in dates" :key="date" :date-str="date"
<span>{{ getDate(date).toLocaleDateString() }}</span> @add-all-entries-clicked="addAllEntriesForDate(date)" />
<span @click="addAllEntriesForDate(date)"></span>
<br />
<span>{{ getWeekday(getDate(date)) }}</span>
</th>
<th>Score</th> <th>Score</th>
</tr> </tr>
</thead> </thead>
@ -178,12 +176,7 @@ function addAllEntriesForDate(dateStr: string) {
<td v-if="assignedDesks" v-text="student.deskNumber"></td> <td v-if="assignedDesks" v-text="student.deskNumber"></td>
<EntryTableCell v-for="(entry, date) in student.entries" :key="date" v-model="student.entries[date]" <EntryTableCell v-for="(entry, date) in student.entries" :key="date" v-model="student.entries[date]"
:date-str="date" :last-save-state-timestamp="lastSaveStateTimestamp" /> :date-str="date" :last-save-state-timestamp="lastSaveStateTimestamp" />
<td style="text-align: right; padding-right: 0.25em;"> <StudentScoreCell :score="student.score" />
<span v-if="student.score" style="font-family: monospace; font-size: large;">
{{ (student.score * 100).toFixed(1) }}%
</span>
<span v-if="!student.score" style="font-size: small; font-style: italic;">No score</span>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -0,0 +1,13 @@
<script setup lang="ts">
defineProps<{
score: number | null
}>()
</script>
<template>
<td style="text-align: right; padding-right: 0.25em;">
<span v-if="score !== null" style="font-family: monospace; font-size: large;">
{{ (score * 100).toFixed(1) }}%
</span>
<span v-if="score === null" style="font-size: small; font-style: italic;">No score</span>
</td>
</template>