From fb02c5b4540028a4daab924c2817f307aad92090 Mon Sep 17 00:00:00 2001 From: Syed Mustafa Ahmed Naqvi Date: Thu, 27 Aug 2026 09:41:59 +0500 Subject: [PATCH] fix(models): extend Device and DashboardViewModel for live status KPIs Adds dashboard status display lines and fixes KPI card bindings to match device list state. --- .../Models/DashboardViewModel.cs | 29 +++++++++++++++---- .../Models/Device.cs | 2 ++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/HikvisionAttendanceManager.App/Models/DashboardViewModel.cs b/src/HikvisionAttendanceManager.App/Models/DashboardViewModel.cs index 9b4001a..b598f32 100644 --- a/src/HikvisionAttendanceManager.App/Models/DashboardViewModel.cs +++ b/src/HikvisionAttendanceManager.App/Models/DashboardViewModel.cs @@ -8,7 +8,7 @@ public sealed class DashboardViewModel : INotifyPropertyChanged private int _totalDevices; private int _onlineDevices; private int _offlineDevices; - private int _notTestedDevices; + private int _authenticationFailedDevices; private int _totalUsersOnDevices; private bool _isInitialLoad = true; private bool _isLoadingConnectivity; @@ -37,6 +37,14 @@ public sealed class DashboardViewModel : INotifyPropertyChanged set => SetField(ref _notTestedDevices, value); } + public int AuthenticationFailedDevices + { + get => _authenticationFailedDevices; + set => SetField(ref _authenticationFailedDevices, value); + } + + private int _notTestedDevices; + public int TotalUsersOnDevices { get => _totalUsersOnDevices; @@ -58,11 +66,19 @@ public sealed class DashboardViewModel : INotifyPropertyChanged get => _isLoadingConnectivity; set { - if (SetField(ref _isLoadingConnectivity, value)) - NotifyConnectivityDisplays(); + _isLoadingConnectivity = value; + OnPropertyChanged(); + NotifyConnectivityDisplays(); } } + public void EndConnectivityRefresh() + { + _isLoadingConnectivity = false; + OnPropertyChanged(nameof(IsLoadingConnectivity)); + NotifyConnectivityDisplays(); + } + public string TotalDevicesDisplay => IsInitialLoad ? "Loading..." : TotalDevices.ToString("N0"); public string OnlineDevicesDisplay => IsInitialLoad || IsLoadingConnectivity ? "Loading..." : OnlineDevices.ToString("N0"); public string OfflineDevicesDisplay => IsInitialLoad || IsLoadingConnectivity ? "Loading..." : OfflineDevices.ToString("N0"); @@ -70,14 +86,17 @@ public sealed class DashboardViewModel : INotifyPropertyChanged public string DeviceStatusSummary => TotalDevices == 0 ? "No devices configured" - : $"{OnlineDevices} online · {OfflineDevices} offline · {NotTestedDevices} not tested"; + : AuthenticationFailedDevices > 0 + ? $"{OnlineDevices} online · {OfflineDevices} offline · {AuthenticationFailedDevices} auth failed · {NotTestedDevices} not tested" + : $"{OnlineDevices} online · {OfflineDevices} offline · {NotTestedDevices} not tested"; public void UpdateFromDevices(IEnumerable devices) { var list = devices as IReadOnlyList ?? devices.ToList(); TotalDevices = list.Count; - OnlineDevices = list.Count(d => IsStatus(d, "Online")); + OnlineDevices = list.Count(d => IsStatus(d, "Online") || IsStatus(d, "API Error")); OfflineDevices = list.Count(d => IsStatus(d, "Offline")); + AuthenticationFailedDevices = list.Count(d => IsStatus(d, "Authentication Failed")); NotTestedDevices = list.Count(d => IsStatus(d, "Not Tested")); TotalUsersOnDevices = list.Sum(d => d.RegisteredUserCount ?? 0); OnPropertyChanged(nameof(DeviceStatusSummary)); diff --git a/src/HikvisionAttendanceManager.App/Models/Device.cs b/src/HikvisionAttendanceManager.App/Models/Device.cs index e60f92d..49c3929 100644 --- a/src/HikvisionAttendanceManager.App/Models/Device.cs +++ b/src/HikvisionAttendanceManager.App/Models/Device.cs @@ -66,6 +66,8 @@ public sealed class Device : INotifyPropertyChanged { "Online" => $"● {Name} Online", "Offline" => $"● {Name} Offline", + "Authentication Failed" => $"● {Name} Authentication Failed", + "API Error" => $"● {Name} API Error", _ => $"● {Name} Not Tested" };