ConfigView.num_user_doors

This commit is contained in:
Jörn-Michael Miehe 2023-09-12 21:06:52 +00:00
parent 60a451a426
commit 2d0209ae61
2 changed files with 19 additions and 5 deletions

View file

@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.responses import StreamingResponse from fastapi.responses import StreamingResponse
from PIL import Image from PIL import Image
from ..core.calendar_config import CalendarConfig, get_calendar_config from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config
from ..core.depends import get_day_image from ..core.depends import get_day_image
from ..core.helpers import api_return_image, load_image from ..core.helpers import api_return_image, load_image
from ._security import user_can_view_day, user_is_admin from ._security import user_can_view_day, user_is_admin
@ -41,3 +41,14 @@ async def get_image_for_day(
raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Wie unhöflich!!!") raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Wie unhöflich!!!")
return await api_return_image(image) return await api_return_image(image)
@router.get("/doors")
async def get_doors(
cal_cfg: CalendarConfig = Depends(get_calendar_config),
) -> DoorsSaved:
"""
User-sichtbare Türchen lesen
"""
return [door for door in cal_cfg.doors if await user_can_view_day(door.day)]

View file

@ -18,8 +18,7 @@
<dd>{{ config_model.puzzle.solution }}</dd> <dd>{{ config_model.puzzle.solution }}</dd>
<dt>Offene Türchen</dt> <dt>Offene Türchen</dt>
<!-- TODO --> <dd>{{ num_user_doors }}</dd>
<dd>10</dd>
<dt>Nächstes Türchen in</dt> <dt>Nächstes Türchen in</dt>
<!-- TODO --> <!-- TODO -->
@ -122,7 +121,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { ConfigModel, DayStrModel } from "@/lib/api"; import { ConfigModel, DayStrModel, DoorsSaved } from "@/lib/api";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import BulmaDrawer from "./bulma/Drawer.vue"; import BulmaDrawer from "./bulma/Drawer.vue";
@ -159,6 +158,7 @@ export default class extends Vue {
}, },
}; };
public day_parts: DayStrModel[] = []; public day_parts: DayStrModel[] = [];
public num_user_doors = 0;
public on_open(): void { public on_open(): void {
this.is_loaded = false; this.is_loaded = false;
@ -166,10 +166,13 @@ export default class extends Vue {
Promise.all([ Promise.all([
this.$advent22.api_get<ConfigModel>("admin/config_model"), this.$advent22.api_get<ConfigModel>("admin/config_model"),
this.$advent22.api_get<DayStrModel[]>("admin/day_parts"), this.$advent22.api_get<DayStrModel[]>("admin/day_parts"),
this.$advent22.api_get<DoorsSaved>("user/doors"),
]) ])
.then(([config_model, day_parts]) => { .then(([config_model, day_parts, user_doors]) => {
this.config_model = config_model; this.config_model = config_model;
this.day_parts = day_parts; this.day_parts = day_parts;
this.num_user_doors = user_doors.length;
this.is_loaded = true; this.is_loaded = true;
}) })
.catch(console.log); .catch(console.log);