From 35ec6d44febe08cee5b132fb371a8507319d402b Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 30 Jul 2024 19:28:53 -0600 Subject: [PATCH] Creating setting for changing navbar color. --- app/src/components/Common.js | 40 +++++++++++++---------- app/src/components/Nav.js | 8 +++-- app/src/components/Search.js | 2 +- app/src/components/admin/Settings.js | 48 ++++++++++++++++++++++------ wrolpi/common.py | 9 ++++++ wrolpi/root_api.py | 3 +- wrolpi/schema.py | 22 +++++++++++++ 7 files changed, 102 insertions(+), 30 deletions(-) diff --git a/app/src/components/Common.js b/app/src/components/Common.js index f032ef3c..ed8b3858 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -746,7 +746,14 @@ export function HelpPopup({icon = 'question', size = null, content, position = ' /> } -export function HelpHeader({icon, headerSize = 'h2', iconSize, headerContent, popupContent, popupPosition = 'top center'}) { +export function HelpHeader({ + icon, + headerSize = 'h2', + iconSize, + headerContent, + popupContent, + popupPosition = 'top center' + }) { return
{headerContent}
@@ -1272,22 +1279,23 @@ export const BackButton = ({...props}) => { return ; - return {({settings}) => { + const navColorOptions = Object.keys(semanticUIColorMap).map(i => { + return {key: i, value: i, text: i.charAt(0).toUpperCase() + i.slice(1)} + }); + + return {({settings, fetchSettings}) => { const mediaDirectoryLabel = `${settings.media_directory}/`; return @@ -326,7 +343,7 @@ export class SettingsPage extends React.Component {
Settings

Any changes will be written to {settings.media_directory}/config/wrolpi.yaml.

-
+
All +
+ + + + this.setState({navColor: value})} + value={navColor} + /> + +
Special Directories
@@ -497,7 +527,7 @@ export class SettingsPage extends React.Component { this.handleSubmit(fetchSettings)} obeyWROLMode={true} disabled={disabled} >Save diff --git a/wrolpi/common.py b/wrolpi/common.py index fa8e57a9..6335beb8 100644 --- a/wrolpi/common.py +++ b/wrolpi/common.py @@ -466,6 +466,7 @@ class WROLPiConfig(ConfigFile): ignore_outdated_zims=False, ignored_directories=['/media/wrolpi/config', ], map_directory='map', + nav_color='violet', throttle_on_startup=False, videos_directory='videos', wrol_mode=False, @@ -597,6 +598,14 @@ class WROLPiConfig(ConfigFile): def map_directory(self, value: str): self.update({'map_directory': value}) + @property + def nav_color(self) -> str: + return self._config['nav_color'] + + @nav_color.setter + def nav_color(self, value: str): + self.update({'nav_color': value}) + @property def zims_directory(self) -> str: return self._config['zims_directory'] diff --git a/wrolpi/root_api.py b/wrolpi/root_api.py index 3a34ab97..4d2263ae 100644 --- a/wrolpi/root_api.py +++ b/wrolpi/root_api.py @@ -11,7 +11,7 @@ from sanic_ext.extensions.openapi import openapi from vininfo import Vin from vininfo.details._base import VinDetails -from modules.archive import archive_bp +from modules.archive.api import archive_bp from modules.inventory import inventory_bp from modules.map.api import map_bp from modules.otp.api import otp_bp @@ -151,6 +151,7 @@ def get_settings(_: Request): 'ignored_directories': ignored_directories, 'log_level': api_app.shared_ctx.log_level.value, 'map_directory': config.map_directory, + 'nav_color': config.nav_color, 'media_directory': str(get_media_directory()), # Convert to string to avoid conversion to relative. 'throttle_on_startup': config.throttle_on_startup, 'throttle_status': admin.throttle_status().name, diff --git a/wrolpi/schema.py b/wrolpi/schema.py index 923b173a..f7bc6aed 100644 --- a/wrolpi/schema.py +++ b/wrolpi/schema.py @@ -1,3 +1,4 @@ +import enum from dataclasses import dataclass, field from typing import Optional, List @@ -14,6 +15,21 @@ class SettingsResponse: config: SettingsObject +class SemanticUIColors(enum.StrEnum): + red = enum.auto() + orange = enum.auto() + yellow = enum.auto() + olive = enum.auto() + green = enum.auto() + teal = enum.auto() + blue = enum.auto() + violet = enum.auto() + purple = enum.auto() + pink = enum.auto() + brown = enum.auto() + grey = enum.auto() + + @dataclass class SettingsRequest: archive_directory: Optional[str] = None @@ -27,6 +43,7 @@ class SettingsRequest: ignore_outdated_zims: Optional[bool] = None log_level: Optional[int] = None map_directory: Optional[str] = None + nav_color: Optional[str] = None media_directory: Optional[str] = None throttle_on: Optional[bool] = None throttle_on_startup: Optional[bool] = None @@ -34,6 +51,11 @@ class SettingsRequest: wrol_mode: Optional[bool] = None zims_directory: Optional[str] = None + def __post_init__(self): + self.nav_color = self.nav_color.lower() if self.nav_color else None + if self.nav_color and self.nav_color not in SemanticUIColors.__members__: + raise ValidationError('Nav color is invalid') + @dataclass class RegexRequest: