Refactor ClientSchedule to mutable types
All checks were successful
/ build (push) Successful in 1m30s
/ deploy (push) Successful in 16s

Use a single mutable location, event, slot, etc, for each unique
resource that keeps track of the local editable client copy and
the server copy of the data contained in it.

This makes it much simpler to update these data structures as I can take
advantage of the v-model bindings in Vue.js and work with the system
instead of against it.
This commit is contained in:
Hornwitser 2025-06-23 22:46:39 +02:00
parent d48fb035b4
commit e3ff872b5c
16 changed files with 1213 additions and 1125 deletions

View file

@ -191,8 +191,8 @@ function* edgesFromShifts(
if (slot.start > slot.end) {
throw new Error(`Slot ${slot.id} ends before it starts.`);
}
yield { type: "start", source: "shift", roleId: shift.role.id, slot };
yield { type: "end", source: "shift", roleId: shift.role.id, slot };
yield { type: "start", source: "shift", roleId: shift.roleId, slot };
yield { type: "end", source: "shift", roleId: shift.roleId, slot };
}
}
}
@ -214,8 +214,8 @@ function junctionsFromEdges(edges: Iterable<Edge>) {
function* spansFromJunctions(
junctions: Iterable<Junction>,
locations: Map<Id, ClientScheduleLocation>,
roles: Map<Id, ClientScheduleRole>,
locations: ClientMap<ClientScheduleLocation>,
roles: ClientMap<ClientScheduleRole>,
): Generator<Span> {
const activeLocations = new Map(
[...locations.keys()].map(id => [id, new Set<ClientScheduleEventSlot>()])
@ -227,8 +227,8 @@ function* spansFromJunctions(
for (const edge of start.edges) {
if (edge.type === "start") {
if (edge.source === "event") {
for (const location of edge.slot.locations) {
activeLocations.get(location.id)?.add(edge.slot)
for (const locationId of edge.slot.locationIds) {
activeLocations.get(locationId)?.add(edge.slot)
}
} else if (edge.source === "shift") {
activeRoles.get(edge.roleId)?.add(edge.slot)
@ -252,8 +252,8 @@ function* spansFromJunctions(
for (const edge of end.edges) {
if (edge.type === "end") {
if (edge.source === "event") {
for (const location of edge.slot.locations) {
activeLocations.get(location.id)?.delete(edge.slot)
for (const locationId of edge.slot.locationIds) {
activeLocations.get(locationId)?.delete(edge.slot)
}
} else if (edge.source === "shift") {
activeRoles.get(edge.roleId)?.delete(edge.slot);
@ -367,10 +367,10 @@ function padStretch(stretch: Stretch, timezone: string): Stretch {
function tableElementsFromStretches(
stretches: Iterable<Stretch>,
events: Map<Id, ClientScheduleEvent>,
locations: Map<Id, ClientScheduleLocation>,
shifts: Map<Id, ClientScheduleShift>,
roles: Map<Id, ClientScheduleRole>,
events: ClientMap<ClientScheduleEvent>,
locations: ClientMap<ClientScheduleLocation>,
shifts: ClientMap<ClientScheduleShift>,
roles: ClientMap<ClientScheduleRole>,
timezone: string,
) {
type Col = { minutes?: number };