From 7949fcdc683d07689bad5da5d20bfa3eeb5a6a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 5 Sep 2023 01:25:00 +0200 Subject: Move frontend code to subdirectories, to simplify command line flags. --- static/ts/globals.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 static/ts/globals.ts (limited to 'static/ts/globals.ts') diff --git a/static/ts/globals.ts b/static/ts/globals.ts new file mode 100644 index 00000000..243e15e4 --- /dev/null +++ b/static/ts/globals.ts @@ -0,0 +1,60 @@ +export { + find_block, + vcal_objects, event_calendar_mapping +} + +import { VEvent } from './vevent' +import { uid } from './types' +import { ComponentBlock } from './components/vevent-block' + +import { v4 as uuid } from 'uuid' +import { setup_popup_element } from './components/popup-element' + +const vcal_objects: Map = new Map; +const event_calendar_mapping: Map = new Map; + +declare global { + interface Window { + vcal_objects: Map; + VIEW: 'month' | 'week'; + EDIT_MODE: boolean; + default_calendar: string; + + addNewEvent(): void; + } +} +window.vcal_objects = vcal_objects; + + +window.addNewEvent = () => { + let ev = new VEvent(); + let uid = uuid() + let now = new Date() + /* Round seconds to 0, since time inputs wants exact seconds */ + now.setUTCSeconds(0); + ev.setProperties([ + ['uid', uid], + ['dtstart', now, 'date-time'], + ['dtend', new Date(now.getTime() + 3600 * 1000), 'date-time'], + ]) + ev.calendar = window.default_calendar; + + vcal_objects.set(uid, ev); + + let popup = setup_popup_element(ev); + popup.maximize(); +} + +function find_block(uid: uid): ComponentBlock | null { + let obj = vcal_objects.get(uid) + if (obj === undefined) { + return null; + } + for (let el of obj.registered) { + if (el instanceof ComponentBlock) { + return el; + } + } + // throw 'Popup not fonud'; + return null; +} -- cgit v1.2.3 From f653a01328be3b8be6af35c0c96867623765ca5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 5 Sep 2023 11:41:46 +0200 Subject: Move JS documentation into the JS-code. Texinfo was a bad match for how TypeScript is structured. This also allows generation of jsdoc pages, which can be nice. Another large win is that this opens up for the texinfo pages to replace the Guile heading with different subheadings, including - external library - internal library - C library - ... --- static/ts/globals.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'static/ts/globals.ts') diff --git a/static/ts/globals.ts b/static/ts/globals.ts index 243e15e4..75fb1df9 100644 --- a/static/ts/globals.ts +++ b/static/ts/globals.ts @@ -1,3 +1,10 @@ +/** + * Different variables and values which for different reasons needs to be + * global. Window Value's are those that are bound to the `window` + * context in JavaScript, so is really always available, no opt out. + * @module + */ + export { find_block, vcal_objects, event_calendar_mapping @@ -10,14 +17,38 @@ import { ComponentBlock } from './components/vevent-block' import { v4 as uuid } from 'uuid' import { setup_popup_element } from './components/popup-element' +/** + * All VEvent objects on current page, indexed by their unique identifiers. + * + * A global object store. + * + * Also bound to the window object for easy access. + */ const vcal_objects: Map = new Map; + +/** + * Mapping from VEvent unique identifier, to name of its calendar. Should + * probably not be global, so refrain from using it. + */ const event_calendar_mapping: Map = new Map; declare global { interface Window { vcal_objects: Map; + /** + * How the calendar is currently formatted. Should be set by the backend + * through a simple `script`-tag. + */ VIEW: 'month' | 'week'; + /** + * However editing of events is enabled or not. + * Should be set by the backend through a simple `script`-tag. + */ EDIT_MODE: boolean; + /** + * Name of the calendar to assume when creating new events. + * Should be set by the backend through a simple `script`-tag. + */ default_calendar: string; addNewEvent(): void; -- cgit v1.2.3 From e753d721519f72014241b3d2fc804a919f655769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 7 Sep 2023 02:58:41 +0200 Subject: Document remaining javascript items. --- static/ts/globals.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'static/ts/globals.ts') diff --git a/static/ts/globals.ts b/static/ts/globals.ts index 75fb1df9..1cdf1733 100644 --- a/static/ts/globals.ts +++ b/static/ts/globals.ts @@ -76,6 +76,10 @@ window.addNewEvent = () => { popup.maximize(); } +/** + Find the calendar block in the inline view containing the VEvent identified + by the uid +*/ function find_block(uid: uid): ComponentBlock | null { let obj = vcal_objects.get(uid) if (obj === undefined) { -- cgit v1.2.3