From a453a51b3ed0cde0790014dec4557f01c6dbbd83 Mon Sep 17 00:00:00 2001 From: Erik Prescher Date: Mon, 3 Nov 2025 22:58:40 +0100 Subject: [PATCH 1/7] feat: Color into Rework branch --- .../files/sql/idempotent/fworch-texts.sql | 16 +++++++ roles/database/files/upgrade/8.8.11.sql | 10 ++++ .../files/FWO.Config.Api/Data/ColorScheme.cs | 45 ++++++++++++++++++ .../files/FWO.Config.Api/Data/ConfigData.cs | 3 ++ .../Pages/Settings/SettingsDefaults.razor | 14 ++++++ .../FWO.UI/Services/ColorThemeService.cs | 46 +++++++++++++++++++ .../files/FWO.UI/Shared/NavigationMenu.razor | 4 +- roles/ui/files/FWO.UI/wwwroot/css/site.css | 5 +- 8 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 roles/database/files/upgrade/8.8.11.sql create mode 100644 roles/lib/files/FWO.Config.Api/Data/ColorScheme.cs create mode 100644 roles/ui/files/FWO.UI/Services/ColorThemeService.cs diff --git a/roles/database/files/sql/idempotent/fworch-texts.sql b/roles/database/files/sql/idempotent/fworch-texts.sql index 191a94c2df..042b826903 100644 --- a/roles/database/files/sql/idempotent/fworch-texts.sql +++ b/roles/database/files/sql/idempotent/fworch-texts.sql @@ -2531,6 +2531,22 @@ INSERT INTO txt VALUES ('complianceCheckRelevantManagements','German', 'Relevant INSERT INTO txt VALUES ('complianceCheckRelevantManagements','English','Relevant managements'); INSERT INTO txt VALUES ('availableModules', 'German', 'Verfügbare Module'); INSERT INTO txt VALUES ('availableModules', 'English', 'Available Modules'); +INSERT INTO txt VALUES ('notification', 'German', 'Benachrichtigung'); +INSERT INTO txt VALUES ('notification', 'English', 'Notification'); +INSERT INTO txt VALUES ('edit_notification', 'German', 'Benachrichtigung bearbeiten'); +INSERT INTO txt VALUES ('edit_notification', 'English', 'Edit Notification'); +INSERT INTO txt VALUES ('delete_notification', 'German', 'Benachrichtigung löschen'); +INSERT INTO txt VALUES ('delete_notification', 'English', 'Delete Notification'); +INSERT INTO txt VALUES ('color_scheme', 'German', 'Farbschema'); +INSERT INTO txt VALUES ('color_scheme', 'English', 'Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_blue', 'German', 'Blaues Farbschema'); +INSERT INTO txt VALUES ('color_scheme_blue', 'English', 'Blue Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_green', 'German', 'Grünes Farbschema'); +INSERT INTO txt VALUES ('color_scheme_green', 'English', 'Green Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_red', 'German', 'Rotes Farbschema'); +INSERT INTO txt VALUES ('color_scheme_red', 'English', 'Red Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_purple', 'German', 'Violettes Farbschema'); +INSERT INTO txt VALUES ('color_scheme_purple', 'English', 'Purple Color Scheme'); -- monitoring diff --git a/roles/database/files/upgrade/8.8.11.sql b/roles/database/files/upgrade/8.8.11.sql new file mode 100644 index 0000000000..5ad1af5e29 --- /dev/null +++ b/roles/database/files/upgrade/8.8.11.sql @@ -0,0 +1,10 @@ +INSERT INTO txt VALUES ('color_scheme', 'German', 'Farbschema'); +INSERT INTO txt VALUES ('color_scheme', 'English', 'Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_standard', 'German', 'Standard Farbschema'); +INSERT INTO txt VALUES ('color_scheme_standard', 'English', 'Standard Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_green', 'German', 'Grünes Farbschema'); +INSERT INTO txt VALUES ('color_scheme_green', 'English', 'Green Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_red', 'German', 'Rotes Farbschema'); +INSERT INTO txt VALUES ('color_scheme_red', 'English', 'Red Color Scheme'); +INSERT INTO txt VALUES ('color_scheme_purple', 'German', 'Violettes Farbschema'); +INSERT INTO txt VALUES ('color_scheme_purple', 'English', 'Purple Color Scheme'); \ No newline at end of file diff --git a/roles/lib/files/FWO.Config.Api/Data/ColorScheme.cs b/roles/lib/files/FWO.Config.Api/Data/ColorScheme.cs new file mode 100644 index 0000000000..a5a95c5c42 --- /dev/null +++ b/roles/lib/files/FWO.Config.Api/Data/ColorScheme.cs @@ -0,0 +1,45 @@ +using System.Text.Json.Serialization; +using Newtonsoft.Json; +using Org.BouncyCastle.Crypto.Engines; + +namespace FWO.Config.Api.Data +{ + /// + /// a list of all available ColorSchemes + /// + public class ColorScheme + { + [JsonProperty("name"), JsonPropertyName("name")] + public string Name { get; set; } = ""; + + [JsonProperty("isDefault"), JsonPropertyName("isDefault")] + public bool IsDefault { get; set; } = false; + + [JsonProperty("hex"), JsonPropertyName("hex")] + public string Hex { get; set; } = ""; + + [JsonProperty("hex2"), JsonPropertyName("hex2")] + public string Hex2 { get; set; } = ""; + + [JsonProperty("textHex"), JsonPropertyName("textHex")] + public string TextHex { get; set; } = ""; + + + public static List AvailableSchemes { get; } = new List + { + new ColorScheme { Name = "color_scheme_blue", IsDefault = true, Hex = "#054B8C", Hex2 = "#03335E", TextHex = "#2FA5ED" }, + new ColorScheme { Name = "color_scheme_green", Hex = "#1c8c05ff" , Hex2 = "#155e03ff", TextHex = "#b4ed2fff" }, + new ColorScheme { Name = "color_scheme_red", Hex = "#8c0505ff", Hex2 = "#5e0303ff", TextHex = "#ed2f2fff" }, + new ColorScheme { Name = "color_scheme_purple", Hex = "#5b058cff", Hex2 = "#3a035eff", TextHex = "#a12fedff" } + // Add more schemes as needed + }; + + public static ColorScheme GetSchemeByName(string name) + { + return AvailableSchemes.FirstOrDefault(s => s.Name == name) ?? AvailableSchemes.First(s => s.IsDefault); + } + } + +} + + diff --git a/roles/lib/files/FWO.Config.Api/Data/ConfigData.cs b/roles/lib/files/FWO.Config.Api/Data/ConfigData.cs index d1e3785f1f..246f507d3a 100644 --- a/roles/lib/files/FWO.Config.Api/Data/ConfigData.cs +++ b/roles/lib/files/FWO.Config.Api/Data/ConfigData.cs @@ -437,6 +437,9 @@ public class ConfigData : ICloneable [JsonProperty("debugConfig"), JsonPropertyName("debugConfig")] public string DebugConfig { get; set; } = ""; + [JsonProperty("colorScheme"), JsonPropertyName("colorScheme"), UserConfigData] + public string ColorScheme { get; set; } = "color_scheme_blue"; + public ConfigData(bool editable = false) { Editable = editable; diff --git a/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor b/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor index 90bacb8981..03cc41eae0 100644 --- a/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor +++ b/roles/ui/files/FWO.UI/Pages/Settings/SettingsDefaults.razor @@ -77,6 +77,16 @@ +
+ +
+ + + @(userConfig.GetText(colorScheme.Name)) + + +
+

@@ -222,6 +232,7 @@ else private ConfigData? configData; private Language selectedLanguage = new Language(); + private ColorScheme selectedColorScheme = new ColorScheme(); private DateTime autoDiscStartDate = DateTime.Today; private DateTime autoDiscStartTime = DateTime.Now.AddSeconds(-DateTime.Now.Second); private List availableModules { get; set; } = []; @@ -238,6 +249,7 @@ else configData = await globalConfig.GetEditableConfig(); selectedLanguage = globalConfig.UiLanguages.FirstOrDefault(l => l.Name == configData.DefaultLanguage) ?? new Language(); + selectedColorScheme = ColorScheme.GetSchemeByName(configData.ColorScheme); autoDiscStartDate = autoDiscStartTime = configData.AutoDiscoverStartAt; availableModules = JsonSerializer.Deserialize>(string.IsNullOrEmpty(configData.AvailableModules) ? ModuleGroups.AllModulesNumList() : configData.AvailableModules) ?? throw new JsonException("Config data could not be parsed."); modulesVisibleDict = []; @@ -260,6 +272,8 @@ else if(configData != null) { configData.DefaultLanguage = selectedLanguage.Name; + configData.ColorScheme = selectedColorScheme.Name; + StateHasChanged(); configData.AutoDiscoverStartAt = autoDiscStartDate.Date.Add(autoDiscStartTime.TimeOfDay); availableModules = []; foreach(Module module in modulesVisibleDict.Keys) diff --git a/roles/ui/files/FWO.UI/Services/ColorThemeService.cs b/roles/ui/files/FWO.UI/Services/ColorThemeService.cs new file mode 100644 index 0000000000..e9af107b16 --- /dev/null +++ b/roles/ui/files/FWO.UI/Services/ColorThemeService.cs @@ -0,0 +1,46 @@ + +using System.Collections.Concurrent; + + +namespace FWO.Ui.Services +{ + public interface IColorModeServices + { + string GetColourMode(string key); + bool SetColourMode(string key, string mode); + } + public class ColorModeServices : IColorModeServices + { + private readonly ConcurrentDictionary _UserColorModes = new ConcurrentDictionary(); + + public string GetColourMode(string key) + { + string mode = string.Empty; + if (_UserColorModes.TryGetValue(key, out mode)) + { + return mode; + } + else + { + //Did not find + mode = "light"; //Default mode + } + return mode; + } + + public bool SetColourMode(string key, string mode) + { + bool allGood = false; + if (_UserColorModes.TryAdd(key, mode)) + { + allGood = true; + + } + else + { + allGood = _UserColorModes.TryUpdate(key, mode, _UserColorModes[key]); + } + return allGood; + } + } +} \ No newline at end of file diff --git a/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor b/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor index bacd919ff6..cf8ea41af9 100644 --- a/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor +++ b/roles/ui/files/FWO.UI/Shared/NavigationMenu.razor @@ -9,7 +9,9 @@ @if (InitComplete) {
-