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.
main
SYED MUSTUFA AHMED NAQVI 2026-08-27 09:41:59 +05:00
parent df0d5a77ee
commit fb02c5b454
2 changed files with 26 additions and 5 deletions

View File

@ -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<Device> devices)
{
var list = devices as IReadOnlyList<Device> ?? 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));

View File

@ -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"
};