aboutsummaryrefslogtreecommitdiff
path: root/static/ts/components/changelog.ts
blob: 8f8adc1c53f85402747949d9349d275b25e3d6f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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)
    }
}