aboutsummaryrefslogtreecommitdiff
path: root/static/vevent.ts
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-12-02 01:51:28 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2021-12-02 01:51:28 +0100
commit6c537f3f60aaac8ae850f8ecaefc2a0d04a8431e (patch)
tree48babe2596284dc2fb58b026428496581bee9d4b /static/vevent.ts
parentRemove jcal-tests.js (diff)
downloadcalp-6c537f3f60aaac8ae850f8ecaefc2a0d04a8431e.tar.gz
calp-6c537f3f60aaac8ae850f8ecaefc2a0d04a8431e.tar.xz
Add basic changelog view
Diffstat (limited to 'static/vevent.ts')
-rw-r--r--static/vevent.ts48
1 files changed, 47 insertions, 1 deletions
diff --git a/static/vevent.ts b/static/vevent.ts
index 4b6d44c6..c7dcd406 100644
--- a/static/vevent.ts
+++ b/static/vevent.ts
@@ -1,4 +1,4 @@
-import { uid, ical_type, valid_input_types, JCal, JCalProperty } from './types'
+import { uid, ical_type, valid_input_types, JCal, JCalProperty, ChangeLogEntry } from './types'
import { parseDate } from './lib'
export {
@@ -103,6 +103,32 @@ class VEvent {
_calendar: string | null = null;
+ _changelog: ChangeLogEntry[] = []
+
+ addlog(entry: ChangeLogEntry) {
+ let len = this._changelog.length
+ let last = this._changelog[len - 1]
+
+ // console.log('entry = ', entry, ', last = ', last);
+
+ if (!last) {
+ // console.log('Adding new entry', entry, this.getProperty('uid'));
+ this._changelog.push(entry);
+ return;
+ }
+
+ if (entry.type === last.type
+ && entry.name === last.name
+ && entry.from === last.to) {
+ this._changelog.pop();
+ entry.from = last.from
+ // console.log('Changing old entry', entry, this.getProperty('uid'));
+ this._changelog.push(entry)
+ } else {
+ this._changelog.push(entry)
+ }
+ }
+
constructor(
properties: Map<string, VEventValue | VEventValue[]> = new Map(),
components: VEvent[] = []
@@ -159,6 +185,20 @@ class VEvent {
}
key = key.toUpperCase();
+
+ /*
+ To is mostly for the user. From is to allow an undo button
+ */
+ let entry: ChangeLogEntry = {
+ type: 'property',
+ name: key,
+ from: this.getProperty(key), // TODO what happens if getProperty returns a weird type
+ to: '' + value,
+ }
+ // console.log('Logging ', entry);
+ this.addlog(entry);
+
+
if (Array.isArray(value)) {
this.properties.set(key,
value.map(el => new VEventValue(resolve_type(key, type), el)))
@@ -201,6 +241,12 @@ class VEvent {
set calendar(calendar: string | null) {
+ this.addlog({
+ type: 'calendar',
+ name: '',
+ from: this._calendar,
+ to: calendar,
+ });
this._calendar = calendar;
for (let el of this.registered) {
el.redraw(this);