Add shop resources based on events that don't match the tool pattern
This commit is contained in:
parent
77ef62503f
commit
48a55519f1
@ -54,15 +54,7 @@ const shops: { [key: string]: Shop } = {
|
||||
},
|
||||
};
|
||||
|
||||
function extract_calendars(shops: { [key: string]: Shop }): string[] {
|
||||
return Object.values(shops)
|
||||
.map((shop) => shop.calendar)
|
||||
.filter((calendar) => calendar !== undefined) as string[];
|
||||
}
|
||||
|
||||
const calendars: string[] = extract_calendars(shops);
|
||||
|
||||
const colors: string[] = unique_colors(calendars.length);
|
||||
const colors: string[] = unique_colors(Object.keys(shops).length);
|
||||
|
||||
export const common_calendarOptions: CalendarOptions = {
|
||||
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
|
||||
@ -113,9 +105,11 @@ export function main(
|
||||
) {
|
||||
const calendarEl = document.getElementById('calendar');
|
||||
const calendar = new Calendar(calendarEl!, calendarOptions);
|
||||
calendars.forEach((id, idx) =>
|
||||
Object.entries(shops)
|
||||
.filter(([shop_name, shop]) => shop.calendar !== undefined)
|
||||
.forEach(([shop_name, shop], idx) => {
|
||||
calendar.addEventSource({
|
||||
url: '/calendar/ical/' + id + '/public/basic.ics',
|
||||
url: '/calendar/ical/' + shop.calendar + '/public/basic.ics',
|
||||
format: 'ics',
|
||||
color: colors[idx],
|
||||
eventDataTransform: (eventData) => {
|
||||
@ -124,19 +118,25 @@ export function main(
|
||||
|
||||
const match = eventData?.title?.match(/([^\/]*) \| ([^-]*) - (.*)/);
|
||||
if (match) {
|
||||
const [, member, shop, tool] = match;
|
||||
const [, member, _event_shop, tool] = match;
|
||||
eventData.title = `${member}`;
|
||||
eventData.resourceId = tool;
|
||||
if (allTools) {
|
||||
if (!calendar.getResourceById(tool)) {
|
||||
calendar.addResource({ id: tool, title: tool }, false);
|
||||
} else {
|
||||
// assume any event not for a specific tool is for the shop as a whole
|
||||
eventData.resourceId = shop_name;
|
||||
}
|
||||
if (allTools) {
|
||||
if (!calendar.getResourceById(eventData.resourceId)) {
|
||||
calendar.addResource(
|
||||
{ id: eventData.resourceId, title: eventData.resourceId },
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
return eventData;
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
calendar.render();
|
||||
//calendar.gotoDate('2022-06-27');
|
||||
|
Loading…
Reference in New Issue
Block a user