From 410404cfdd54c083b6609fd52334e02d320145d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 10 Nov 2021 01:40:22 +0100 Subject: Re-modularize javascript. This moves almost everything out of globals.ts, into sepparate files. Things are still slightly to tightly coupled. But that is worked on. --- static/components/vevent.ts | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 static/components/vevent.ts (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts new file mode 100644 index 00000000..de232794 --- /dev/null +++ b/static/components/vevent.ts @@ -0,0 +1,71 @@ +export { ComponentVEvent } + +import { vcal_objects } from '../globals' +import { VEvent } from '../vevent' + +/* Root component for all events which content is closely linked to a +@code{VEvent} object + +Lacks an accompaning tag, and shouldn't be directly instanciated. +*/ +class ComponentVEvent extends HTMLElement { + + template: HTMLTemplateElement + uid: string + + constructor(uid?: string) { + super(); + this.template = document.getElementById(this.tagName) as HTMLTemplateElement; + + let real_uid; + if (this.dataset.uid) uid = this.dataset.uid; + if (uid) real_uid = uid; + + if (!real_uid) { + throw `UID required` + } + + this.uid = real_uid; + + vcal_objects.get(this.uid)?.register(this); + + /* We DON'T have a redraw here in the general case, since the + HTML rendered server-side should be fine enough for us. + Those that need a direct rerendering (such as the edit tabs) + should take care of that some other way */ + } + + connectedCallback() { + let uid, v; + if ((uid = this.dataset.uid)) { + v = vcal_objects.get(uid) + if (v) this.redraw(v); + } + } + + redraw(data: VEvent) { + // update ourselves from template + + if (!this.template) { + throw "Something"; + } + + let body = (this.template.content.cloneNode(true) as DocumentFragment).firstElementChild!; + + for (let el of body.getElementsByClassName("bind")) { + if (!(el instanceof HTMLElement)) continue; + let p = el.dataset.property!; + let d, fmt; + if ((d = data.getProperty(p))) { + if ((fmt = el.dataset.fmt)) { + el.innerHTML = d.format(fmt); + } else { + el.innerHTML = d; + } + } + } + + this.replaceChildren(body); + } + +} -- cgit v1.2.3 From ecdb4b7eeb42dc859cfd6aa31634b423b72c50bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 15 Nov 2021 00:47:13 +0100 Subject: Rework some drawing and how calendar is accessed. --- static/components/vevent.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index de232794..d957c7c8 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -26,6 +26,7 @@ class ComponentVEvent extends HTMLElement { } this.uid = real_uid; + this.dataset.uid = uid; vcal_objects.get(this.uid)?.register(this); @@ -36,9 +37,9 @@ class ComponentVEvent extends HTMLElement { } connectedCallback() { - let uid, v; - if ((uid = this.dataset.uid)) { - v = vcal_objects.get(uid) + let uid = this.dataset.uid + if (uid) { + let v = vcal_objects.get(uid) if (v) this.redraw(v); } } -- cgit v1.2.3 From 74102c3f5f400542a09c5c5fc1043ab5fa490be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 18 Nov 2021 23:15:35 +0100 Subject: Change popup tabs interface. --- static/components/vevent.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index d957c7c8..23eba0a9 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -22,6 +22,7 @@ class ComponentVEvent extends HTMLElement { if (uid) real_uid = uid; if (!real_uid) { + console.warn(this.outerHTML); throw `UID required` } -- cgit v1.2.3 From b3d72678192902252613e654c3fada1e57250ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 22 Nov 2021 01:09:04 +0100 Subject: Change innerHTML to textContent. Also changed some innerText to textContent --- static/components/vevent.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index 23eba0a9..cf28045a 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -60,9 +60,9 @@ class ComponentVEvent extends HTMLElement { let d, fmt; if ((d = data.getProperty(p))) { if ((fmt = el.dataset.fmt)) { - el.innerHTML = d.format(fmt); + el.textContent = d.format(fmt); } else { - el.innerHTML = d; + el.textContent = d; } } } -- cgit v1.2.3 From 0cfa00fc43eaf98db8b2461a2d07687b6591cd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 26 Nov 2021 17:14:30 +0100 Subject: Remove default ComponentVEvent redraw. --- static/components/vevent.ts | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index cf28045a..561051fa 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -8,7 +8,7 @@ import { VEvent } from '../vevent' Lacks an accompaning tag, and shouldn't be directly instanciated. */ -class ComponentVEvent extends HTMLElement { +abstract class ComponentVEvent extends HTMLElement { template: HTMLTemplateElement uid: string @@ -45,29 +45,6 @@ class ComponentVEvent extends HTMLElement { } } - redraw(data: VEvent) { - // update ourselves from template - - if (!this.template) { - throw "Something"; - } - - let body = (this.template.content.cloneNode(true) as DocumentFragment).firstElementChild!; - - for (let el of body.getElementsByClassName("bind")) { - if (!(el instanceof HTMLElement)) continue; - let p = el.dataset.property!; - let d, fmt; - if ((d = data.getProperty(p))) { - if ((fmt = el.dataset.fmt)) { - el.textContent = d.format(fmt); - } else { - el.textContent = d; - } - } - } - - this.replaceChildren(body); - } + abstract redraw(data: VEvent): void } -- cgit v1.2.3 From 3e8902476dd6436d2b792be9d8ddaf044646016e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 29 Nov 2021 21:18:25 +0100 Subject: Change UID resolve. --- static/components/vevent.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index 561051fa..a7fe3e08 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -17,9 +17,29 @@ abstract class ComponentVEvent extends HTMLElement { super(); this.template = document.getElementById(this.tagName) as HTMLTemplateElement; + let real_uid; - if (this.dataset.uid) uid = this.dataset.uid; - if (uid) real_uid = uid; + + console.log(this.tagName); + if (uid) { + console.log('Got UID directly'); + real_uid = uid; + } else { + /* I know that this case is redundant, it's here if we don't want to + look up the tree later */ + if (this.dataset.uid) { + console.log('Had UID as direct attribute'); + real_uid = this.dataset.uid; + } else { + let el = this.closest('[data-uid]') + if (el) { + console.log('Found UID higher up in the tree'); + real_uid = (el as HTMLElement).dataset.uid + } else { + throw "No parent with [data-uid] set" + } + } + } if (!real_uid) { console.warn(this.outerHTML); @@ -27,7 +47,7 @@ abstract class ComponentVEvent extends HTMLElement { } this.uid = real_uid; - this.dataset.uid = uid; + this.dataset.uid = real_uid; vcal_objects.get(this.uid)?.register(this); -- cgit v1.2.3 From e71f0c20adc4dc2f49bca99a859241fdadf376d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 30 Nov 2021 01:09:53 +0100 Subject: Rework tab system. This sepparates popup-elements from their tabbed contents, allowing clearer sepparations of concerns, along with easier adding and removing of tabs to the tabset! --- static/components/vevent.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index a7fe3e08..01391f9e 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -20,20 +20,20 @@ abstract class ComponentVEvent extends HTMLElement { let real_uid; - console.log(this.tagName); + // console.log(this.tagName); if (uid) { - console.log('Got UID directly'); + // console.log('Got UID directly'); real_uid = uid; } else { /* I know that this case is redundant, it's here if we don't want to look up the tree later */ if (this.dataset.uid) { - console.log('Had UID as direct attribute'); + // console.log('Had UID as direct attribute'); real_uid = this.dataset.uid; } else { let el = this.closest('[data-uid]') if (el) { - console.log('Found UID higher up in the tree'); + // console.log('Found UID higher up in the tree'); real_uid = (el as HTMLElement).dataset.uid } else { throw "No parent with [data-uid] set" @@ -46,6 +46,7 @@ abstract class ComponentVEvent extends HTMLElement { throw `UID required` } + // console.log(real_uid); this.uid = real_uid; this.dataset.uid = real_uid; -- cgit v1.2.3 From 3ddbd37ade2e03e4fc3a6f5ba52234bc286fded3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 13 Dec 2021 02:26:36 +0100 Subject: Made VEventComponent template optional. --- static/components/vevent.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index 01391f9e..b72cda90 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -10,13 +10,12 @@ Lacks an accompaning tag, and shouldn't be directly instanciated. */ abstract class ComponentVEvent extends HTMLElement { - template: HTMLTemplateElement + template: HTMLTemplateElement | null uid: string constructor(uid?: string) { super(); - this.template = document.getElementById(this.tagName) as HTMLTemplateElement; - + this.template = document.getElementById(this.tagName) as HTMLTemplateElement | null let real_uid; -- cgit v1.2.3