From 59e512903a68f368aee02f4afcfff4f9eee787b5 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sun, 26 Jan 2025 20:18:39 +0100 Subject: [PATCH] Add fixes to slot select --- .../coursebook/absences/AbsenceCreationForm.vue | 12 ++++++++---- aleksis/apps/alsijil/schema/__init__.py | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue b/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue index 601c2916a..13fcd9ddc 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/absences/AbsenceCreationForm.vue @@ -186,16 +186,19 @@ export default { getPeriodsForWeekday(weekday) { // Adapt from python conventions const pythonWeekday = weekday - 1; - return this.periodsByDay.find( + let periodsForWeekday = this.periodsByDay.find( (period) => period.weekday === pythonWeekday, - ).periods; + ); + if (!periodsForWeekday) return false; + return periodsForWeekday.periods; }, handleStartDate(date) { this.start = DateTime.fromISO(date); - if (this.periodsByDay.length > 0) { + if (this.periodsByDay && this.periodsByDay.length > 0) { // Select periods for day this.startPeriods = this.getPeriodsForWeekday(this.start.weekday); + if (!this.startPeriods) return; // Sync PeriodSelect const startTime = this.start.toFormat("HH:mm:ss"); this.startSlot = this.startPeriods.find( @@ -206,9 +209,10 @@ export default { handleEndDate(date) { this.end = DateTime.fromISO(date); - if (this.periodsByDay.length > 0) { + if (this.periodsByDay && this.periodsByDay.length > 0) { // Select periods for day this.endPeriods = this.getPeriodsForWeekday(this.end.weekday); + if (!this.endPeriods) return; // Sync PeriodSelect const endTime = this.end.toFormat("HH:mm:ss"); this.endSlot = this.endPeriods.find( diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py index 0c75517fd..1614cf0f3 100644 --- a/aleksis/apps/alsijil/schema/__init__.py +++ b/aleksis/apps/alsijil/schema/__init__.py @@ -368,7 +368,9 @@ class Query(graphene.ObjectType): Slot = apps.get_model("lesrooster", "Slot") ValidityRange = apps.get_model("lesrooster", "ValidityRange") slots = ( - Slot.objects.filter(time_grid__validity_range=ValidityRange.current) + Slot.objects.filter( + time_grid__validity_range=ValidityRange.current, period__isnull=False + ) .order_by("weekday") .values("weekday", "period", "time_start", "time_end") ) -- GitLab