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,8 +19,8 @@ async def check_admin(
return True
class PrivatePuzzle(BaseModel):
title: str
class ConfigModel(BaseModel):
class __Puzzle(BaseModel):
solution: str
shuffled: str
begin: date
@ -28,62 +28,58 @@ class PrivatePuzzle(BaseModel):
closing: date
seed: str
class PrivateCalendar(BaseModel):
class __Calendar(BaseModel):
config_file: str
background: str
doors: list[int]
class PrivateImage(BaseModel):
class __Image(BaseModel):
size: int
border: int
fonts: list[tuple[str, int]]
class PrivateWebDAV(BaseModel):
class __WebDAV(BaseModel):
url: str
cache_ttl: int
config_file: str
class PrivateConfig(BaseModel):
puzzle: PrivatePuzzle
calendar: PrivateCalendar
image: PrivateImage
webdav: PrivateWebDAV
puzzle: __Puzzle
calendar: __Calendar
image: __Image
webdav: __WebDAV
@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,
},
}
)

View file

@ -10,10 +10,10 @@
<dd>Adventskalender 2023</dd>
<dt>Lösung</dt>
<dd>ABCDEFGHIJKLMNOPQRSTUVWX</dd>
<dd>{{ admin_config_model.puzzle.solution }}</dd>
<dt>Reihenfolge</dt>
<dd>AGFCINBEWLKQMXDURPOSJVHT</dd>
<dd>{{ admin_config_model.puzzle.shuffled }}</dd>
<dt>Offene Türchen</dt>
<dd>10</dd>
@ -22,16 +22,16 @@
<dd>dd-hh-mm-ss</dd>
<dt>Erstes Türchen</dt>
<dd>01.12.2023</dd>
<dd>{{ admin_config_model.puzzle.begin }}</dd>
<dt>Letztes Türchen</dt>
<dd>24.12.2023</dd>
<dd>{{ admin_config_model.puzzle.end }}</dd>
<dt>Rätsel schließt</dt>
<dd>01.04.2024</dd>
<dd>{{ admin_config_model.puzzle.closing }}</dd>
<dt>Zufalls-Seed</dt>
<dd>""</dd>
<dd>{{ admin_config_model.puzzle.seed }}</dd>
</dl>
</div>
</div>
@ -40,14 +40,14 @@
<h4>Kalender</h4>
<dl>
<dt>Definition</dt>
<dd>files/default.toml</dd>
<dd>{{ admin_config_model.calendar.config_file }}</dd>
<dt>Hintergrundbild</dt>
<dd>files/adventskalender.jpg</dd>
<dd>{{ admin_config_model.calendar.background }}</dd>
<dt>Türchen</dt>
<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="icon">
<font-awesome-icon icon="fa-solid fa-bolt" />
@ -59,13 +59,13 @@
<h4>Bilder</h4>
<dl>
<dt>Größe</dt>
<dd>500 px</dd>
<dd>{{ admin_config_model.image.size }} px</dd>
<dt>Rand</dt>
<dd>30 px</dd>
<dd>{{ admin_config_model.image.border }} px</dd>
<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>
</dl>
</div>
@ -75,7 +75,7 @@
<h4>WebDAV</h4>
<dl>
<dt>URL</dt>
<dd>https://example.com/remote.php/webdav/advent22</dd>
<dd>{{ admin_config_model.webdav.url }}</dd>
<dt>Zugangsdaten</dt>
<dd>
@ -88,10 +88,10 @@
</dd>
<dt>Cache-Dauer</dt>
<dd>30 s</dd>
<dd>{{ admin_config_model.webdav.cache_ttl }} s</dd>
<dt>Konfigurationsdatei</dt>
<dd>config.toml</dd>
<dd>{{ admin_config_model.webdav.config_file }}</dd>
<dt>UI-Admin</dt>
<dd>
@ -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<ConfigModel>("admin/config_model")
.then((data) => (this.admin_config_model = data))
.catch(console.log);
}
}
</script>
<style scoped>