advent22/ui/src/components/admin/ConfigView.vue

232 lines
6.6 KiB
Vue
Raw Normal View History

2023-09-10 03:10:22 +00:00
<template>
2023-09-14 12:51:30 +00:00
<BulmaDrawer header="Konfiguration" @open="on_open" refreshable>
2023-09-10 03:25:12 +00:00
<div class="card-content">
2023-09-10 03:38:24 +00:00
<div class="columns">
<div class="column is-one-third">
<div class="content">
2023-09-21 08:52:35 +00:00
<h3>Rätsel</h3>
<dl>
<dt>Titel</dt>
<!-- TODO -->
<dd>Advent22</dd>
<dt>Lösung</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.puzzle.solution }}</dd>
2023-09-10 03:10:22 +00:00
<dt>Offene Türchen</dt>
2023-09-12 21:06:52 +00:00
<dd>{{ num_user_doors }}</dd>
2023-09-10 03:10:22 +00:00
2023-09-15 16:55:03 +00:00
<dt>Zeit zum nächsten Türchen</dt>
2023-09-15 17:01:38 +00:00
<dd v-if="next_door === null">Kein nächstes Türchen</dd>
<dd v-else><CountDown :millis="next_door" /></dd>
2023-09-10 03:10:22 +00:00
<dt>Erstes Türchen</dt>
2023-09-16 00:17:13 +00:00
<dd>{{ fmt_puzzle_date("first") }}</dd>
2023-09-10 03:10:22 +00:00
2023-09-15 17:06:28 +00:00
<dt>Nächstes Türchen</dt>
2023-09-16 00:17:13 +00:00
<dd>{{ fmt_puzzle_date("next") }}</dd>
2023-09-15 17:06:28 +00:00
<dt>Letztes Türchen</dt>
2023-09-16 00:17:13 +00:00
<dd>{{ fmt_puzzle_date("last") }}</dd>
2023-09-10 03:10:22 +00:00
<dt>Rätsel schließt nach</dt>
2023-09-16 00:17:13 +00:00
<dd>{{ fmt_puzzle_date("end") }}</dd>
2023-09-10 03:10:22 +00:00
<dt>Zufalls-Seed</dt>
2023-09-11 22:50:11 +00:00
<dd class="is-family-monospace">
2023-09-12 16:26:12 +00:00
"{{ config_model.puzzle.seed }}"
2023-09-11 22:50:11 +00:00
</dd>
</dl>
</div>
2023-09-10 03:10:22 +00:00
</div>
<div class="column is-one-third">
<div class="content">
2023-09-21 08:52:35 +00:00
<h3>Kalender</h3>
<dl>
<dt>Definition</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.calendar.config_file }}</dd>
<dt>Hintergrundbild</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.calendar.background }}</dd>
<dt>Türchen</dt>
2023-09-11 02:36:51 +00:00
<dd>
2023-09-21 00:45:57 +00:00
<template v-for="(part, day) in day_parts" :key="`door-${day}`">
2023-09-12 13:56:05 +00:00
<span>
2023-09-21 00:45:57 +00:00
<template v-if="Number(day) > 1">, </template>
<span v-if="part == ''" class="tag is-warning">_</span>
<template v-else>{{ part }}</template>
2023-09-11 02:36:51 +00:00
</span>
2023-09-12 13:56:05 +00:00
</template>
2023-09-11 02:36:51 +00:00
</dd>
</dl>
2023-09-21 08:52:35 +00:00
<h3>Bilder</h3>
<dl>
<dt>Größe</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.image.size }} px</dd>
<dt>Rand</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.image.border }} px</dd>
<dt>Schriftarten</dt>
2023-09-11 22:50:11 +00:00
<dd
2023-09-12 16:26:12 +00:00
v-for="(font, index) in config_model.image.fonts"
2023-09-12 14:55:08 +00:00
:key="`font-${index}`"
2023-09-11 22:50:11 +00:00
>
{{ font.file }} (Größe {{ font.size }})
</dd>
</dl>
</div>
2023-09-10 03:10:22 +00:00
</div>
<div class="column is-one-third">
<div class="content">
2023-09-21 08:52:35 +00:00
<h3>WebDAV</h3>
<dl>
<dt>URL</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.webdav.url }}</dd>
<dt>Zugangsdaten</dt>
<dd class="is-family-monospace">
<BulmaSecret @load="load_dav_credentials">
<span class="tag is-danger">user</span>
{{ dav_credentials.username }}
<br />
<span class="tag is-danger">pass</span>
{{ dav_credentials.password }}
</BulmaSecret>
2023-09-11 02:36:51 +00:00
</dd>
<dt>Cache-Dauer</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.webdav.cache_ttl }} s</dd>
<dt>Konfigurationsdatei</dt>
2023-09-12 16:26:12 +00:00
<dd>{{ config_model.webdav.config_file }}</dd>
<dt>UI-Admin</dt>
<dd class="is-family-monospace">
<BulmaSecret @load="load_ui_credentials">
<span class="tag is-danger">user</span>
{{ ui_credentials.username }}
<br />
<span class="tag is-danger">pass</span>
{{ ui_credentials.password }}
</BulmaSecret>
2023-09-11 02:36:51 +00:00
</dd>
</dl>
</div>
2023-09-10 03:10:22 +00:00
</div>
</div>
</div>
2023-09-10 03:38:24 +00:00
</BulmaDrawer>
2023-09-10 03:10:22 +00:00
</template>
<script lang="ts">
2023-09-21 09:53:30 +00:00
import { ConfigModel, DoorsSaved, NumStrDict } from "@/lib/api";
2023-09-16 00:17:13 +00:00
import { DateTime } from "luxon";
2023-09-10 03:10:22 +00:00
import { Options, Vue } from "vue-class-component";
2023-09-14 12:51:30 +00:00
import BulmaDrawer from "../bulma/Drawer.vue";
2023-09-13 16:08:05 +00:00
import BulmaSecret from "../bulma/Secret.vue";
2023-09-15 16:55:03 +00:00
import CountDown from "../CountDown.vue";
interface Credentials {
username: string;
password: string;
}
2023-09-10 03:10:22 +00:00
@Options({
components: {
BulmaDrawer,
BulmaSecret,
2023-09-15 16:55:03 +00:00
CountDown,
2023-09-10 03:10:22 +00:00
},
})
2023-09-11 22:24:01 +00:00
export default class extends Vue {
2023-09-12 16:26:12 +00:00
public config_model: ConfigModel = {
2023-09-11 22:24:01 +00:00
puzzle: {
2023-09-16 00:17:13 +00:00
solution: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
first: "2023-12-01",
next: "2023-12-01",
last: "2023-12-24",
end: "2024-04-01",
2023-09-11 22:24:01 +00:00
seed: "",
},
calendar: {
2023-09-16 00:17:13 +00:00
config_file: "lorem ipsum",
background: "dolor sit amet",
2023-09-11 22:24:01 +00:00
},
image: {
size: 500,
2023-09-16 00:17:13 +00:00
border: 0,
fonts: [{ file: "consetetur", size: 0 }],
2023-09-11 22:24:01 +00:00
},
webdav: {
2023-09-16 00:17:13 +00:00
url: "sadipscing elitr",
cache_ttl: 0,
config_file: "sed diam nonumy",
2023-09-11 22:24:01 +00:00
},
};
2023-09-21 09:53:30 +00:00
public day_parts: NumStrDict = {};
2023-09-12 21:06:52 +00:00
public num_user_doors = 0;
2023-09-15 16:55:03 +00:00
public next_door: number | null = null;
public dav_credentials: Credentials = { username: "", password: "" };
public ui_credentials: Credentials = { username: "", password: "" };
2023-09-11 22:24:01 +00:00
2023-09-16 00:17:13 +00:00
public fmt_puzzle_date(name: keyof ConfigModel["puzzle"]): string {
const iso_date = this.config_model.puzzle[name];
if (iso_date === null) return "-";
return DateTime.fromISO(iso_date).toLocaleString(DateTime.DATE_SHORT);
}
2023-09-14 12:51:30 +00:00
public on_open(ready: () => void, fail: () => void): void {
2023-09-12 16:26:12 +00:00
Promise.all([
this.$advent22.api_get<ConfigModel>("admin/config_model"),
2023-09-21 09:53:30 +00:00
this.$advent22.api_get<NumStrDict>("admin/day_parts"),
2023-09-12 21:06:52 +00:00
this.$advent22.api_get<DoorsSaved>("user/doors"),
2023-09-15 16:55:03 +00:00
this.$advent22.api_get<number | null>("user/next_door"),
2023-09-12 16:26:12 +00:00
])
2023-09-15 16:55:03 +00:00
.then(([config_model, day_parts, user_doors, next_door]) => {
2023-09-12 16:26:12 +00:00
this.config_model = config_model;
this.day_parts = day_parts;
2023-09-12 21:06:52 +00:00
this.num_user_doors = user_doors.length;
2023-09-15 16:55:03 +00:00
this.next_door = next_door;
2023-09-12 21:06:52 +00:00
2023-09-14 12:51:30 +00:00
ready();
2023-09-12 15:10:54 +00:00
})
2023-09-14 12:51:30 +00:00
.catch(fail);
2023-09-11 22:24:01 +00:00
}
public load_dav_credentials(): void {
this.$advent22
.api_get<string[]>("admin/dav_credentials")
.then(([username, password]) => {
this.dav_credentials = {
username: username,
password: password,
};
})
2023-09-13 15:58:15 +00:00
.catch(() => {});
}
public load_ui_credentials(): void {
this.$advent22
.api_get<string[]>("admin/ui_credentials")
.then(([username, password]) => {
this.ui_credentials = {
username: username,
password: password,
};
})
2023-09-13 15:58:15 +00:00
.catch(() => {});
}
2023-09-11 22:24:01 +00:00
}
2023-09-10 03:10:22 +00:00
</script>
2023-09-10 20:08:13 +00:00
<style scoped>
dd {
overflow-x: auto;
}
</style>