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[];
|
children?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const colors: string[] = unique_colors(Object.keys(ALL_SHOPS).length);
|
|
||||||
|
|
||||||
export const common_calendarOptions: CalendarOptions = {
|
export const common_calendarOptions: CalendarOptions = {
|
||||||
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
|
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
|
||||||
plugins: [iCalendarPlugin, resourceTimeGridPlugin],
|
plugins: [iCalendarPlugin, resourceTimeGridPlugin],
|
||||||
@ -39,7 +37,15 @@ export const common_calendarOptions: CalendarOptions = {
|
|||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
hour12: false,
|
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 {
|
return {
|
||||||
id: shop_name,
|
id: shop_name,
|
||||||
title: 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);
|
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)
|
.filter(([shop_name, shop]) => shop.calendar !== undefined)
|
||||||
.forEach(([shop_name, shop], idx) => {
|
.forEach(([shop_name, shop], idx) => {
|
||||||
calendar.addEventSource({
|
calendar.addEventSource({
|
||||||
@ -82,7 +83,7 @@ export function main(
|
|||||||
// assume any event not for a specific tool is for the shop as a whole
|
// assume any event not for a specific tool is for the shop as a whole
|
||||||
eventData.resourceId = shop_name;
|
eventData.resourceId = shop_name;
|
||||||
}
|
}
|
||||||
if (allTools) {
|
if (showNewTools) {
|
||||||
if (!calendar.getResourceById(eventData.resourceId)) {
|
if (!calendar.getResourceById(eventData.resourceId)) {
|
||||||
calendar.addResource(
|
calendar.addResource(
|
||||||
{ id: eventData.resourceId, title: eventData.resourceId },
|
{ id: eventData.resourceId, title: eventData.resourceId },
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { CalendarOptions } from '@fullcalendar/core';
|
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 './wall-display.html';
|
||||||
import './modal.css';
|
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() {
|
function refresh() {
|
||||||
calendar.refetchEvents();
|
calendar.refetchEvents();
|
||||||
|
Loading…
Reference in New Issue
Block a user