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

134 lines
2.9 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-24 16:39:03 +00:00
import { Component, Ref, Vue } from "@/ovd-vue";
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-24 16:39:03 +00:00
import { EventData } from "./EventModel";
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-24 16:39:03 +00:00
private data: CalendarData[] = require("@/assets/calendar_testdata.json");
private speed = 10000;
2022-09-15 16:25:58 +00:00
2022-09-15 15:04:01 +00:00
@Ref("main")
private readonly _main?: Vue;
2022-09-24 16:39:03 +00:00
public created(): void {
super.created();
}
public beforeDestroy(): void {
super.beforeDestroy();
clearInterval(this.interval);
}
protected update(): void {
// Update Calendar Aggregates
this.$ovdashboard.api_get_list("aggregate/list", (names) => {
this.$ovdashboard.api_get_object_multi<EventData[]>(
names.map((name) => `aggregate/get/${name}`),
(calendars) => {
this.data = [];
for (let i = 0; i < names.length; i++) {
this.data.push({
title: names[i],
events: calendars[i],
});
}
}
);
});
// Update Calendar Config
type CalendarConfig = {
speed: number;
};
this.$ovdashboard.api_get_object<CalendarConfig>(
"calendar/config",
(data) => {
this.speed = data.speed;
}
);
}
2022-09-15 15:04:01 +00:00
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;
2022-09-19 09:17:53 +00:00
divElement.style.setProperty("max-height", `${maxHeight}px`);
2022-09-15 15:04:01 +00:00
}
public mounted(): void {
this.update_height();
this.interval = setInterval(this.update_height, 10000);
}
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>