From 954a88ab76e4f5b04d04c9a00381ad1146ebce55 Mon Sep 17 00:00:00 2001 From: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> Date: Sat, 21 Dec 2024 07:55:33 -0700 Subject: [PATCH] Include additional UI variables in docs (#824) * Update per UI variables per https://github.com/wmo-im/wis2box-ui/pull/95 * Update wis2box-create-config.py * Fix flake8 * Use UI prefix for env variables per https://github.com/wmo-im/wis2box-ui/pull/103 * Update based on PR feedback --- docs/source/reference/configuration.rst | 4 +++ wis2box-create-config.py | 38 +++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/source/reference/configuration.rst b/docs/source/reference/configuration.rst index f22c97dd..f73361eb 100644 --- a/docs/source/reference/configuration.rst +++ b/docs/source/reference/configuration.rst @@ -170,6 +170,7 @@ Web application ^^^^^^^^^^^^^^^ Web application configuration provides the ability to customize web components. +All of the below directives are optional. .. code-block:: bash @@ -177,6 +178,9 @@ Web application configuration provides the ability to customize web components. WIS2BOX_BASEMAP_ATTRIBUTION="OpenStreetMap contributors" # attribution of map tile server WIS2BOX_UI_CLUSTER=False # default setting of the cluster toggle WIS2BOX_UI_LANG="en" # default language, one of: ar, en, es, fr, ru, zh + WIS2BOX_UI_LOGO=http://example.com/logo.png # use custom organization logo in the UI + WIS2BOX_UI_BANNER_COLOR="#014e9e" # use custom background color for header and footer + WIS2BOX_UI_DISABLE_SEPARATOR_IMAGE=false # boolean to disable WMO separator Other ^^^^^ diff --git a/wis2box-create-config.py b/wis2box-create-config.py index 304c17c3..83ddd441 100644 --- a/wis2box-create-config.py +++ b/wis2box-create-config.py @@ -26,7 +26,7 @@ import random import string from string import Template -from typing import Tuple +from typing import Tuple, Union # Identify platform type WINDOWS = False @@ -284,6 +284,39 @@ def get_wis2box_url() -> str: return wis2box_url +def get_custom_ui_logo(): + """ + Prompt the user to enter a custom UI logo path or URL. + + :returns: string of URL logo + """ + while True: + logo = input("Enter the URL for the custom UI logo (leave blank to skip): ").strip() # noqa + msg = f"Confirm custom UI logo: '{logo or 'Default'}'? (y/n): " + confirm = input(msg).strip().lower() + if confirm == 'y': + return logo or None + + +def get_default_ui_language() -> Union[str, None]: + """ + Prompt the user to enter a default UI language and + validate against possible values. + + :returns: string of languge + """ + valid_languages = ['en', 'fr', 'es', 'ar', 'zh', 'ru'] + while True: + language = input("Enter the default UI language (e.g., 'fr' for French, 'ar' for Arabic, leave blank for 'en'): ").strip() or 'en' # noqa + if language in valid_languages: + msg = f"Confirm default UI language: '{language}'? (y/n): " + confirm = input(msg).strip().lower() + if confirm == 'y': + return language + else: + print(f"Invalid language. Please choose from: {', '.join(valid_languages)}.") # noqa + + def create_wis2box_env(host_datadir: str) -> None: """ creates the wis2box.env file in the host_datadir @@ -305,7 +338,8 @@ def create_wis2box_env(host_datadir: str) -> None: fh.write('# wis2box public URL\n') fh.write(f'WIS2BOX_URL={wis2box_url}\n') fh.write('WIS2BOX_UI_CLUSTER=false\n') - fh.write('WIS2BOX_UI_LANG=en\n') + fh.write(f'WIS2BOX_UI_LOGO="{get_custom_ui_logo() or ""}"\n') + fh.write(f'WIS2BOX_UI_LANG={get_default_ui_language()}\n') fh.write('\n') fh.write('# api\n') fh.write('WIS2BOX_API_TYPE=pygeoapi\n')