From 74b9322ae24171952d5c0c4ae42415c9de6470c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 11 Sep 2023 22:24:01 +0000 Subject: [PATCH] query admin/config_model in ConfigView --- api/advent22_api/routers/admin.py | 118 +++++++++++++++--------------- ui/src/components/ConfigView.vue | 91 +++++++++++++++++++---- 2 files changed, 132 insertions(+), 77 deletions(-) diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index cda823b..8636e4f 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -19,71 +19,67 @@ async def check_admin( return True -class PrivatePuzzle(BaseModel): - title: str - solution: str - shuffled: str - begin: date - end: date - closing: date - seed: str +class ConfigModel(BaseModel): + class __Puzzle(BaseModel): + solution: str + shuffled: str + begin: date + end: date + closing: date + seed: str + + class __Calendar(BaseModel): + config_file: str + background: str + doors: list[int] + + class __Image(BaseModel): + size: int + border: int + fonts: list[tuple[str, int]] + + class __WebDAV(BaseModel): + url: str + cache_ttl: int + config_file: str + + puzzle: __Puzzle + calendar: __Calendar + image: __Image + webdav: __WebDAV -class PrivateCalendar(BaseModel): - config_file: str - background: str - doors: list[int] - - -class PrivateImage(BaseModel): - size: int - border: int - fonts: list[tuple[str, int]] - - -class PrivateWebDAV(BaseModel): - url: str - cache_ttl: int - config_file: str - - -class PrivateConfig(BaseModel): - puzzle: PrivatePuzzle - calendar: PrivateCalendar - image: PrivateImage - webdav: PrivateWebDAV - - -@router.get("/private_config") -async def get_private_config( +@router.get("/config_model") +async def get_config_model( _: None = Depends(require_admin), cfg: Config = Depends(get_config), cal_cfg: CalendarConfig = Depends(get_calendar_config), shuffled_solution: str = Depends(shuffle_solution), -) -> PrivateConfig: - return PrivateConfig( - puzzle=PrivatePuzzle( - title="Adventskalender 2023", - solution=cfg.puzzle.solution, - shuffled=shuffled_solution, - begin=date.today(), - end=date.today(), - closing=date.today(), - seed=cfg.puzzle.random_seed, - ), - calendar=PrivateCalendar( - config_file=cfg.puzzle.calendar, - background=cal_cfg.background, - doors=[door.day for door in cal_cfg.doors], - ), - image=PrivateImage( - size=500, - border=30, - fonts=[(cfg.server.font, 50)], - ), - webdav=PrivateWebDAV( - url=SETTINGS.webdav.url, - cache_ttl=SETTINGS.webdav.cache_ttl, - config_file=SETTINGS.webdav.config_filename, - ), +) -> ConfigModel: + return ConfigModel.model_validate( + { + "puzzle": { + "solution": cfg.puzzle.solution, + "shuffled": shuffled_solution, + "begin": date.today(), + "end": date.today(), + "closing": date.today(), + "seed": cfg.puzzle.random_seed, + }, + "calendar": { + "config_file": cfg.puzzle.calendar, + "background": cal_cfg.background, + "doors": [door.day for door in cal_cfg.doors], + }, + "image": { + "size": 500, + "border": 30, + "fonts": [(cfg.server.font, 50)], + }, + "webdav": { + "url": SETTINGS.webdav.url, + "cache_ttl": SETTINGS.webdav.cache_ttl, + "config_file": SETTINGS.webdav.config_filename, + }, + } ) diff --git a/ui/src/components/ConfigView.vue b/ui/src/components/ConfigView.vue index e228774..99db282 100644 --- a/ui/src/components/ConfigView.vue +++ b/ui/src/components/ConfigView.vue @@ -10,10 +10,10 @@
Adventskalender 2023
Lösung
-
ABCDEFGHIJKLMNOPQRSTUVWX
+
{{ admin_config_model.puzzle.solution }}
Reihenfolge
-
AGFCINBEWLKQMXDURPOSJVHT
+
{{ admin_config_model.puzzle.shuffled }}
Offene Türchen
10
@@ -22,16 +22,16 @@
dd-hh-mm-ss
Erstes Türchen
-
01.12.2023
+
{{ admin_config_model.puzzle.begin }}
Letztes Türchen
-
24.12.2023
+
{{ admin_config_model.puzzle.end }}
Rätsel schließt
-
01.04.2024
+
{{ admin_config_model.puzzle.closing }}
Zufalls-Seed
-
""
+
{{ admin_config_model.puzzle.seed }}
@@ -40,14 +40,14 @@

Kalender

Definition
-
files/default.toml
+
{{ admin_config_model.calendar.config_file }}
Hintergrundbild
-
files/adventskalender.jpg
+
{{ admin_config_model.calendar.background }}
Türchen
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 + {{ admin_config_model.calendar.doors }} @@ -59,13 +59,13 @@

Bilder

Größe
-
500 px
+
{{ admin_config_model.image.size }} px
Rand
-
30 px
+
{{ admin_config_model.image.border }} px
Schriftarten
-
files/Lena.ttf (Größe 50)
+
{{ admin_config_model.image.fonts }}
files/foobar.ttf (Größe 33)
@@ -75,7 +75,7 @@

WebDAV

URL
-
https://example.com/remote.php/webdav/advent22
+
{{ admin_config_model.webdav.url }}
Zugangsdaten
@@ -88,10 +88,10 @@
Cache-Dauer
-
30 s
+
{{ admin_config_model.webdav.cache_ttl }} s
Konfigurationsdatei
-
config.toml
+
{{ admin_config_model.webdav.config_file }}
UI-Admin
@@ -115,12 +115,71 @@ import { Options, Vue } from "vue-class-component"; import BulmaDrawer from "./bulma/Drawer.vue"; +interface ConfigModel { + puzzle: { + solution: string; + shuffled: string; + begin: string; + end: string; + closing: string; + seed: string; + }; + calendar: { + config_file: string; + background: string; + doors: number[]; + }; + image: { + size: number; + border: number; + fonts: (string | number)[]; + }; + webdav: { + url: string; + cache_ttl: number; + config_file: string; + }; +} + @Options({ components: { BulmaDrawer, }, }) -export default class extends Vue {} +export default class extends Vue { + public admin_config_model: ConfigModel = { + puzzle: { + solution: "ABCDEFGHIJKLMNOPQRSTUVWX", + shuffled: "AGFCINBEWLKQMXDURPOSJVHT", + begin: "01.12.2023", + end: "24.12.2023", + closing: "01.04.2024", + seed: "", + }, + calendar: { + config_file: "default.toml", + background: "adventskalender.jpg", + doors: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + }, + image: { + size: 500, + border: 30, + fonts: ["files/Lena.ttf", 50], + }, + webdav: { + url: "https://example.com/remote.php/webdav/advent22", + cache_ttl: 30, + config_file: "config.toml", + }, + }; + + public mounted(): void { + this.$advent22 + .api_get("admin/config_model") + .then((data) => (this.admin_config_model = data)) + .catch(console.log); + } +}