diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-09-13 00:01:28 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-09-13 00:01:28 +0200 |
commit | a82b6c772089aa46e30c6c89ef48f514294df3cb (patch) | |
tree | e25d9b6fd1fefe8b6ac293a5c0b53293872a8f54 /static/ts/components/changelog.ts | |
parent | Add basic documentation for lens. (diff) | |
parent | Even more documentation. (diff) | |
download | calp-a82b6c772089aa46e30c6c89ef48f514294df3cb.tar.gz calp-a82b6c772089aa46e30c6c89ef48f514294df3cb.tar.xz |
Merge branch 'next' into datarewrite-structures
Diffstat (limited to 'static/ts/components/changelog.ts')
-rw-r--r-- | static/ts/components/changelog.ts | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/static/ts/components/changelog.ts b/static/ts/components/changelog.ts new file mode 100644 index 00000000..8f8adc1c --- /dev/null +++ b/static/ts/components/changelog.ts @@ -0,0 +1,71 @@ +/** + `<changelog />` + + Display of a VEvents changelog. @ref{ChangeLogEntry} + + TODO rename this file! + + + @privateRemarks @anchor{VEventChangelog} + + @category Web Components + @mergeTarget components + @module +*/ +import { makeElement } from '../lib' +import { ComponentVEvent } from './vevent' +import { VEvent } from '../vevent' + +export { VEventChangelog } + +/** + Component displaying veevents changelog. + + This component is dumb, and (almost) doesn't keep any internal state. Instead + other parts of the program should call it with a `VEvent`, which contains the + actual changelog. +*/ +class VEventChangelog extends ComponentVEvent { + + /** The list holding the changelog */ + readonly #ul: HTMLElement + + constructor(uid?: string) { + super(uid); + + this.#ul = makeElement('ul'); + } + + connectedCallback() { + this.replaceChildren(this.#ul); + } + + redraw(data: VEvent) { + /* TODO only redraw what is needed */ + let children = [] + for (let [_, el] of data.changelog) { + let msg = ''; + switch (el.type) { + case 'property': + msg += `change ${el.name}: ` + msg += `from "${el.from}" to "${el.to}"` + break; + case 'calendar': + if (el.from === null && el.to === null) { + msg += '???' + } else if (el.from === null) { + msg += `set calendar to "${atob(el.to!)}"` + } else if (el.to === null) { + msg += `Remove calendar "${atob(el.from)}"` + } else { + msg += `Change calendar from "${atob(el.from)}" to "${atob(el.to)}"` + } + break; + } + + children.push(makeElement('li', { textContent: msg })); + } + + this.#ul.replaceChildren(...children) + } +} |