|
| 1 | +// Licensed to ICTAce under the MIT license. |
| 2 | + |
| 3 | +namespace ICTAce.FileHub; |
| 4 | + |
| 5 | +public partial class RadzenThemeChanger |
| 6 | +{ |
| 7 | + [Inject] |
| 8 | + protected ISettingService SettingService { get; set; } = default!; |
| 9 | + |
| 10 | + [Inject] |
| 11 | + private Radzen.ThemeService ThemeService { get; set; } = default!; |
| 12 | + |
| 13 | + private string RadzenTheme { get; set; } = "default"; |
| 14 | + |
| 15 | + // Preview component state |
| 16 | + private bool _switchValue = true; |
| 17 | + private int _radioValue = 1; |
| 18 | + private int _sliderValue = 50; |
| 19 | + private int _stepsIndex = 1; |
| 20 | + private int _ratingValue = 4; |
| 21 | + private double _gaugeValue = 72; |
| 22 | + private bool _toggleValue = true; |
| 23 | + |
| 24 | + // Sample data for DataGrid |
| 25 | + private List<SampleData> _sampleData = |
| 26 | + [ |
| 27 | + new(1, "Product A", "Electronics", 299.99m, DateTime.Now.AddDays(-5), true), |
| 28 | + new(2, "Product B", "Clothing", 49.99m, DateTime.Now.AddDays(-3), true), |
| 29 | + new(3, "Product C", "Electronics", 199.99m, DateTime.Now.AddDays(-1), false), |
| 30 | + new(4, "Product D", "Home", 89.99m, DateTime.Now.AddDays(-7), true), |
| 31 | + new(5, "Product E", "Clothing", 29.99m, DateTime.Now.AddDays(-2), true), |
| 32 | + new(6, "Product F", "Home", 149.99m, DateTime.Now.AddDays(-10), false), |
| 33 | + new(7, "Product G", "Electronics", 599.99m, DateTime.Now.AddDays(-4), true), |
| 34 | + new(8, "Product H", "Clothing", 79.99m, DateTime.Now.AddDays(-6), true), |
| 35 | + ]; |
| 36 | + |
| 37 | + private record SampleData(int Id, string Name, string Category, decimal Price, DateTime Date, bool IsActive); |
| 38 | + |
| 39 | + private record ThemeOption( |
| 40 | + string Name, |
| 41 | + string Value, |
| 42 | + string Background, |
| 43 | + string Card, |
| 44 | + string Primary, |
| 45 | + string Accent, |
| 46 | + string Text, |
| 47 | + string ChartColor1, |
| 48 | + string ChartColor2, |
| 49 | + string ChartColor3, |
| 50 | + string BorderRadius); |
| 51 | + |
| 52 | + private List<ThemeOption> AvailableThemes { get; } = |
| 53 | + [ |
| 54 | + new("Default", "default", "#f5f5f5", "#ffffff", "#007bff", "#dc3545", "#212529", "#3700b3", "#ba68c8", "#f06292", "4"), |
| 55 | + new("Dark", "dark", "#121212", "#1e1e1e", "#90caf9", "#f48fb1", "#e0e0e0", "#3700b3", "#ba68c8", "#f06292", "4"), |
| 56 | + new("Material", "material", "#f5f5f5", "#ffffff", "#4340d2", "#e31c65", "#212121", "#3700b3", "#ba68c8", "#f06292", "4"), |
| 57 | + new("Material Dark", "material-dark", "#121212", "#1e1e1e", "#90caf9", "#f48fb1", "#e0e0e0", "#3700b3", "#ba68c8", "#f06292", "4"), |
| 58 | + new("Standard", "standard", "#f4f5f9", "#ffffff", "#1776d1", "#c3002f", "#212121", "#3d7cf4", "#64dfdf", "#f68769", "4"), |
| 59 | + new("Standard Dark", "standard-dark", "#19191a", "#242527", "#90caf9", "#f48fb1", "#e0e0e0", "#3d7cf4", "#64dfdf", "#f68769", "4"), |
| 60 | + new("Humanistic", "humanistic", "#f6f7fa", "#ffffff", "#376df5", "#e91e63", "#212121", "#376df5", "#64dfdf", "#f68769", "4"), |
| 61 | + new("Humanistic Dark", "humanistic-dark", "#28363c", "#38474e", "#90caf9", "#f48fb1", "#e0e0e0", "#376df5", "#64dfdf", "#f68769", "4"), |
| 62 | + new("Software", "software", "#f6f7fa", "#ffffff", "#4a5568", "#ed8936", "#2d3748", "#376df5", "#64dfdf", "#f68769", "4"), |
| 63 | + new("Software Dark", "software-dark", "#28363c", "#3a474d", "#63b3ed", "#f6ad55", "#e2e8f0", "#376df5", "#64dfdf", "#f68769", "4"), |
| 64 | + ]; |
| 65 | + |
| 66 | + private Dictionary<string, string> _settings = new(); |
| 67 | + |
| 68 | + protected override async Task OnInitializedAsync() |
| 69 | + { |
| 70 | + await base.OnInitializedAsync(); |
| 71 | + if (PageState.User != null) |
| 72 | + { |
| 73 | + _settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId); |
| 74 | + RadzenTheme = SettingService.GetSetting(_settings, "RadzenTheme", "default"); |
| 75 | + ThemeService.SetTheme(RadzenTheme); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + private async Task OnThemeSelectedAsync(string theme) |
| 80 | + { |
| 81 | + RadzenTheme = theme; |
| 82 | + |
| 83 | + // Apply theme immediately |
| 84 | + ThemeService.SetTheme(theme); |
| 85 | + |
| 86 | + // Save to user settings |
| 87 | + if (PageState.User != null) |
| 88 | + { |
| 89 | + SettingService.SetSetting(_settings, "RadzenTheme", theme); |
| 90 | + await SettingService.UpdateUserSettingsAsync(_settings, PageState.User.UserId); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments