From 9e392fb9452a197338bc908444f20b4175475bb7 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 27 Dec 2023 11:07:54 -0500 Subject: [PATCH] wall-display: Only fetch the calendars that are used by the toolFilter --- src/common.ts | 27 ++++++++++++++------------- src/wall-display.ts | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/common.ts b/src/common.ts index fc4e4e7..7275a7d 100644 --- a/src/common.ts +++ b/src/common.ts @@ -11,8 +11,6 @@ interface Shop { children?: string[]; } -const colors: string[] = unique_colors(Object.keys(ALL_SHOPS).length); - export const common_calendarOptions: CalendarOptions = { schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives', plugins: [iCalendarPlugin, resourceTimeGridPlugin], @@ -39,7 +37,15 @@ export const common_calendarOptions: CalendarOptions = { minute: '2-digit', hour12: false, }, - resources: Object.entries(ALL_SHOPS).map(([shop_name, shop]) => { +}; + +export function main( + calendarOptions: CalendarOptions, + showNewTools: boolean = false, + shops: { [key: string]: Shop } = ALL_SHOPS +) { + const calendarEl = document.getElementById('calendar'); + calendarOptions.resources = Object.entries(shops).map(([shop_name, shop]) => { return { id: shop_name, title: shop_name, @@ -53,16 +59,11 @@ export const common_calendarOptions: CalendarOptions = { }; }), }; - }), -}; - -export function main( - calendarOptions: CalendarOptions, - allTools: boolean = false -) { - const calendarEl = document.getElementById('calendar'); + }); const calendar = new Calendar(calendarEl!, calendarOptions); - Object.entries(ALL_SHOPS) + + const colors: string[] = unique_colors(Object.keys(shops).length); + Object.entries(shops) .filter(([shop_name, shop]) => shop.calendar !== undefined) .forEach(([shop_name, shop], idx) => { calendar.addEventSource({ @@ -82,7 +83,7 @@ export function main( // assume any event not for a specific tool is for the shop as a whole eventData.resourceId = shop_name; } - if (allTools) { + if (showNewTools) { if (!calendar.getResourceById(eventData.resourceId)) { calendar.addResource( { id: eventData.resourceId, title: eventData.resourceId }, diff --git a/src/wall-display.ts b/src/wall-display.ts index ca25342..889888a 100644 --- a/src/wall-display.ts +++ b/src/wall-display.ts @@ -1,6 +1,6 @@ import type { CalendarOptions } from '@fullcalendar/core'; -import { common_calendarOptions, main } from './common'; +import { ALL_SHOPS, common_calendarOptions, main } from './common'; import './wall-display.html'; import './modal.css'; @@ -61,7 +61,19 @@ const calendarOptions: CalendarOptions = { }, }; -const calendar = main(calendarOptions, !toolFilter); +const calendar = main( + calendarOptions, + !toolFilter, + toolFilter + ? Object.fromEntries( + Object.entries(ALL_SHOPS).filter( + ([shop_name, shop]) => + toolFilter.includes(shop_name) || + shop.children?.some((t) => toolFilter.includes(t)) + ) + ) + : ALL_SHOPS +); function refresh() { calendar.refetchEvents();