Add shop resources based on events that don't match the tool pattern

This commit is contained in:
Adam Goldsmith 2023-09-21 23:10:44 -04:00
parent 77ef62503f
commit 18176196cf

View File

@ -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,30 +105,39 @@ export function main(
) {
const calendarEl = document.getElementById('calendar');
const calendar = new Calendar(calendarEl!, calendarOptions);
calendars.forEach((id, idx) =>
calendar.addEventSource({
url: '/calendar/ical/' + id + '/public/basic.ics',
format: 'ics',
color: colors[idx],
eventDataTransform: (eventData) => {
// clear the url to prevent clicking on the event
delete eventData.url;
Object.entries(shops)
.filter(([shop_name, shop]) => shop.calendar !== undefined)
.forEach(([shop_name, shop], idx) => {
calendar.addEventSource({
url: '/calendar/ical/' + shop.calendar + '/public/basic.ics',
format: 'ics',
color: colors[idx],
eventDataTransform: (eventData) => {
// clear the url to prevent clicking on the event
delete eventData.url;
const match = eventData?.title?.match(/([^\/]*) \| ([^-]*) - (.*)/);
if (match) {
const [, member, shop, tool] = match;
eventData.title = `${member}`;
eventData.resourceId = tool;
const match = eventData?.title?.match(/([^\/]*) \| ([^-]*) - (.*)/);
if (match) {
const [, member, _event_shop, tool] = match;
eventData.title = `${member}`;
eventData.resourceId = tool;
} else {
// assume any event not for a specific tool is for the shop as a whole
eventData.resourceId = shop_name;
}
console.log(eventData.resourceId);
if (allTools) {
if (!calendar.getResourceById(tool)) {
calendar.addResource({ id: tool, title: tool }, false);
if (!calendar.getResourceById(eventData.resourceId)) {
calendar.addResource(
{ id: eventData.resourceId, title: eventData.resourceId },
false
);
}
}
}
return eventData;
},
})
);
return eventData;
},
});
});
calendar.render();
//calendar.gotoDate('2022-06-27');