From 9a46ea5af005c8bb9090bdfba84e56678ad81677 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 6 Sep 2025 15:54:58 +0200 Subject: [PATCH] Add cancelled field to event slots Make it possible to represent one slot out of a multi-slot event being cancelled by adding a field for it in the slot, in addition to the existing field on the event itself. --- components/TableScheduleEventSlots.vue | 1 + shared/types/api.ts | 1 + utils/client-schedule.nuxt.test.ts | 5 +++-- utils/client-schedule.ts | 10 ++++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/components/TableScheduleEventSlots.vue b/components/TableScheduleEventSlots.vue index 5661865..9699f79 100644 --- a/components/TableScheduleEventSlots.vue +++ b/components/TableScheduleEventSlots.vue @@ -318,6 +318,7 @@ function newEventSlot(options: { start?: DateTime, end?: DateTime } = {}) { start, end, new Set(newEventLocationIds.value), + false, new Set(), 0, ); diff --git a/shared/types/api.ts b/shared/types/api.ts index dbec20a..d1994e0 100644 --- a/shared/types/api.ts +++ b/shared/types/api.ts @@ -81,6 +81,7 @@ export const apiScheduleEventSlotSchema = z.object({ start: z.string(), end: z.string(), locationIds: z.array(idSchema), + cancelled: z.optional(z.boolean()), assigned: z.optional(z.array(z.number())), interested: z.optional(z.number()), }); diff --git a/utils/client-schedule.nuxt.test.ts b/utils/client-schedule.nuxt.test.ts index 2fddf34..e422633 100644 --- a/utils/client-schedule.nuxt.test.ts +++ b/utils/client-schedule.nuxt.test.ts @@ -28,8 +28,8 @@ function fixtureClientSchedule(multiSlot = false) { ), ]; const eventSlots = idMap([ - new ClientScheduleEventSlot(1, false, false, 1, now, now.plus({ hours: 1 }), new Set([left.id]), new Set(), 0), - new ClientScheduleEventSlot(2, false, false, multiSlot ? 1 : 2, now, now.plus({ hours: 2 }), new Set([right.id]), new Set(), 0), + new ClientScheduleEventSlot(1, false, false, 1, now, now.plus({ hours: 1 }), new Set([left.id]), false, new Set(), 0), + new ClientScheduleEventSlot(2, false, false, multiSlot ? 1 : 2, now, now.plus({ hours: 2 }), new Set([right.id]), false, new Set(), 0), ]); const red = new ClientScheduleRole(1, now, false, "Red", "Is a color."); @@ -277,6 +277,7 @@ describe("class ClientSchedule", () => { now, now.plus({ hours: 3 }), new Set(), + false, new Set(), 0, ); diff --git a/utils/client-schedule.ts b/utils/client-schedule.ts index 2772503..7334163 100644 --- a/utils/client-schedule.ts +++ b/utils/client-schedule.ts @@ -295,6 +295,7 @@ export class ClientScheduleEventSlot { serverStart: DateTime; serverEnd: DateTime; serverLocationIds: Set; + serverCancelled: boolean; serverAssigned: Set; serverInterested: number; @@ -306,6 +307,7 @@ export class ClientScheduleEventSlot { public start: DateTime, public end: DateTime, public locationIds: Set, + public cancelled: boolean, public assigned: Set, public interested: number, ) { @@ -314,6 +316,7 @@ export class ClientScheduleEventSlot { this.serverStart = start; this.serverEnd = end; this.serverLocationIds = new Set(locationIds); + this.serverCancelled = cancelled; this.serverAssigned = new Set(assigned); this.serverInterested = interested; } @@ -327,6 +330,7 @@ export class ClientScheduleEventSlot { || this.start.toMillis() !== this.serverStart.toMillis() || this.end.toMillis() !== this.serverEnd.toMillis() || !setEquals(this.locationIds, this.serverLocationIds) + || this.cancelled !== this.serverCancelled || !setEquals(this.assigned, this.serverAssigned) || this.interested !== this.serverInterested ); @@ -349,6 +353,7 @@ export class ClientScheduleEventSlot { this.start = this.serverStart; this.end = this.serverEnd; this.locationIds = new Set(this.serverLocationIds); + this.cancelled = this.serverCancelled; this.assigned = new Set(this.serverAssigned); this.interested = this.serverInterested; } @@ -360,6 +365,7 @@ export class ClientScheduleEventSlot { start: DateTime, end: DateTime, locationIds: Set, + cancelled: boolean, assigned: Set, interested: number, ) { @@ -371,6 +377,7 @@ export class ClientScheduleEventSlot { start, end, locationIds, + cancelled, assigned, interested, ); @@ -391,6 +398,7 @@ export class ClientScheduleEventSlot { DateTime.fromISO(api.start, opts), DateTime.fromISO(api.end, opts), new Set(api.locationIds), + api.cancelled ?? false, new Set(api.assigned), api.interested ?? 0, ); @@ -408,6 +416,7 @@ export class ClientScheduleEventSlot { this.serverStart = DateTime.fromISO(api.start, opts); this.serverEnd = DateTime.fromISO(api.end, opts); this.serverLocationIds = new Set(api.locationIds); + this.serverCancelled = api.cancelled ?? false; this.serverAssigned = new Set(api.assigned); this.serverInterested = api.interested ?? 0; if (!wasModified || !this.isModified()) { @@ -424,6 +433,7 @@ export class ClientScheduleEventSlot { start: toIso(this.start), end: toIso(this.end), locationIds: [...this.locationIds], + cancelled: this.cancelled || undefined, assigned: this.assigned.size ? [...this.assigned] : undefined, interested: this.interested || undefined, }