| | | 1 | | using Chronicis.Shared.DTOs; |
| | | 2 | | using MudBlazor; |
| | | 3 | | |
| | | 4 | | namespace Chronicis.Client.Pages.Admin; |
| | | 5 | | |
| | | 6 | | public partial class Status |
| | | 7 | | { |
| | | 8 | | private bool? _authorized; |
| | | 9 | | private SystemHealthStatusDto? _healthStatus; |
| | 0 | 10 | | private bool _isLoading = true; |
| | | 11 | | private DateTime? _lastChecked; |
| | | 12 | | |
| | | 13 | | protected override async Task OnInitializedAsync() |
| | | 14 | | { |
| | 0 | 15 | | _authorized = await AdminAuth.IsSysAdminAsync(); |
| | | 16 | | |
| | 0 | 17 | | if (_authorized == true) |
| | | 18 | | { |
| | 0 | 19 | | await LoadHealthStatus(); |
| | | 20 | | } |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | private async Task RefreshStatus() |
| | | 24 | | { |
| | 0 | 25 | | await LoadHealthStatus(); |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | private async Task LoadHealthStatus() |
| | | 29 | | { |
| | 0 | 30 | | _isLoading = true; |
| | 0 | 31 | | StateHasChanged(); |
| | | 32 | | |
| | | 33 | | try |
| | | 34 | | { |
| | 0 | 35 | | _healthStatus = await HealthStatusApi.GetSystemHealthAsync(); |
| | 0 | 36 | | _lastChecked = DateTime.Now; |
| | 0 | 37 | | } |
| | 0 | 38 | | catch (Exception ex) |
| | | 39 | | { |
| | | 40 | | // Log error but don't throw - we'll show the error state |
| | 0 | 41 | | Console.WriteLine($"Failed to load health status: {ex.Message}"); |
| | 0 | 42 | | } |
| | | 43 | | finally |
| | | 44 | | { |
| | 0 | 45 | | _isLoading = false; |
| | 0 | 46 | | StateHasChanged(); |
| | | 47 | | } |
| | 0 | 48 | | } |
| | | 49 | | |
| | 0 | 50 | | private static string GetFriendlyServiceName(string serviceKey) => serviceKey switch |
| | 0 | 51 | | { |
| | 0 | 52 | | ServiceKeys.Api => "API", |
| | 0 | 53 | | ServiceKeys.Database => "Database", |
| | 0 | 54 | | ServiceKeys.AzureOpenAI => "AI", |
| | 0 | 55 | | ServiceKeys.BlobStorage => "Storage", |
| | 0 | 56 | | ServiceKeys.Auth0 => "Auth", |
| | 0 | 57 | | ServiceKeys.Open5e => "External Data", |
| | 0 | 58 | | _ => serviceKey |
| | 0 | 59 | | }; |
| | | 60 | | |
| | 0 | 61 | | private static string GetServiceIcon(string serviceKey) => serviceKey switch |
| | 0 | 62 | | { |
| | 0 | 63 | | ServiceKeys.Api => Icons.Material.Filled.Api, |
| | 0 | 64 | | ServiceKeys.Database => Icons.Material.Filled.Storage, |
| | 0 | 65 | | ServiceKeys.AzureOpenAI => Icons.Material.Filled.Psychology, |
| | 0 | 66 | | ServiceKeys.BlobStorage => Icons.Material.Filled.Cloud, |
| | 0 | 67 | | ServiceKeys.Auth0 => Icons.Material.Filled.Security, |
| | 0 | 68 | | ServiceKeys.Open5e => Icons.Material.Filled.Extension, |
| | 0 | 69 | | _ => Icons.Material.Filled.Help |
| | 0 | 70 | | }; |
| | | 71 | | |
| | 0 | 72 | | private static Severity GetStatusSeverity(string status) => status switch |
| | 0 | 73 | | { |
| | 0 | 74 | | HealthStatus.Healthy => Severity.Success, |
| | 0 | 75 | | HealthStatus.Degraded => Severity.Warning, |
| | 0 | 76 | | HealthStatus.Unhealthy => Severity.Error, |
| | 0 | 77 | | _ => Severity.Info |
| | 0 | 78 | | }; |
| | | 79 | | |
| | 0 | 80 | | private static Color GetStatusColor(string status) => status switch |
| | 0 | 81 | | { |
| | 0 | 82 | | HealthStatus.Healthy => Color.Success, |
| | 0 | 83 | | HealthStatus.Degraded => Color.Warning, |
| | 0 | 84 | | HealthStatus.Unhealthy => Color.Error, |
| | 0 | 85 | | _ => Color.Info |
| | 0 | 86 | | }; |
| | | 87 | | |
| | 0 | 88 | | private static Severity GetOverallSeverity(string overallStatus) => overallStatus switch |
| | 0 | 89 | | { |
| | 0 | 90 | | HealthStatus.Healthy => Severity.Success, |
| | 0 | 91 | | HealthStatus.Degraded => Severity.Warning, |
| | 0 | 92 | | HealthStatus.Unhealthy => Severity.Error, |
| | 0 | 93 | | _ => Severity.Info |
| | 0 | 94 | | }; |
| | | 95 | | |
| | 0 | 96 | | private static string GetOverallStatusIcon(string overallStatus) => overallStatus switch |
| | 0 | 97 | | { |
| | 0 | 98 | | HealthStatus.Healthy => Icons.Material.Filled.CheckCircle, |
| | 0 | 99 | | HealthStatus.Degraded => Icons.Material.Filled.Warning, |
| | 0 | 100 | | HealthStatus.Unhealthy => Icons.Material.Filled.Error, |
| | 0 | 101 | | _ => Icons.Material.Filled.Info |
| | 0 | 102 | | }; |
| | | 103 | | } |