From 730776620a963b09b4c6ec856003d08b77672233 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 13 Oct 2022 00:52:36 -0400 Subject: [PATCH] Pre-define all resources, with shops as parents of tools --- src/common.ts | 81 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/src/common.ts b/src/common.ts index efbc740..f803e8c 100644 --- a/src/common.ts +++ b/src/common.ts @@ -4,17 +4,62 @@ import resourceTimeGridPlugin from '@fullcalendar/resource-timegrid'; import { unique_colors } from 'unique-colors'; -const calendars: { [key: string]: string } = { - computer_lab: '6mmjp85e4732ru6skf1dda54ls@group.calendar.google.com', - electronics: '1g8atbdschshrg2inf162rcqt4@group.calendar.google.com', - wood_shop: '4unv3ia1n9mc9u31n2n5lv8nd8@group.calendar.google.com', - fiber_arts_studio: '7gbndciog37ge0hd8ug33ml70k@group.calendar.google.com', - jewelry_studio: 'l0dl2jq3vhbi9f4lfmaf5negc0@group.calendar.google.com', - metal_shop: 'a4p97kiiafatqdr52c3a0cpre0@group.calendar.google.com', - room_reservations: 'f4ro53uklj2u6pr0se7ucskm6g@group.calendar.google.com', +interface Shop { + calendar?: string; + children?: string[]; +} + +const shops: { [key: string]: Shop } = { + Cafe: {}, // same calendar as mezzanine + 'Classroom / Computer Lab': { + calendar: '6mmjp85e4732ru6skf1dda54ls@group.calendar.google.com', + children: ['Printer, Canon iPF8400S 44" 8-Color/Pigment'], + }, + 'Digital Fabrication and Electronics Lab': { + calendar: '1g8atbdschshrg2inf162rcqt4@group.calendar.google.com', + children: [ + '3d printer, Lulzbot Taz 6', + '3d printer, Lulzbot Mini', + 'Laser Cutter, GLS Hybrid', + ], + }, + 'Fiber Arts Studio': { + calendar: '7gbndciog37ge0hd8ug33ml70k@group.calendar.google.com', + children: ['Mid Arm, Brother DQLT15'], + }, + 'Jewelry Studio': { + calendar: 'l0dl2jq3vhbi9f4lfmaf5negc0@group.calendar.google.com', + }, + 'Metal Shop': { + calendar: 'a4p97kiiafatqdr52c3a0cpre0@group.calendar.google.com', + children: [ + 'Plasma Cutter, Hypertherm Powermax85', + 'MIG Welder, Miller 210', + ], + }, + Mezzanine: { + calendar: 'f4ro53uklj2u6pr0se7ucskm6g@group.calendar.google.com', + }, + 'Wood Shop': { + calendar: '4unv3ia1n9mc9u31n2n5lv8nd8@group.calendar.google.com', + children: [ + 'ShopBot, PRSstandard 96-48-8, w/2.2hp Spindle', + 'Table Saw, SawStop 3HP 10"', + 'Planer, Powermatic 20"', + 'Jointer, Powermatic 8"', + ], + }, }; -const colors: string[] = unique_colors(Object.keys(calendars).length); +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); export const common_calendarOptions: CalendarOptions = { schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives', @@ -41,6 +86,18 @@ export const common_calendarOptions: CalendarOptions = { minute: '2-digit', hour12: false, }, + resources: Object.entries(shops).map(([shop, tools]) => { + return { + id: shop, + title: shop, + children: tools.children?.map((tool) => { + return { + id: tool, + title: tool, + }; + }), + }; + }), }; export function main( @@ -49,7 +106,7 @@ export function main( ) { const calendarEl = document.getElementById('calendar'); const calendar = new Calendar(calendarEl!, calendarOptions); - Object.values(calendars).forEach((id, idx) => + calendars.forEach((id, idx) => calendar.addEventSource({ url: '/calendar/ical/' + id + '/public/basic.ics', format: 'ics', @@ -64,7 +121,9 @@ export function main( eventData.title = `${member}`; eventData.resourceId = tool; if (allTools) { - calendar.addResource({ id: tool, title: tool }, false); + if (!calendar.getResourceById(tool)) { + calendar.addResource({ id: tool, title: tool }, false); + } } } return eventData;