From a55bcfb9e01802d9d54b857b39f7ea9bd97f541d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 15 Sep 2022 22:14:02 +0000 Subject: [PATCH] API: config change to meet the UI needs --- api/ovdashboard_api/config.py | 59 ++++++++++++++++----------- api/ovdashboard_api/routers/ticker.py | 8 ++-- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/api/ovdashboard_api/config.py b/api/ovdashboard_api/config.py index 23eaa04..8ea6353 100644 --- a/api/ovdashboard_api/config.py +++ b/api/ovdashboard_api/config.py @@ -18,11 +18,19 @@ from .settings import SETTINGS _logger = getLogger(__name__) -class TickerAPIConfig(BaseModel): +class TickerUIConfig(BaseModel): + """ + Configuration for how the UI displays the ticker content. """ - Section "[ticker.api]" in "config.txt". - Configuration for how the API generates the ticker content. + color: str = "primary" + + +class TickerConfig(TickerUIConfig): + """ + Section "[ticker]" in "config.txt". + + Combined configuration for the ticker. """ file_name: str = "ticker" @@ -30,30 +38,17 @@ class TickerAPIConfig(BaseModel): comment_marker: str = "#" -class TickerUIConfig(BaseModel): +class ImageUIConfig(BaseModel): """ - Section "[ticker.ui]" in "config.txt". - - Configuration for how the UI displays the ticker content. + Configuration for how the UI displays the image carousel. """ - display: bool = True - color: str = "primary" - speed: int = 30 + height: int = 300 + contain: bool = False + speed: int = 10000 -class TickerConfig(BaseModel): - """ - Section "[ticker]" in "config.txt". - - Combined configuration for the ticker. - """ - - api: TickerAPIConfig = TickerAPIConfig() - ui: TickerUIConfig = TickerUIConfig() - - -class ImageConfig(BaseModel): +class ImageConfig(ImageUIConfig): """ Sections "[image*]" in "config.txt". """ @@ -65,7 +60,15 @@ class ImageConfig(BaseModel): } -class CalendarConfig(BaseModel): +class CalendarUIConfig(BaseModel): + """ + Configuration for how the UI displays the calendar carousel. + """ + + speed: int = 10000 + + +class CalendarConfig(CalendarUIConfig): """ Sections "[calendar*]" in "config.txt". """ @@ -74,6 +77,15 @@ class CalendarConfig(BaseModel): aggregates: dict[str, list[str]] = {} +class ServerUIConfig(BaseModel): + """ + Section "[server]" in "config.txt". + """ + + name: str = "OEKZident" + host: str = "https://oekzident.de" + + class Config(BaseModel): """ Main representation of "config.txt". @@ -82,6 +94,7 @@ class Config(BaseModel): image_dir: str = "image" text_dir: str = "text" + server: ServerUIConfig = ServerUIConfig() ticker: TickerConfig = TickerConfig() image: ImageConfig = ImageConfig() calendar: CalendarConfig = CalendarConfig() diff --git a/api/ovdashboard_api/routers/ticker.py b/api/ovdashboard_api/routers/ticker.py index 39932b0..b10d8fa 100644 --- a/api/ovdashboard_api/routers/ticker.py +++ b/api/ovdashboard_api/routers/ticker.py @@ -31,7 +31,7 @@ async def start_router() -> None: async def get_ticker_lines() -> Iterator[str]: cfg = await Config.get() - file_name = await text_unique(cfg.ticker.api.file_name) + file_name = await text_unique(cfg.ticker.file_name) ticker = await DavFile( f"{await text_lister.remote_path}/{file_name}", @@ -52,7 +52,7 @@ async def get_ticker_content_lines( return ( line for line in ticker_lines - if not line.startswith(cfg.ticker.api.comment_marker) + if not line.startswith(cfg.ticker.comment_marker) ) @@ -60,7 +60,7 @@ async def get_ticker_content( ticker_content_lines: Iterator[str] = Depends(get_ticker_content_lines), ) -> str: cfg = await Config.get() - ticker_content = cfg.ticker.api.separator.join( + ticker_content = cfg.ticker.separator.join( ["", *ticker_content_lines, ""], ) @@ -88,4 +88,4 @@ async def get_raw_ticker( async def get_ui_config( cfg: Config = Depends(Config.get), ) -> TickerUIConfig: - return cfg.ticker.ui + return cfg.ticker