ovdashboard/ui/src/components/calendar/EventItem.vue

76 lines
1.9 KiB
Vue
Raw Normal View History

2022-09-14 23:04:26 +00:00
<template>
<v-list-item class="pa-0" three-line>
2022-09-14 23:14:44 +00:00
<EventDate :date="event.start" />
2022-09-14 23:04:26 +00:00
<v-list-item-content>
<v-list-item-title class="text-h6 text-md-h5 mt-0 mb-1">
{{ event.summary }}
</v-list-item-title>
<v-list-item-subtitle
v-if="event.description"
class="text-subtitle-2 text-md-subtitle-1 mt-0 mb-2"
>
{{ event.description }}
</v-list-item-subtitle>
<v-list-item-subtitle
2022-09-14 23:55:13 +00:00
class="
2022-09-15 01:13:12 +00:00
d-inline-block
text-truncate
2022-09-14 23:55:13 +00:00
thw-heading-font
blue-grey--text
text--darken-1
font-weight-bold
ma-0
"
2022-09-14 23:04:26 +00:00
>
{{ data_string }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
2022-09-15 11:54:05 +00:00
import { DateTime, DurationLikeObject } from "luxon";
2022-09-14 23:04:26 +00:00
import Event from "./event";
2022-09-14 23:14:44 +00:00
import EventDate from "./EventDate.vue";
2022-09-14 23:04:26 +00:00
2022-09-14 23:14:44 +00:00
@Component({
components: {
EventDate,
},
})
2022-09-14 23:04:26 +00:00
export default class EventItem extends Vue {
@Prop()
private readonly event!: Event;
private get data_string(): string {
2022-09-15 00:40:49 +00:00
const locale_string = this.event.start.toLocaleString(
DateTime.DATETIME_MED_WITH_WEEKDAY
);
2022-09-14 23:04:26 +00:00
2022-09-15 11:54:05 +00:00
// decide which duration units to include
let units: Array<keyof DurationLikeObject> = ["hours"];
if (this.event.duration.as("days") >= 1) {
// include days if duration is at least one day
units.push("days");
}
if (!Number.isInteger(this.event.duration.as("hours"))) {
// include minutes if duration in hours is not a whole number
units.push("minutes");
}
const duration_string = this.event.duration
// "..." is the spread operator
.shiftTo(...units)
.mapUnits((x) => Math.round(x))
.toHuman();
2022-09-14 23:04:26 +00:00
return locale_string + " (" + duration_string + ")";
}
}
</script>
<style>
</style>