- {{ role.name }}
+ {{ schedule.roles.get(id!)?.name }}
|
>,
- roles: Map>,
+ roles: Map>,
};
/**
@@ -238,9 +237,10 @@ function* spansFromJunctions(
const activeLocations = new Map(
[...locations.keys()].map(id => [id, new Set()])
);
- const activeRoles = new Map(
- [...roles.keys()].map(id => [id, new Set()])
+ const activeRoles = new Map>(
+ [...roles.keys()].map(id => [id, new Set()]),
);
+ activeRoles.set(undefined, new Set());
for (const [start, end] of pairs(junctions)) {
for (const edge of start.edges) {
if (edge.type === "start") {
@@ -249,7 +249,7 @@ function* spansFromJunctions(
activeLocations.get(locationId)?.add(edge.slot)
}
} else if (edge.source === "shift") {
- activeRoles.get(edge.roleId)?.add(edge.slot)
+ activeRoles.get(edge.roleId)?.add(edge.slot);
}
}
}
@@ -403,7 +403,8 @@ function tableElementsFromStretches(
const dayHeaders: DayHead[] = [];
const hourHeaders: HourHead[]= [];
const locationGroups = new Map([...locations.keys()].map(id => [id, []]));
- const roleGroups = new Map([...roles.keys()].map(id => [id, []]));
+ const roleGroups = new Map([...roles.keys()].map(id => [id, []]));
+ roleGroups.set(undefined, []);
const eventBySlotId = new Map([...events.values()].flatMap(event => [...event.slots.values()].map(slot => [slot.id, event])));
const shiftBySlotId = new Map([...shifts.values()].flatMap?.(shift => [...shift.slots.values()].map(slot =>[slot.id, shift])));
let totalColumns = 0;
@@ -443,7 +444,7 @@ function tableElementsFromStretches(
row.push({ span: 0, isBreak, slot, event: eventBySlotId.get(slot.id) });
}
}
- function startRole(id: number, isBreak: boolean, newSlots = new Set()) {
+ function startRole(id: number | undefined, isBreak: boolean, newSlots = new Set()) {
const group = roleGroups.get(id)!;
// Remove all slots that are no longer in the new slots.
for (const row of group) {
@@ -481,9 +482,8 @@ function tableElementsFromStretches(
row[row.length - 1].span += 1;
}
}
- for(const role of roles.values()) {
- const group = roleGroups.get(role.id)!;
- for (const row of group) {
+ for (const roleGroup of roleGroups.values()) {
+ for (const row of roleGroup) {
row[row.length - 1].span += 1;
}
}
@@ -500,8 +500,8 @@ function tableElementsFromStretches(
for (const location of locations.values()) {
startLocation(location.id, false);
}
- for (const role of roles.values()) {
- startRole(role.id, false);
+ for (const roleId of roleGroups.keys()) {
+ startRole(roleId, false);
}
} else {
startColumnGroup(lastStretch.end, stretch.start, 1, true);
@@ -514,8 +514,8 @@ function tableElementsFromStretches(
for(const location of locations.values()) {
startLocation(location.id, true);
}
- for(const role of roles.values()) {
- startRole(role.id, true);
+ for (const roleId of roleGroups.keys()) {
+ startRole(roleId, true);
}
pushColumn();
@@ -526,8 +526,8 @@ function tableElementsFromStretches(
for(const location of locations.values()) {
startLocation(location.id, false);
}
- for(const role of roles.values()) {
- startRole(role.id, false);
+ for (const roleId of roleGroups.keys()) {
+ startRole(roleId, false);
}
}
@@ -544,12 +544,12 @@ function tableElementsFromStretches(
startLocation(location.id, false, slots)
}
}
- for (const role of roles.values()) {
- const slots = cutSpan.roles.get(role.id) ?? new Set();
- const group = roleGroups.get(role.id)!;
+ for (const roleId of roleGroups.keys()) {
+ const slots = cutSpan.roles.get(roleId) ?? new Set();
+ const group = roleGroups.get(roleId)!;
const existing = new Set(group.map(row => row[row.length - 1].slot).filter(slot => slot));
if (!setEquals(slots, existing)) {
- startRole(role.id, false, slots);
+ startRole(roleId, false, slots);
}
}
diff --git a/shared/types/api.ts b/shared/types/api.ts
index 49b54a3..2b526fa 100644
--- a/shared/types/api.ts
+++ b/shared/types/api.ts
@@ -111,7 +111,7 @@ export const apiScheduleShiftSlotSchema = z.object({
export type ApiScheduleShiftSlot = z.infer;
export const apiScheduleShiftSchema = defineApiEntity({
- roleId: idSchema,
+ roleId: z.optional(idSchema),
name: z.string(),
description: z.optional(z.string()),
slots: z.array(apiScheduleShiftSlotSchema),
diff --git a/utils/client-schedule.ts b/utils/client-schedule.ts
index 8f08fbb..f28b6f8 100644
--- a/utils/client-schedule.ts
+++ b/utils/client-schedule.ts
@@ -515,7 +515,7 @@ export class ClientScheduleRole extends ClientEntity {
export class ClientScheduleShift extends ClientEntity {
schedule!: ClientSchedule;
- serverRoleId: Id;
+ serverRoleId: Id | undefined;
serverName: string;
serverDescription: string;
serverSlotIds: Set;
@@ -524,7 +524,7 @@ export class ClientScheduleShift extends ClientEntity {
id: Id,
updatedAt: DateTime,
deleted: boolean,
- public roleId: Id,
+ public roleId: Id | undefined,
public name: string,
public description: string,
public slotIds: Set,
@@ -572,7 +572,7 @@ export class ClientScheduleShift extends ClientEntity {
static create(
schedule: ClientSchedule,
id: Id,
- roleId: Id,
+ roleId: Id | undefined,
name: string,
description: string,
slotIds: Set,
|