"Vue" implementation with interval

This commit is contained in:
Jörn-Michael Miehe 2022-09-24 01:37:26 +00:00
parent 004723499b
commit 738be6e667
4 changed files with 66 additions and 50 deletions

View file

@ -1,11 +1,7 @@
<template>
<v-app>
<v-layout column fill-height>
<TitleBar
:logo_above="logo_above"
:logo_below="logo_below"
:title="title_html"
/>
<TitleBar />
<Dashboard>
<template slot="message">
<div class="d-flex flex-column fill-height pb-sm-12">
@ -41,7 +37,7 @@
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Component, Vue } from "@/ovd-vue";
import { EventData } from "./components/calendar/EventModel";
import { CalendarData } from "./components/calendar/CalendarModel";
@ -65,13 +61,7 @@ import TickerBar from "./components/TickerBar.vue";
},
})
export default class App extends Vue {
private interval?: number;
// API data
private logo_above = "Technisches Hilfswerk";
private logo_below = "OV Musterstadt";
private title_html = "<h1>changeme</h1>";
private image_urls: string[] = require("@/assets/image_testdata.json");
private image_height = 300;
private image_contain = false;
@ -88,23 +78,15 @@ export default class App extends Vue {
private ticker_html = "<p>changeme</p>";
private ticker_color = "primary";
private update(): void {
// Update Logo Config
type LogoConfig = {
above: string;
below: string;
};
public created(): void {
super.created();
}
this.$ovdashboard.api_get_object<LogoConfig>("misc/config/logo", (cfg) => {
this.logo_above = cfg.above;
this.logo_below = cfg.below;
});
// Update Title
this.$ovdashboard.api_get_string("text/get/html/title", (title) => {
this.title_html = title;
});
public beforeDestroy(): void {
super.beforeDestroy();
}
protected update(): void {
// Update Images
this.$ovdashboard.api_get_list("image/list", (names) => {
this.image_urls = names.map((name: string) =>
@ -198,15 +180,6 @@ export default class App extends Vue {
this.ticker_color = data.color;
});
}
public created(): void {
this.update();
this.interval = setInterval(this.update, 30000);
}
public beforeDestroy(): void {
clearInterval(this.interval);
}
}
</script>

View file

@ -14,19 +14,37 @@
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { Component, Vue } from "@/ovd-vue";
@Component
export default class THWLogo extends Vue {
@Prop({ required: true })
private readonly above!: string;
@Prop({ required: true })
private readonly below!: string;
private above = "Technisches Hilfswerk";
private below = "OV Musterstadt";
private get logo_url(): string {
return this.$ovdashboard.api_url("file/get/logo");
}
public created(): void {
super.created();
}
public beforeDestroy(): void {
super.beforeDestroy();
}
protected update(): void {
// Update Logo Config
type LogoConfig = {
above: string;
below: string;
};
this.$ovdashboard.api_get_object<LogoConfig>("misc/config/logo", (cfg) => {
this.above = cfg.above;
this.below = cfg.below;
});
}
}
</script>

View file

@ -2,7 +2,7 @@
<v-toolbar color="primary" prominent dark>
<v-container class="d-flex pa-0" fluid fill-height>
<div class="d-flex justify-start text-left text-no-wrap">
<THWLogo :above="logo_above" :below="logo_below" />
<THWLogo />
</div>
<div
@ -27,7 +27,7 @@
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { Component, Vue } from "@/ovd-vue";
import Clock from "./Clock.vue";
import THWLogo from "./THWLogo.vue";
@ -38,14 +38,22 @@ import THWLogo from "./THWLogo.vue";
},
})
export default class TitleBar extends Vue {
@Prop({ default: "Technisches Hilfswerk" })
private readonly logo_above!: string;
private title = "<h1>TITLE</h1>";
@Prop({ default: "OV Musterstadt" })
private readonly logo_below!: string;
public created(): void {
super.created();
}
@Prop({ default: "TITLE" })
private readonly title!: string;
public beforeDestroy(): void {
super.beforeDestroy();
}
protected update(): void {
// Update Title
this.$ovdashboard.api_get_string("text/get/html/title", (title) => {
this.title = title;
});
}
}
</script>

17
ui/src/ovd-vue.ts Normal file
View file

@ -0,0 +1,17 @@
import { Vue as _Vue } from "vue-property-decorator";
export * from "vue-property-decorator";
export abstract class Vue extends _Vue {
private interval?: number;
protected abstract update(): void;
public created(): void {
this.update();
this.interval = setInterval(this.update, 30000);
}
public beforeDestroy(): void {
clearInterval(this.interval);
}
}