refactor: event -> model, Hashable objects

This commit is contained in:
Jörn-Michael Miehe 2022-09-15 13:11:50 +00:00
parent 5cfebd4c6f
commit 6217ae2ecb
4 changed files with 40 additions and 38 deletions

View file

@ -14,7 +14,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator"; import { Component, Prop, Vue } from "vue-property-decorator";
import Event from "./event"; import { EventData } from "./model";
import EventItem from "./EventItem.vue"; import EventItem from "./EventItem.vue";
@Component({ @Component({
@ -27,7 +27,7 @@ export default class Calendar extends Vue {
private readonly title!: string; private readonly title!: string;
@Prop({ default: () => [] }) @Prop({ default: () => [] })
private readonly events!: Array<Event>; private readonly events!: Array<EventData>;
} }
</script> </script>

View file

@ -7,12 +7,8 @@
touchless touchless
hide-delimiters hide-delimiters
> >
<v-carousel-item v-for="calendar in calendars" :key="calendar.title"> <v-carousel-item v-for="calendar in calendars" :key="calendar.hash">
<Calendar <Calendar :title="calendar.title" :events="calendar.events" />
:key="calendar.title + '-cal'"
:title="calendar.title"
:events="calendar.events"
/>
</v-carousel-item> </v-carousel-item>
</v-carousel> </v-carousel>
</template> </template>
@ -20,7 +16,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue } from "vue-property-decorator"; import { Component, Vue } from "vue-property-decorator";
import Calendar from "./Calendar.vue"; import Calendar from "./Calendar.vue";
import { CalendarData, CalendarJSONData } from "./event"; import { CalendarData, CalendarJSONData } from "./model";
@Component({ @Component({
components: { components: {

View file

@ -31,7 +31,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator"; import { Component, Prop, Vue } from "vue-property-decorator";
import { DateTime, DurationLikeObject } from "luxon"; import { DateTime, DurationLikeObject } from "luxon";
import Event from "./event"; import { EventData } from "./model";
import EventDate from "./EventDate.vue"; import EventDate from "./EventDate.vue";
@Component({ @Component({
@ -41,7 +41,7 @@ import EventDate from "./EventDate.vue";
}) })
export default class EventItem extends Vue { export default class EventItem extends Vue {
@Prop() @Prop()
private readonly event!: Event; private readonly event!: EventData;
private get data_string(): string { private get data_string(): string {
const locale_string = this.event.start.toLocaleString( const locale_string = this.event.start.toLocaleString(

View file

@ -1,31 +1,6 @@
import { DateTime, Duration } from "luxon"; import { DateTime, Duration } from "luxon";
export type EventJSONData = { class Hashable {
summary: string;
description: string;
dtstart: string;
dtend: string;
};
export default class EventData {
public summary: string;
public description: string;
public start: DateTime;
public duration: Duration;
public constructor(json_data: EventJSONData) {
this.summary = json_data.summary;
this.description = json_data.description;
this.start = DateTime
.fromISO(json_data.dtstart)
.setLocale(navigator.language);
const end = DateTime
.fromISO(json_data.dtend)
.setLocale(navigator.language);
this.duration = end.diff(this.start);
}
public get hash(): string { public get hash(): string {
const str = JSON.stringify(this); const str = JSON.stringify(this);
@ -38,16 +13,47 @@ export default class EventData {
} }
} }
export type EventJSONData = {
summary: string;
description: string;
dtstart: string;
dtend: string;
};
export class EventData extends Hashable {
public summary: string;
public description: string;
public start: DateTime;
public duration: Duration;
public constructor(json_data: EventJSONData) {
super();
this.summary = json_data.summary;
this.description = json_data.description;
this.start = DateTime
.fromISO(json_data.dtstart)
.setLocale(navigator.language);
const end = DateTime
.fromISO(json_data.dtend)
.setLocale(navigator.language);
this.duration = end.diff(this.start);
}
}
export type CalendarJSONData = { export type CalendarJSONData = {
title: string; title: string;
events: Array<EventJSONData>; events: Array<EventJSONData>;
}; };
export class CalendarData { export class CalendarData extends Hashable {
public title: string; public title: string;
public events: Array<EventData>; public events: Array<EventData>;
public constructor(json_data: CalendarJSONData) { public constructor(json_data: CalendarJSONData) {
super();
this.title = json_data.title this.title = json_data.title
this.events = []; this.events = [];