mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-12-24 05:23:04 +00:00
splice DayPartModel from ConfigModel
This commit is contained in:
parent
334540187e
commit
4e1a9fa10d
3 changed files with 51 additions and 37 deletions
|
@ -21,7 +21,7 @@ async def get_days(
|
|||
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),
|
||||
days: list[int] = Depends(get_days),
|
||||
) -> dict[int, str]:
|
||||
|
@ -48,7 +48,7 @@ async def get_day_parts(
|
|||
|
||||
async def get_day_part(
|
||||
day: int,
|
||||
parts: dict[int, str] = Depends(get_day_parts),
|
||||
parts: dict[int, str] = Depends(get_parts),
|
||||
) -> str:
|
||||
"""
|
||||
Heute angezeigter Teil der Lösung
|
||||
|
|
|
@ -5,7 +5,7 @@ from pydantic import BaseModel
|
|||
|
||||
from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_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 ._security import require_admin, user_is_admin
|
||||
|
||||
|
@ -21,12 +21,7 @@ async def is_admin(
|
|||
|
||||
class ConfigModel(BaseModel):
|
||||
class __Puzzle(BaseModel):
|
||||
class __Part(BaseModel):
|
||||
day: int
|
||||
part: str
|
||||
|
||||
solution: str
|
||||
day_parts: list[__Part]
|
||||
begin: date
|
||||
end: date
|
||||
closing: date
|
||||
|
@ -61,16 +56,12 @@ async def get_config_model(
|
|||
_: None = Depends(require_admin),
|
||||
cfg: Config = Depends(get_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:
|
||||
return ConfigModel.model_validate(
|
||||
{
|
||||
"puzzle": {
|
||||
"solution": cfg.puzzle.solution,
|
||||
"day_parts": [
|
||||
{"day": day, "part": part}
|
||||
for day, part in sorted(day_parts.items())
|
||||
],
|
||||
"begin": date.today(), # TODO
|
||||
"end": 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")
|
||||
async def get_doors(
|
||||
_: None = Depends(require_admin),
|
||||
cal_cfg: CalendarConfig = Depends(get_calendar_config),
|
||||
) -> DoorsSaved:
|
||||
"""
|
||||
|
@ -108,6 +116,7 @@ async def get_doors(
|
|||
@router.put("/doors")
|
||||
async def put_doors(
|
||||
doors: DoorsSaved,
|
||||
_: None = Depends(require_admin),
|
||||
cfg: Config = Depends(get_config),
|
||||
cal_cfg: CalendarConfig = Depends(get_calendar_config),
|
||||
) -> None:
|
||||
|
|
|
@ -16,13 +16,12 @@
|
|||
<dd>Adventskalender 2023</dd>
|
||||
|
||||
<dt>Lösung</dt>
|
||||
<dd>{{ admin_config_model.puzzle.solution }}</dd>
|
||||
<dd>{{ config_model.puzzle.solution }}</dd>
|
||||
|
||||
<dt>Reihenfolge</dt>
|
||||
<dd>
|
||||
<template
|
||||
v-for="(day_part, index) in admin_config_model.puzzle
|
||||
.day_parts"
|
||||
v-for="(day_part, index) in day_parts"
|
||||
:key="`part-${index}`"
|
||||
>
|
||||
<span>
|
||||
|
@ -42,17 +41,17 @@
|
|||
<dd>dd-hh-mm-ss</dd>
|
||||
|
||||
<dt>Erstes Türchen</dt>
|
||||
<dd>{{ admin_config_model.puzzle.begin }}</dd>
|
||||
<dd>{{ config_model.puzzle.begin }}</dd>
|
||||
|
||||
<dt>Letztes Türchen</dt>
|
||||
<dd>{{ admin_config_model.puzzle.end }}</dd>
|
||||
<dd>{{ config_model.puzzle.end }}</dd>
|
||||
|
||||
<dt>Rätsel schließt</dt>
|
||||
<dd>{{ admin_config_model.puzzle.closing }}</dd>
|
||||
<dd>{{ config_model.puzzle.closing }}</dd>
|
||||
|
||||
<dt>Zufalls-Seed</dt>
|
||||
<dd class="is-family-monospace">
|
||||
"{{ admin_config_model.puzzle.seed }}"
|
||||
"{{ config_model.puzzle.seed }}"
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
@ -62,16 +61,15 @@
|
|||
<h4>Kalender</h4>
|
||||
<dl>
|
||||
<dt>Definition</dt>
|
||||
<dd>{{ admin_config_model.calendar.config_file }}</dd>
|
||||
<dd>{{ config_model.calendar.config_file }}</dd>
|
||||
|
||||
<dt>Hintergrundbild</dt>
|
||||
<dd>{{ admin_config_model.calendar.background }}</dd>
|
||||
<dd>{{ config_model.calendar.background }}</dd>
|
||||
|
||||
<dt>Türchen</dt>
|
||||
<dd>
|
||||
<template
|
||||
v-for="(day_part, index) in admin_config_model.puzzle
|
||||
.day_parts"
|
||||
v-for="(day_part, index) in day_parts"
|
||||
:key="`door-${index}`"
|
||||
>
|
||||
<span>
|
||||
|
@ -85,14 +83,14 @@
|
|||
<h4>Bilder</h4>
|
||||
<dl>
|
||||
<dt>Größe</dt>
|
||||
<dd>{{ admin_config_model.image.size }} px</dd>
|
||||
<dd>{{ config_model.image.size }} px</dd>
|
||||
|
||||
<dt>Rand</dt>
|
||||
<dd>{{ admin_config_model.image.border }} px</dd>
|
||||
<dd>{{ config_model.image.border }} px</dd>
|
||||
|
||||
<dt>Schriftarten</dt>
|
||||
<dd
|
||||
v-for="(font, index) in admin_config_model.image.fonts"
|
||||
v-for="(font, index) in config_model.image.fonts"
|
||||
:key="`font-${index}`"
|
||||
>
|
||||
{{ font.file }} (Größe {{ font.size }})
|
||||
|
@ -105,7 +103,7 @@
|
|||
<h4>WebDAV</h4>
|
||||
<dl>
|
||||
<dt>URL</dt>
|
||||
<dd>{{ admin_config_model.webdav.url }}</dd>
|
||||
<dd>{{ config_model.webdav.url }}</dd>
|
||||
|
||||
<dt>Zugangsdaten</dt>
|
||||
<!-- TODO -->
|
||||
|
@ -117,10 +115,10 @@
|
|||
</dd>
|
||||
|
||||
<dt>Cache-Dauer</dt>
|
||||
<dd>{{ admin_config_model.webdav.cache_ttl }} s</dd>
|
||||
<dd>{{ config_model.webdav.cache_ttl }} s</dd>
|
||||
|
||||
<dt>Konfigurationsdatei</dt>
|
||||
<dd>{{ admin_config_model.webdav.config_file }}</dd>
|
||||
<dd>{{ config_model.webdav.config_file }}</dd>
|
||||
|
||||
<dt>UI-Admin</dt>
|
||||
<!-- TODO -->
|
||||
|
@ -146,7 +144,6 @@ import BulmaDrawer from "./bulma/Drawer.vue";
|
|||
interface ConfigModel {
|
||||
puzzle: {
|
||||
solution: string;
|
||||
day_parts: { day: number; part: string }[];
|
||||
begin: string;
|
||||
end: string;
|
||||
closing: string;
|
||||
|
@ -168,6 +165,11 @@ interface ConfigModel {
|
|||
};
|
||||
}
|
||||
|
||||
interface DayPartModel {
|
||||
day: number;
|
||||
part: string;
|
||||
}
|
||||
|
||||
@Options({
|
||||
components: {
|
||||
BulmaDrawer,
|
||||
|
@ -175,10 +177,9 @@ interface ConfigModel {
|
|||
})
|
||||
export default class extends Vue {
|
||||
public is_loaded = false;
|
||||
public admin_config_model: ConfigModel = {
|
||||
public config_model: ConfigModel = {
|
||||
puzzle: {
|
||||
solution: "ABCDEFGHIJKLMNOPQRSTUVWX",
|
||||
day_parts: [],
|
||||
begin: "01.12.2023",
|
||||
end: "24.12.2023",
|
||||
closing: "01.04.2024",
|
||||
|
@ -199,14 +200,18 @@ export default class extends Vue {
|
|||
config_file: "config.toml",
|
||||
},
|
||||
};
|
||||
public day_parts: DayPartModel[] = [];
|
||||
|
||||
public on_open(): void {
|
||||
this.is_loaded = false;
|
||||
|
||||
this.$advent22
|
||||
.api_get<ConfigModel>("admin/config_model")
|
||||
.then((data) => {
|
||||
this.admin_config_model = data;
|
||||
Promise.all([
|
||||
this.$advent22.api_get<ConfigModel>("admin/config_model"),
|
||||
this.$advent22.api_get<DayPartModel[]>("admin/day_parts"),
|
||||
])
|
||||
.then(([config_model, day_parts]) => {
|
||||
this.config_model = config_model;
|
||||
this.day_parts = day_parts;
|
||||
this.is_loaded = true;
|
||||
})
|
||||
.catch(console.log);
|
||||
|
|
Loading…
Reference in a new issue