query admin/config_model in ConfigView

This commit is contained in:
Jörn-Michael Miehe 2023-09-11 22:24:01 +00:00
parent d5d99caeb2
commit 74b9322ae2
2 changed files with 132 additions and 77 deletions

View file

@ -19,71 +19,67 @@ async def check_admin(
return True return True
class PrivatePuzzle(BaseModel): class ConfigModel(BaseModel):
title: str class __Puzzle(BaseModel):
solution: str solution: str
shuffled: str shuffled: str
begin: date begin: date
end: date end: date
closing: date closing: date
seed: str 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): @router.get("/config_model")
config_file: str async def get_config_model(
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(
_: None = Depends(require_admin), _: None = Depends(require_admin),
cfg: Config = Depends(get_config), cfg: Config = Depends(get_config),
cal_cfg: CalendarConfig = Depends(get_calendar_config), cal_cfg: CalendarConfig = Depends(get_calendar_config),
shuffled_solution: str = Depends(shuffle_solution), shuffled_solution: str = Depends(shuffle_solution),
) -> PrivateConfig: ) -> ConfigModel:
return PrivateConfig( return ConfigModel.model_validate(
puzzle=PrivatePuzzle( {
title="Adventskalender 2023", "puzzle": {
solution=cfg.puzzle.solution, "solution": cfg.puzzle.solution,
shuffled=shuffled_solution, "shuffled": shuffled_solution,
begin=date.today(), "begin": date.today(),
end=date.today(), "end": date.today(),
closing=date.today(), "closing": date.today(),
seed=cfg.puzzle.random_seed, "seed": cfg.puzzle.random_seed,
), },
calendar=PrivateCalendar( "calendar": {
config_file=cfg.puzzle.calendar, "config_file": cfg.puzzle.calendar,
background=cal_cfg.background, "background": cal_cfg.background,
doors=[door.day for door in cal_cfg.doors], "doors": [door.day for door in cal_cfg.doors],
), },
image=PrivateImage( "image": {
size=500, "size": 500,
border=30, "border": 30,
fonts=[(cfg.server.font, 50)], "fonts": [(cfg.server.font, 50)],
), },
webdav=PrivateWebDAV( "webdav": {
url=SETTINGS.webdav.url, "url": SETTINGS.webdav.url,
cache_ttl=SETTINGS.webdav.cache_ttl, "cache_ttl": SETTINGS.webdav.cache_ttl,
config_file=SETTINGS.webdav.config_filename, "config_file": SETTINGS.webdav.config_filename,
), },
}
) )

View file

@ -10,10 +10,10 @@
<dd>Adventskalender 2023</dd> <dd>Adventskalender 2023</dd>
<dt>Lösung</dt> <dt>Lösung</dt>
<dd>ABCDEFGHIJKLMNOPQRSTUVWX</dd> <dd>{{ admin_config_model.puzzle.solution }}</dd>
<dt>Reihenfolge</dt> <dt>Reihenfolge</dt>
<dd>AGFCINBEWLKQMXDURPOSJVHT</dd> <dd>{{ admin_config_model.puzzle.shuffled }}</dd>
<dt>Offene Türchen</dt> <dt>Offene Türchen</dt>
<dd>10</dd> <dd>10</dd>
@ -22,16 +22,16 @@
<dd>dd-hh-mm-ss</dd> <dd>dd-hh-mm-ss</dd>
<dt>Erstes Türchen</dt> <dt>Erstes Türchen</dt>
<dd>01.12.2023</dd> <dd>{{ admin_config_model.puzzle.begin }}</dd>
<dt>Letztes Türchen</dt> <dt>Letztes Türchen</dt>
<dd>24.12.2023</dd> <dd>{{ admin_config_model.puzzle.end }}</dd>
<dt>Rätsel schließt</dt> <dt>Rätsel schließt</dt>
<dd>01.04.2024</dd> <dd>{{ admin_config_model.puzzle.closing }}</dd>
<dt>Zufalls-Seed</dt> <dt>Zufalls-Seed</dt>
<dd>""</dd> <dd>{{ admin_config_model.puzzle.seed }}</dd>
</dl> </dl>
</div> </div>
</div> </div>
@ -40,14 +40,14 @@
<h4>Kalender</h4> <h4>Kalender</h4>
<dl> <dl>
<dt>Definition</dt> <dt>Definition</dt>
<dd>files/default.toml</dd> <dd>{{ admin_config_model.calendar.config_file }}</dd>
<dt>Hintergrundbild</dt> <dt>Hintergrundbild</dt>
<dd>files/adventskalender.jpg</dd> <dd>{{ admin_config_model.calendar.background }}</dd>
<dt>Türchen</dt> <dt>Türchen</dt>
<dd> <dd>
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 {{ admin_config_model.calendar.doors }}
<span class="tag is-danger ml-2"> <span class="tag is-danger ml-2">
<span class="icon"> <span class="icon">
<font-awesome-icon icon="fa-solid fa-bolt" /> <font-awesome-icon icon="fa-solid fa-bolt" />
@ -59,13 +59,13 @@
<h4>Bilder</h4> <h4>Bilder</h4>
<dl> <dl>
<dt>Größe</dt> <dt>Größe</dt>
<dd>500 px</dd> <dd>{{ admin_config_model.image.size }} px</dd>
<dt>Rand</dt> <dt>Rand</dt>
<dd>30 px</dd> <dd>{{ admin_config_model.image.border }} px</dd>
<dt>Schriftarten</dt> <dt>Schriftarten</dt>
<dd>files/Lena.ttf (Größe 50)</dd> <dd>{{ admin_config_model.image.fonts }}</dd>
<dd>files/foobar.ttf (Größe 33)</dd> <dd>files/foobar.ttf (Größe 33)</dd>
</dl> </dl>
</div> </div>
@ -75,7 +75,7 @@
<h4>WebDAV</h4> <h4>WebDAV</h4>
<dl> <dl>
<dt>URL</dt> <dt>URL</dt>
<dd>https://example.com/remote.php/webdav/advent22</dd> <dd>{{ admin_config_model.webdav.url }}</dd>
<dt>Zugangsdaten</dt> <dt>Zugangsdaten</dt>
<dd> <dd>
@ -88,10 +88,10 @@
</dd> </dd>
<dt>Cache-Dauer</dt> <dt>Cache-Dauer</dt>
<dd>30 s</dd> <dd>{{ admin_config_model.webdav.cache_ttl }} s</dd>
<dt>Konfigurationsdatei</dt> <dt>Konfigurationsdatei</dt>
<dd>config.toml</dd> <dd>{{ admin_config_model.webdav.config_file }}</dd>
<dt>UI-Admin</dt> <dt>UI-Admin</dt>
<dd> <dd>
@ -115,12 +115,71 @@ import { Options, Vue } from "vue-class-component";
import BulmaDrawer from "./bulma/Drawer.vue"; 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({ @Options({
components: { components: {
BulmaDrawer, 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<ConfigModel>("admin/config_model")
.then((data) => (this.admin_config_model = data))
.catch(console.log);
}
}
</script> </script>
<style scoped> <style scoped>