From 5b5b5acf7c19d2ec13b34de051c86951ea32ad11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 15 Sep 2022 00:07:27 +0000 Subject: [PATCH] add event hash and dividers between list items --- ui/src/components/calendar/Calendar.vue | 20 +++++++++++++++----- ui/src/components/calendar/event.ts | 13 +++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ui/src/components/calendar/Calendar.vue b/ui/src/components/calendar/Calendar.vue index cb8b221..f533ae1 100644 --- a/ui/src/components/calendar/Calendar.vue +++ b/ui/src/components/calendar/Calendar.vue @@ -1,6 +1,13 @@ @@ -15,7 +22,7 @@ import EventItem from "./EventItem.vue"; }, }) export default class Calendar extends Vue { - private readonly events_json = [ + private readonly events = [ { summary: "Lorem Ipsum", description: @@ -37,10 +44,10 @@ export default class Calendar extends Vue { }, ]; - private get events(): Array { + private get parsed_events(): Array { let arr = []; - for (let json of this.events_json) { + for (let json of this.events) { arr.push(new Event(json)); } @@ -49,5 +56,8 @@ export default class Calendar extends Vue { } - \ No newline at end of file diff --git a/ui/src/components/calendar/event.ts b/ui/src/components/calendar/event.ts index 39eca76..d26f37b 100644 --- a/ui/src/components/calendar/event.ts +++ b/ui/src/components/calendar/event.ts @@ -14,4 +14,17 @@ export default class Event { this.duration = end.diff(this.start); } + + public get hash(): string { + const str = JSON.stringify(this); + + // from https://gist.github.com/jlevy/c246006675becc446360a798e2b2d781 + let hash = 0; + for (let i = 0; i < str.length; i++) { + const char = str.charCodeAt(i); + hash = (hash << 5) - hash + char; + hash &= hash; // Convert to 32bit integer + } + return new Uint32Array([hash])[0].toString(36); + } } \ No newline at end of file