wall-display: Only fetch the calendars that are used by the toolFilter
This commit is contained in:
parent
ec92effe91
commit
9e392fb945
@ -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 },
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user