From d6e0eccb0058b86adddfb84d156ca20106aba508 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 19 Nov 2024 19:02:09 +0100 Subject: [PATCH] Make dashboard titles customizable --- central_backend/src/app_config.rs | 12 ++++++++++++ .../src/server/web_api/server_controller.rs | 12 ++++++++++++ central_frontend/src/api/ServerApi.ts | 3 +++ .../src/routes/HomeRoute/CachedConsumptionWidget.tsx | 9 ++++++++- .../src/routes/HomeRoute/CurrConsumptionWidget.tsx | 6 +++++- .../src/routes/HomeRoute/RelayConsumptionWidget.tsx | 6 +++++- 6 files changed, 45 insertions(+), 3 deletions(-) diff --git a/central_backend/src/app_config.rs b/central_backend/src/app_config.rs index 818e7d0..a90e671 100644 --- a/central_backend/src/app_config.rs +++ b/central_backend/src/app_config.rs @@ -110,6 +110,18 @@ pub struct AppConfig { #[arg(short('f'), long, env, default_value_t = 5)] pub energy_fetch_interval: u64, + /// Custom current consumption title in dashboard + #[arg(long, env)] + pub dashboard_custom_current_consumption_title: Option, + + /// Custom relays consumption title in dashboard + #[arg(long, env)] + pub dashboard_custom_relays_consumption_title: Option, + + /// Custom cached consumption title in dashboard + #[arg(long, env)] + pub dashboard_custom_cached_consumption_title: Option, + /// Consumption backend provider #[clap(subcommand)] pub consumption_backend: Option, diff --git a/central_backend/src/server/web_api/server_controller.rs b/central_backend/src/server/web_api/server_controller.rs index 8eeab1d..cf54548 100644 --- a/central_backend/src/server/web_api/server_controller.rs +++ b/central_backend/src/server/web_api/server_controller.rs @@ -14,6 +14,9 @@ struct ServerConfig { constraints: StaticConstraints, unsecure_origin: String, backend_version: &'static str, + dashboard_custom_current_consumption_title: Option<&'static str>, + dashboard_custom_relays_consumption_title: Option<&'static str>, + dashboard_custom_cached_consumption_title: Option<&'static str>, } impl Default for ServerConfig { @@ -23,6 +26,15 @@ impl Default for ServerConfig { constraints: Default::default(), unsecure_origin: AppConfig::get().unsecure_origin(), backend_version: env!("CARGO_PKG_VERSION"), + dashboard_custom_current_consumption_title: AppConfig::get() + .dashboard_custom_current_consumption_title + .as_deref(), + dashboard_custom_relays_consumption_title: AppConfig::get() + .dashboard_custom_relays_consumption_title + .as_deref(), + dashboard_custom_cached_consumption_title: AppConfig::get() + .dashboard_custom_cached_consumption_title + .as_deref(), } } } diff --git a/central_frontend/src/api/ServerApi.ts b/central_frontend/src/api/ServerApi.ts index 5db6f9f..4dab89b 100644 --- a/central_frontend/src/api/ServerApi.ts +++ b/central_frontend/src/api/ServerApi.ts @@ -5,6 +5,9 @@ export interface ServerConfig { constraints: ServerConstraint; unsecure_origin: string; backend_version: string; + dashboard_custom_current_consumption_title?: string; + dashboard_custom_relays_consumption_title?: string; + dashboard_custom_cached_consumption_title?: string; } export interface ServerConstraint { diff --git a/central_frontend/src/routes/HomeRoute/CachedConsumptionWidget.tsx b/central_frontend/src/routes/HomeRoute/CachedConsumptionWidget.tsx index bb5d97d..212306b 100644 --- a/central_frontend/src/routes/HomeRoute/CachedConsumptionWidget.tsx +++ b/central_frontend/src/routes/HomeRoute/CachedConsumptionWidget.tsx @@ -2,6 +2,7 @@ import React from "react"; import { EnergyApi } from "../../api/EnergyApi"; import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider"; import StatCard from "../../widgets/StatCard"; +import { ServerApi } from "../../api/ServerApi"; export function CachedConsumptionWidget(): React.ReactElement { const snackbar = useSnackbar(); @@ -26,6 +27,12 @@ export function CachedConsumptionWidget(): React.ReactElement { }); return ( - + ); } diff --git a/central_frontend/src/routes/HomeRoute/CurrConsumptionWidget.tsx b/central_frontend/src/routes/HomeRoute/CurrConsumptionWidget.tsx index 474e269..1d7e5cf 100644 --- a/central_frontend/src/routes/HomeRoute/CurrConsumptionWidget.tsx +++ b/central_frontend/src/routes/HomeRoute/CurrConsumptionWidget.tsx @@ -2,6 +2,7 @@ import React from "react"; import { EnergyApi } from "../../api/EnergyApi"; import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider"; import StatCard from "../../widgets/StatCard"; +import { ServerApi } from "../../api/ServerApi"; export function CurrConsumptionWidget(): React.ReactElement { const snackbar = useSnackbar(); @@ -29,7 +30,10 @@ export function CurrConsumptionWidget(): React.ReactElement { return (