splice DayPartModel from ConfigModel

This commit is contained in:
Jörn-Michael Miehe 2023-09-12 16:26:12 +00:00
parent 334540187e
commit 4e1a9fa10d
3 changed files with 51 additions and 37 deletions

View file

@ -21,7 +21,7 @@ async def get_days(
return sorted(set(door.day for door in cal_cfg.doors)) return sorted(set(door.day for door in cal_cfg.doors))
async def get_day_parts( async def get_parts(
cfg: Config = Depends(get_config), cfg: Config = Depends(get_config),
days: list[int] = Depends(get_days), days: list[int] = Depends(get_days),
) -> dict[int, str]: ) -> dict[int, str]:
@ -48,7 +48,7 @@ async def get_day_parts(
async def get_day_part( async def get_day_part(
day: int, day: int,
parts: dict[int, str] = Depends(get_day_parts), parts: dict[int, str] = Depends(get_parts),
) -> str: ) -> str:
""" """
Heute angezeigter Teil der Lösung Heute angezeigter Teil der Lösung

View file

@ -5,7 +5,7 @@ from pydantic import BaseModel
from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config
from ..core.config import Config, get_config from ..core.config import Config, get_config
from ..core.depends import get_day_parts from ..core.depends import get_parts
from ..core.settings import SETTINGS from ..core.settings import SETTINGS
from ._security import require_admin, user_is_admin from ._security import require_admin, user_is_admin
@ -21,12 +21,7 @@ async def is_admin(
class ConfigModel(BaseModel): class ConfigModel(BaseModel):
class __Puzzle(BaseModel): class __Puzzle(BaseModel):
class __Part(BaseModel):
day: int
part: str
solution: str solution: str
day_parts: list[__Part]
begin: date begin: date
end: date end: date
closing: date closing: date
@ -61,16 +56,12 @@ async def get_config_model(
_: 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),
day_parts: dict[int, str] = Depends(get_day_parts), parts: dict[int, str] = Depends(get_parts),
) -> ConfigModel: ) -> ConfigModel:
return ConfigModel.model_validate( return ConfigModel.model_validate(
{ {
"puzzle": { "puzzle": {
"solution": cfg.puzzle.solution, "solution": cfg.puzzle.solution,
"day_parts": [
{"day": day, "part": part}
for day, part in sorted(day_parts.items())
],
"begin": date.today(), # TODO "begin": date.today(), # TODO
"end": date.today(), # TODO "end": date.today(), # TODO
"closing": date.today(), # TODO "closing": date.today(), # TODO
@ -94,8 +85,25 @@ async def get_config_model(
) )
class DayPartModel(BaseModel):
day: int
part: str
@router.get("/day_parts")
async def get_day_parts(
_: None = Depends(require_admin),
parts: dict[int, str] = Depends(get_parts),
) -> list[DayPartModel]:
return [
DayPartModel.model_validate({"day": day, "part": part})
for day, part in sorted(parts.items())
]
@router.get("/doors") @router.get("/doors")
async def get_doors( async def get_doors(
_: None = Depends(require_admin),
cal_cfg: CalendarConfig = Depends(get_calendar_config), cal_cfg: CalendarConfig = Depends(get_calendar_config),
) -> DoorsSaved: ) -> DoorsSaved:
""" """
@ -108,6 +116,7 @@ async def get_doors(
@router.put("/doors") @router.put("/doors")
async def put_doors( async def put_doors(
doors: DoorsSaved, doors: DoorsSaved,
_: 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),
) -> None: ) -> None:

View file

@ -16,13 +16,12 @@
<dd>Adventskalender 2023</dd> <dd>Adventskalender 2023</dd>
<dt>Lösung</dt> <dt>Lösung</dt>
<dd>{{ admin_config_model.puzzle.solution }}</dd> <dd>{{ config_model.puzzle.solution }}</dd>
<dt>Reihenfolge</dt> <dt>Reihenfolge</dt>
<dd> <dd>
<template <template
v-for="(day_part, index) in admin_config_model.puzzle v-for="(day_part, index) in day_parts"
.day_parts"
:key="`part-${index}`" :key="`part-${index}`"
> >
<span> <span>
@ -42,17 +41,17 @@
<dd>dd-hh-mm-ss</dd> <dd>dd-hh-mm-ss</dd>
<dt>Erstes Türchen</dt> <dt>Erstes Türchen</dt>
<dd>{{ admin_config_model.puzzle.begin }}</dd> <dd>{{ config_model.puzzle.begin }}</dd>
<dt>Letztes Türchen</dt> <dt>Letztes Türchen</dt>
<dd>{{ admin_config_model.puzzle.end }}</dd> <dd>{{ config_model.puzzle.end }}</dd>
<dt>Rätsel schließt</dt> <dt>Rätsel schließt</dt>
<dd>{{ admin_config_model.puzzle.closing }}</dd> <dd>{{ config_model.puzzle.closing }}</dd>
<dt>Zufalls-Seed</dt> <dt>Zufalls-Seed</dt>
<dd class="is-family-monospace"> <dd class="is-family-monospace">
"{{ admin_config_model.puzzle.seed }}" "{{ config_model.puzzle.seed }}"
</dd> </dd>
</dl> </dl>
</div> </div>
@ -62,16 +61,15 @@
<h4>Kalender</h4> <h4>Kalender</h4>
<dl> <dl>
<dt>Definition</dt> <dt>Definition</dt>
<dd>{{ admin_config_model.calendar.config_file }}</dd> <dd>{{ config_model.calendar.config_file }}</dd>
<dt>Hintergrundbild</dt> <dt>Hintergrundbild</dt>
<dd>{{ admin_config_model.calendar.background }}</dd> <dd>{{ config_model.calendar.background }}</dd>
<dt>Türchen</dt> <dt>Türchen</dt>
<dd> <dd>
<template <template
v-for="(day_part, index) in admin_config_model.puzzle v-for="(day_part, index) in day_parts"
.day_parts"
:key="`door-${index}`" :key="`door-${index}`"
> >
<span> <span>
@ -85,14 +83,14 @@
<h4>Bilder</h4> <h4>Bilder</h4>
<dl> <dl>
<dt>Größe</dt> <dt>Größe</dt>
<dd>{{ admin_config_model.image.size }} px</dd> <dd>{{ config_model.image.size }} px</dd>
<dt>Rand</dt> <dt>Rand</dt>
<dd>{{ admin_config_model.image.border }} px</dd> <dd>{{ config_model.image.border }} px</dd>
<dt>Schriftarten</dt> <dt>Schriftarten</dt>
<dd <dd
v-for="(font, index) in admin_config_model.image.fonts" v-for="(font, index) in config_model.image.fonts"
:key="`font-${index}`" :key="`font-${index}`"
> >
{{ font.file }} (Größe {{ font.size }}) {{ font.file }} (Größe {{ font.size }})
@ -105,7 +103,7 @@
<h4>WebDAV</h4> <h4>WebDAV</h4>
<dl> <dl>
<dt>URL</dt> <dt>URL</dt>
<dd>{{ admin_config_model.webdav.url }}</dd> <dd>{{ config_model.webdav.url }}</dd>
<dt>Zugangsdaten</dt> <dt>Zugangsdaten</dt>
<!-- TODO --> <!-- TODO -->
@ -117,10 +115,10 @@
</dd> </dd>
<dt>Cache-Dauer</dt> <dt>Cache-Dauer</dt>
<dd>{{ admin_config_model.webdav.cache_ttl }} s</dd> <dd>{{ config_model.webdav.cache_ttl }} s</dd>
<dt>Konfigurationsdatei</dt> <dt>Konfigurationsdatei</dt>
<dd>{{ admin_config_model.webdav.config_file }}</dd> <dd>{{ config_model.webdav.config_file }}</dd>
<dt>UI-Admin</dt> <dt>UI-Admin</dt>
<!-- TODO --> <!-- TODO -->
@ -146,7 +144,6 @@ import BulmaDrawer from "./bulma/Drawer.vue";
interface ConfigModel { interface ConfigModel {
puzzle: { puzzle: {
solution: string; solution: string;
day_parts: { day: number; part: string }[];
begin: string; begin: string;
end: string; end: string;
closing: string; closing: string;
@ -168,6 +165,11 @@ interface ConfigModel {
}; };
} }
interface DayPartModel {
day: number;
part: string;
}
@Options({ @Options({
components: { components: {
BulmaDrawer, BulmaDrawer,
@ -175,10 +177,9 @@ interface ConfigModel {
}) })
export default class extends Vue { export default class extends Vue {
public is_loaded = false; public is_loaded = false;
public admin_config_model: ConfigModel = { public config_model: ConfigModel = {
puzzle: { puzzle: {
solution: "ABCDEFGHIJKLMNOPQRSTUVWX", solution: "ABCDEFGHIJKLMNOPQRSTUVWX",
day_parts: [],
begin: "01.12.2023", begin: "01.12.2023",
end: "24.12.2023", end: "24.12.2023",
closing: "01.04.2024", closing: "01.04.2024",
@ -199,14 +200,18 @@ export default class extends Vue {
config_file: "config.toml", config_file: "config.toml",
}, },
}; };
public day_parts: DayPartModel[] = [];
public on_open(): void { public on_open(): void {
this.is_loaded = false; this.is_loaded = false;
this.$advent22 Promise.all([
.api_get<ConfigModel>("admin/config_model") this.$advent22.api_get<ConfigModel>("admin/config_model"),
.then((data) => { this.$advent22.api_get<DayPartModel[]>("admin/day_parts"),
this.admin_config_model = data; ])
.then(([config_model, day_parts]) => {
this.config_model = config_model;
this.day_parts = day_parts;
this.is_loaded = true; this.is_loaded = true;
}) })
.catch(console.log); .catch(console.log);