@page "/" @page "/dashboard" @attribute [Authorize] @layout MainLayout @inject HeimdallApiClient Api @inject AuthState Auth @inject ISnackbar Snackbar Dashboard Bienvenue, @Auth.User?.DisplayName Dernière mise à jour : @_lastRefresh.ToString("T") @* Stats Cards Row *@ @if (_loading) { } else {
@_stats?.TotalCameras
Caméras @(_stats?.CamerasOnline ?? 0) en ligne @(_stats?.CamerasOffline ?? 0) hors ligne }
@if (_loading) { } else {
@(_stats?.OnlineAgents ?? 0)
Agents en ligne @(_stats?.TotalAgents ?? 0) total }
@if (_loading) { } else {
@_eventCount24h
Événements (24h) Voir tous → }
@if (_loading) { } else {
@(_stats?.TotalSites ?? 0)
Sites Gérer → }
@* Camera Status + Recent Events Row *@ @* Camera Status Breakdown *@ État des caméras @if (_cameraStatusData is not null) { Statut Nombre @context.Label @context.Count } else { } @* Recent Events *@
Derniers événements Voir tout →
@if (_recentEventsLoading) { } else if (_recentEvents is { Count: > 0 }) { Heure Type Confiance @context.OccurredAt.ToLocalTime().ToString("HH:mm") @FormatEventType(context.Type) @($"{context.Confidence:P0}") } else { Aucun événement récent. }
@* Agent Workload + Quick Actions *@ @* Agent Workload *@ Charge des agents @if (_agentsLoading) { } else if (_agents is { Count: > 0 }) { Agent Dernier heartbeat Statut GPU @context.Name @(context.LastHeartbeat?.ToLocalTime().ToString("g") ?? "—") @context.Status @if (context.HasGpu) { } else { — } Tous les agents → } else { Aucun agent enregistré. } @* Quick Actions *@ Actions rapides
Événements
Nouveau site
Agents
Audit
@* Sites Table *@
Sites
@if (_loading) { for (int i = 0; i < 3; i++) { } } else if (_sites?.Count > 0) { Nom Adresse Statut Créé le @context.Name @(context.Address ?? "—") @(context.Enabled ? "Actif" : "Inactif") @context.CreatedAt.ToString("g") } else {
Aucun site configuré Commencez par créer un site pour déployer vos agents de surveillance. Créer un site
}
@code { private StatsResult? _stats; private IReadOnlyList? _sites; private bool _loading = true; private DateTime _lastRefresh; private bool _recentEventsLoading; private bool _agentsLoading; private List? _recentEvents; private int _eventCount24h; private List? _agents; private List? _cameraStatusData; private readonly List _defaultCameraStatus = [ new("En ligne", 0, Color.Success, 0), new("Hors ligne", 0, Color.Error, 0), new("Désactivée", 0, Color.Default, 0), ]; protected override async Task OnInitializedAsync() => await LoadData(); private async Task LoadData() { _loading = true; try { // Stats _stats = await Api.GetStatsAsync(); if (_stats is not null) { var total = _stats.CamerasOnline + _stats.CamerasOffline + (_stats.TotalCameras - _stats.CamerasOnline - _stats.CamerasOffline); total = total > 0 ? total : 1; _cameraStatusData = [ new("En ligne", _stats.CamerasOnline, Color.Success, (int)(_stats.CamerasOnline * 100.0 / total)), new("Hors ligne", _stats.CamerasOffline, Color.Error, (int)(_stats.CamerasOffline * 100.0 / total)), new("Autre", _stats.TotalCameras - _stats.CamerasOnline - _stats.CamerasOffline, Color.Default, (int)((_stats.TotalCameras - _stats.CamerasOnline - _stats.CamerasOffline) * 100.0 / total)), ]; } // Sites var sitesResult = await Api.GetSitesAsync(1, 5); _sites = sitesResult?.Items; // Agents try { _agentsLoading = true; var agentsPage = await Api.GetAllAgentsAsync(1, 5); _agents = agentsPage?.Items?.ToList(); } catch { } finally { _agentsLoading = false; } // Recent events try { _recentEventsLoading = true; var eventsResult = await Api.GetEventsAsync(null, null, 1, 10); _recentEvents = eventsResult?.Items ?? []; _eventCount24h = eventsResult?.TotalCount ?? 0; } catch { } finally { _recentEventsLoading = false; } _lastRefresh = DateTime.Now; } catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); } finally { _loading = false; } } private static string FormatEventType(string type) => type switch { "MotionDetected" => "Mouvement", "PersonDetected" => "Personne", "VehicleDetected" => "Véhicule", "FaceRecognized" => "Visage", "CameraOffline" => "Hors ligne", _ => type }; private static Color GetEventColor(string type) => type switch { "MotionDetected" => Color.Warning, "PersonDetected" => Color.Error, "VehicleDetected" => Color.Info, "FaceRecognized" => Color.Success, _ => Color.Default }; private record CameraStatusEntry(string Label, int Count, Color Color, int Percent); }