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

100 lines
2.2 KiB
Vue
Raw Normal View History

2022-09-15 13:03:19 +00:00
<template>
<v-carousel
2022-09-15 15:04:01 +00:00
ref="main"
2022-09-15 13:03:19 +00:00
cycle
2022-09-15 13:20:41 +00:00
:interval="speed"
2022-09-15 13:03:19 +00:00
height="auto"
:show-arrows="false"
touchless
hide-delimiters
>
<v-carousel-item v-for="calendar in calendars" :key="calendar.hash">
<Calendar :title="calendar.title" :events="calendar.events" />
2022-09-15 13:03:19 +00:00
</v-carousel-item>
</v-carousel>
</template>
<script lang="ts">
2022-09-15 15:04:01 +00:00
import { Component, Prop, Ref, Vue } from "vue-property-decorator";
2022-09-15 13:03:19 +00:00
import Calendar from "./Calendar.vue";
2022-09-15 13:28:49 +00:00
import { CalendarData, CalendarModel } from "./CalendarModel";
2022-09-15 13:03:19 +00:00
@Component({
components: {
Calendar,
},
})
export default class CalendarCarousel extends Vue {
2022-09-15 15:04:01 +00:00
private interval?: number;
2022-09-15 13:20:41 +00:00
@Prop({ default: 10000 })
private readonly speed!: number;
2022-09-15 16:25:58 +00:00
@Prop({ required: true })
2022-09-15 19:08:15 +00:00
private readonly data!: CalendarData[];
2022-09-15 16:25:58 +00:00
2022-09-15 15:04:01 +00:00
@Ref("main")
private readonly _main?: Vue;
private update_height(): void {
const diff = 150;
if (this._main === undefined) return;
const parentElement = this._main.$el.parentElement;
if (parentElement === null) return;
const divElement = this._main.$el.querySelector("div");
if (divElement === null) return;
const divHeightPX = window
.getComputedStyle(parentElement)
.getPropertyValue("height");
const maxHeight = parseFloat(divHeightPX) - diff;
divElement.style.setProperty("max-height", maxHeight + "px");
}
public mounted(): void {
this.update_height();
this.interval = setInterval(this.update_height, 10000);
}
public beforeDestroy(): void {
clearInterval(this.interval);
}
2022-09-15 19:08:15 +00:00
private get calendars(): CalendarModel[] {
2022-09-15 13:03:19 +00:00
let arr = [];
for (const json_data of this.data) {
2022-09-15 13:28:49 +00:00
arr.push(new CalendarModel(json_data));
2022-09-15 13:03:19 +00:00
}
return arr;
}
}
</script>
2022-09-15 15:04:01 +00:00
<style lang="scss" scoped>
2022-09-15 20:30:25 +00:00
@import "~vuetify/src/styles/settings/_variables";
2022-09-15 15:04:01 +00:00
.v-carousel:deep() > div {
max-height: 500px;
2022-09-15 20:30:25 +00:00
@media #{map-get($display-breakpoints, "sm-and-down")} {
min-height: 500px;
}
2022-09-15 15:04:01 +00:00
}
2022-09-15 17:49:06 +00:00
.v-window {
&-x-transition,
&-x-reverse-transition,
&-y-transition,
&-y-reverse-transition {
&-enter-active,
&-leave-active {
transition: 1.5s cubic-bezier(0.25, 0.8, 0.5, 1) !important;
}
}
}
2022-09-15 15:04:01 +00:00
</style>