mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 14:36:22 -05:00
Creating setting for changing navbar color.
This commit is contained in:
parent
9dd027b86b
commit
35ec6d44fe
7 changed files with 102 additions and 30 deletions
|
|
@ -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 <div className='inline-header'>
|
||||
<Header as={headerSize}>{headerContent}</Header>
|
||||
<span>
|
||||
|
|
@ -1272,22 +1279,23 @@ export const BackButton = ({...props}) => {
|
|||
return <Button icon='arrow left' content='Back' onClick={() => navigate(-1)} {...props}/>;
|
||||
}
|
||||
|
||||
export const semanticUIColorMap = {
|
||||
red: '#db2828',
|
||||
orange: '#f2711c',
|
||||
yellow: '#fbbd08',
|
||||
olive: '#b5cc18',
|
||||
green: '#21ba45',
|
||||
teal: '#00b5ad',
|
||||
blue: '#2185d0',
|
||||
violet: '#6435c9',
|
||||
purple: '#a333c8',
|
||||
pink: '#e03997',
|
||||
brown: '#a5673f',
|
||||
grey: '#767676',
|
||||
}
|
||||
|
||||
export const ColorToSemanticHexColor = (color) => {
|
||||
const colorMap = {
|
||||
red: '#db2828',
|
||||
orange: '#f2711c',
|
||||
yellow: '#fbbd08',
|
||||
olive: '#b5cc18',
|
||||
green: '#21ba45',
|
||||
teal: '#00b5ad',
|
||||
blue: '#2185d0',
|
||||
violet: '#6435c9',
|
||||
purple: '#a333c8',
|
||||
pink: '#e03997',
|
||||
brown: '#a5673f',
|
||||
grey: '#767676',
|
||||
}
|
||||
return colorMap[color] || null;
|
||||
return semanticUIColorMap[color] || null;
|
||||
}
|
||||
|
||||
export const filterToMimetypes = (filter) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React from "react";
|
||||
import {NavLink} from "react-router-dom";
|
||||
import {Dropdown, Menu} from "semantic-ui-react";
|
||||
import {Media, ThemeContext} from "../contexts/contexts";
|
||||
import {Media, SettingsContext, ThemeContext} from "../contexts/contexts";
|
||||
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
||||
import {CPUTemperatureIcon, DarkModeToggle, HotspotStatusIcon, NAME, SystemLoadIcon} from "./Common";
|
||||
import {ShareButton} from "./Share";
|
||||
|
|
@ -61,10 +61,12 @@ function NavIconWrapper(props) {
|
|||
|
||||
export function NavBar() {
|
||||
const wrolModeEnabled = useWROLMode();
|
||||
const {settings} = React.useContext(SettingsContext);
|
||||
const wrolpiIcon = <img src='/icon.svg' height='32px' width='32px' alt='WROLPi Home Icon'/>;
|
||||
const name = <i>{NAME || wrolpiIcon}</i>;
|
||||
const topNavText = wrolModeEnabled ? <>{name} <Icon name='lock'/></> : name;
|
||||
const {i} = React.useContext(ThemeContext);
|
||||
const navColor = settings && settings.nav_color ? settings.nav_color : 'violet';
|
||||
|
||||
const homeLink = <NavLink className='item' to='/' style={{paddingTop: 0, paddingBottom: 0}}>
|
||||
{topNavText}
|
||||
|
|
@ -83,7 +85,7 @@ export function NavBar() {
|
|||
|
||||
return <>
|
||||
<Media at='mobile'>
|
||||
<Menu {...i} attached='top' color='violet'>
|
||||
<Menu {...i} attached='top' color={navColor}>
|
||||
{homeLink}
|
||||
<Menu.Menu position='right'>
|
||||
{icons}
|
||||
|
|
@ -96,7 +98,7 @@ export function NavBar() {
|
|||
</Menu>
|
||||
</Media>
|
||||
<Media greaterThanOrEqual='tablet'>
|
||||
<Menu {...i} attached='top' color='violet'>
|
||||
<Menu {...i} attached='top' color={navColor}>
|
||||
{homeLink}
|
||||
{links.map(i => <MenuLink link={i} key={i.key}/>)}
|
||||
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ export function SearchIconButton() {
|
|||
}, [open]);
|
||||
|
||||
return <React.Fragment>
|
||||
<SButton icon='search' onClick={() => setOpen(!open)} color='blue'/>
|
||||
<SButton icon='search' onClick={() => setOpen(!open)} color='blue' style={{marginTop: '-0.2em'}}/>
|
||||
<Modal open={open} onClose={() => setOpen(false)} centered={false}>
|
||||
<ModalContent>
|
||||
<SearchResultsInput clearable
|
||||
|
|
|
|||
|
|
@ -14,8 +14,17 @@ import {
|
|||
ModalHeader,
|
||||
Segment
|
||||
} from "../Theme";
|
||||
import {Container, Dimmer, GridColumn, GridRow, Icon, Input} from "semantic-ui-react";
|
||||
import {APIButton, ErrorMessage, HelpPopup, HotspotToggle, ThrottleToggle, Toggle, WROLModeMessage} from "../Common";
|
||||
import {ButtonGroup, Container, Dimmer, Dropdown, GridColumn, GridRow, Icon, Input} from "semantic-ui-react";
|
||||
import {
|
||||
APIButton,
|
||||
ErrorMessage,
|
||||
HelpPopup,
|
||||
HotspotToggle,
|
||||
semanticUIColorMap,
|
||||
ThrottleToggle,
|
||||
Toggle,
|
||||
WROLModeMessage
|
||||
} from "../Common";
|
||||
import QRCode from "react-qr-code";
|
||||
import {useDockerized} from "../../hooks/customHooks";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
|
|
@ -182,6 +191,7 @@ export class SettingsPage extends React.Component {
|
|||
ignore_outdated_zims: null,
|
||||
log_level: null,
|
||||
map_directory: null,
|
||||
navColor: null,
|
||||
throttle_on_startup: null,
|
||||
throttle_status: null,
|
||||
videos_directory: null,
|
||||
|
|
@ -208,6 +218,7 @@ export class SettingsPage extends React.Component {
|
|||
ignore_outdated_zims: settings.ignore_outdated_zims,
|
||||
log_level: fromApiLogLevel(settings.log_level),
|
||||
map_directory: settings.map_directory,
|
||||
navColor: settings.nav_color || 'violet',
|
||||
throttle_on_startup: settings.throttle_on_startup,
|
||||
throttle_status: settings.throttle_status,
|
||||
videos_directory: settings.videos_directory,
|
||||
|
|
@ -219,10 +230,7 @@ export class SettingsPage extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
async handleSubmit(e) {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
async handleSubmit(callback) {
|
||||
this.setState({disabled: true, pending: true});
|
||||
let settings = {
|
||||
archive_directory: this.state.archive_directory,
|
||||
|
|
@ -234,6 +242,7 @@ export class SettingsPage extends React.Component {
|
|||
ignore_outdated_zims: this.state.ignore_outdated_zims,
|
||||
log_level: toApiLogLevel(this.state.log_level),
|
||||
map_directory: this.state.map_directory,
|
||||
nav_color: this.state.navColor,
|
||||
throttle_on_startup: this.state.throttle_on_startup,
|
||||
videos_directory: this.state.videos_directory,
|
||||
zims_directory: this.state.zims_directory,
|
||||
|
|
@ -253,6 +262,9 @@ export class SettingsPage extends React.Component {
|
|||
throw e;
|
||||
} finally {
|
||||
this.setState({disabled: false, pending: false});
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -303,6 +315,7 @@ export class SettingsPage extends React.Component {
|
|||
ignore_outdated_zims,
|
||||
log_level,
|
||||
map_directory,
|
||||
navColor,
|
||||
pending,
|
||||
qrCodeValue,
|
||||
throttle_on_startup,
|
||||
|
|
@ -312,7 +325,11 @@ export class SettingsPage extends React.Component {
|
|||
|
||||
const qrButton = <Button icon style={{marginBottom: '1em'}}><Icon name='qrcode' size='big'/></Button>;
|
||||
|
||||
return <SettingsContext.Consumer>{({settings}) => {
|
||||
const navColorOptions = Object.keys(semanticUIColorMap).map(i => {
|
||||
return {key: i, value: i, text: i.charAt(0).toUpperCase() + i.slice(1)}
|
||||
});
|
||||
|
||||
return <SettingsContext.Consumer>{({settings, fetchSettings}) => {
|
||||
const mediaDirectoryLabel = `${settings.media_directory}/`;
|
||||
return <Container fluid>
|
||||
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
||||
|
|
@ -326,7 +343,7 @@ export class SettingsPage extends React.Component {
|
|||
<Header as='h2'>Settings</Header>
|
||||
<p>Any changes will be written to <i>{settings.media_directory}/config/wrolpi.yaml</i>.</p>
|
||||
|
||||
<Form id="settings" onSubmit={this.handleSubmit}>
|
||||
<Form id="settings">
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='Download on Startup'
|
||||
|
|
@ -425,6 +442,19 @@ export class SettingsPage extends React.Component {
|
|||
<option value='5'>All</option>
|
||||
</datalist>
|
||||
|
||||
<br/>
|
||||
|
||||
<ButtonGroup>
|
||||
<Button color={navColor} onClick={e => e.preventDefault()}>Navbar Color</Button>
|
||||
<Dropdown
|
||||
className='button icon'
|
||||
floating
|
||||
options={navColorOptions}
|
||||
onChange={(e, {value}) => this.setState({navColor: value})}
|
||||
value={navColor}
|
||||
/>
|
||||
</ButtonGroup>
|
||||
|
||||
<Divider/>
|
||||
|
||||
<Header as='h3'>Special Directories</Header>
|
||||
|
|
@ -497,7 +527,7 @@ export class SettingsPage extends React.Component {
|
|||
<APIButton
|
||||
color='violet'
|
||||
size='big'
|
||||
onClick={this.handleSubmit}
|
||||
onClick={() => this.handleSubmit(fetchSettings)}
|
||||
obeyWROLMode={true}
|
||||
disabled={disabled}
|
||||
>Save</APIButton>
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue