381 lines
17 KiB
Plaintext
381 lines
17 KiB
Plaintext
@page "/"
|
|
@page "/dashboard"
|
|
@attribute [Authorize]
|
|
@layout MainLayout
|
|
@inject HeimdallApiClient Api
|
|
@inject AuthState Auth
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-1">
|
|
Dashboard
|
|
</MudText>
|
|
<MudText Typo="Typo.body1" Class="mb-2">
|
|
Bienvenue, <strong>@Auth.User?.DisplayName</strong>
|
|
</MudText>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-6">
|
|
<MudIcon Icon="@Icons.Material.Filled.Update" Size="Size.Small" Class="mr-1" />
|
|
Dernière mise à jour : @_lastRefresh.ToString("T")
|
|
</MudText>
|
|
|
|
@* Stats Cards Row *@
|
|
<MudGrid>
|
|
<MudItem xs="12" sm="6" lg="3">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
@if (_loading) { <MudSkeleton Width="40%" Height="32px" /><MudSkeleton Width="60%" Height="16px" Class="mt-2" /> }
|
|
else
|
|
{
|
|
<div class="d-flex align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Videocam" Color="Color.Primary" Size="Size.Medium" Class="mr-2" />
|
|
<MudText Typo="Typo.h4" Color="Color.Primary">@_stats?.TotalCameras</MudText>
|
|
</div>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Caméras</MudText>
|
|
<MudText Typo="Typo.caption" Color="Color.Success">@(_stats?.CamerasOnline ?? 0) en ligne</MudText>
|
|
<MudText Typo="Typo.caption" Color="Color.Error">@(_stats?.CamerasOffline ?? 0) hors ligne</MudText>
|
|
}
|
|
</MudPaper>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6" lg="3">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
@if (_loading) { <MudSkeleton Width="40%" Height="32px" /><MudSkeleton Width="60%" Height="16px" Class="mt-2" /> }
|
|
else
|
|
{
|
|
<div class="d-flex align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Memory" Color="Color.Success" Size="Size.Medium" Class="mr-2" />
|
|
<MudText Typo="Typo.h4" Color="Color.Success">@(_stats?.OnlineAgents ?? 0)</MudText>
|
|
</div>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Agents en ligne</MudText>
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@(_stats?.TotalAgents ?? 0) total</MudText>
|
|
}
|
|
</MudPaper>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6" lg="3">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
@if (_loading) { <MudSkeleton Width="40%" Height="32px" /><MudSkeleton Width="60%" Height="16px" Class="mt-2" /> }
|
|
else
|
|
{
|
|
<div class="d-flex align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Notifications" Color="Color.Warning" Size="Size.Medium" Class="mr-2" />
|
|
<MudText Typo="Typo.h4" Color="Color.Warning">@_eventCount24h</MudText>
|
|
</div>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Événements (24h)</MudText>
|
|
<MudLink Href="/events" Typo="Typo.caption">Voir tous →</MudLink>
|
|
}
|
|
</MudPaper>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6" lg="3">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
@if (_loading) { <MudSkeleton Width="40%" Height="32px" /><MudSkeleton Width="60%" Height="16px" Class="mt-2" /> }
|
|
else
|
|
{
|
|
<div class="d-flex align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Assignment" Color="Color.Info" Size="Size.Medium" Class="mr-2" />
|
|
<MudText Typo="Typo.h4" Color="Color.Info">@(_stats?.TotalSites ?? 0)</MudText>
|
|
</div>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Sites</MudText>
|
|
<MudLink Href="/sites" Typo="Typo.caption">Gérer →</MudLink>
|
|
}
|
|
</MudPaper>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
@* Camera Status + Recent Events Row *@
|
|
<MudGrid Class="mt-4">
|
|
@* Camera Status Breakdown *@
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
<MudText Typo="Typo.h6" Class="mb-4">
|
|
<MudIcon Icon="@Icons.Material.Filled.Videocam" Class="mr-1" Size="Size.Small" />
|
|
État des caméras
|
|
</MudText>
|
|
@if (_cameraStatusData is not null)
|
|
{
|
|
<MudTable Items="@_cameraStatusData" Hover="false" Elevation="0">
|
|
<HeaderContent>
|
|
<MudTh>Statut</MudTh>
|
|
<MudTh>Nombre</MudTh>
|
|
<MudTh></MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd>
|
|
<MudText Color="@context.Color">@context.Label</MudText>
|
|
</MudTd>
|
|
<MudTd>
|
|
<MudText Typo="Typo.h6">@context.Count</MudText>
|
|
</MudTd>
|
|
<MudTd>
|
|
<MudProgressLinear Value="@context.Percent" Color="@context.Color" style="width:100px" />
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
}
|
|
else { <MudSkeleton Width="100%" Height="100px" /> }
|
|
</MudPaper>
|
|
</MudItem>
|
|
|
|
@* Recent Events *@
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
<div class="d-flex align-center mb-4">
|
|
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
|
<MudIcon Icon="@Icons.Material.Filled.Notifications" Class="mr-1" Size="Size.Small" />
|
|
Derniers événements
|
|
</MudText>
|
|
<MudLink Href="/events" Typo="Typo.caption">Voir tout →</MudLink>
|
|
</div>
|
|
@if (_recentEventsLoading)
|
|
{
|
|
<MudSkeleton Width="100%" Height="40px" />
|
|
<MudSkeleton Width="100%" Height="40px" Class="mt-1" />
|
|
}
|
|
else if (_recentEvents is { Count: > 0 })
|
|
{
|
|
<MudTable Items="@_recentEvents" Hover="true" Elevation="0">
|
|
<HeaderContent>
|
|
<MudTh>Heure</MudTh>
|
|
<MudTh>Type</MudTh>
|
|
<MudTh>Confiance</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd><MudText Typo="Typo.body2">@context.OccurredAt.ToLocalTime().ToString("HH:mm")</MudText></MudTd>
|
|
<MudTd><MudText Color="@GetEventColor(context.Type)">@FormatEventType(context.Type)</MudText></MudTd>
|
|
<MudTd><MudText>@($"{context.Confidence:P0}")</MudText></MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
}
|
|
else
|
|
{
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Aucun événement récent.</MudText>
|
|
}
|
|
</MudPaper>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
@* Agent Workload + Quick Actions *@
|
|
<MudGrid Class="mt-4">
|
|
@* Agent Workload *@
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
<MudText Typo="Typo.h6" Class="mb-4">
|
|
<MudIcon Icon="@Icons.Material.Filled.Memory" Class="mr-1" Size="Size.Small" />
|
|
Charge des agents
|
|
</MudText>
|
|
@if (_agentsLoading)
|
|
{
|
|
<MudSkeleton Width="100%" Height="60px" />
|
|
}
|
|
else if (_agents is { Count: > 0 })
|
|
{
|
|
<MudTable Items="@_agents" Hover="true" Elevation="0">
|
|
<HeaderContent>
|
|
<MudTh>Agent</MudTh>
|
|
<MudTh>Dernier heartbeat</MudTh>
|
|
<MudTh>Statut</MudTh>
|
|
<MudTh>GPU</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd><MudLink Href="@($"/agents/{context.Id}")">@context.Name</MudLink></MudTd>
|
|
<MudTd><MudText Typo="Typo.body2">@(context.LastHeartbeat?.ToLocalTime().ToString("g") ?? "—")</MudText></MudTd>
|
|
<MudTd><MudText Color="@(context.Status == "Online" ? Color.Success : Color.Error)">@context.Status</MudText></MudTd>
|
|
<MudTd>
|
|
@if (context.HasGpu)
|
|
{
|
|
<MudIcon Icon="@Icons.Material.Filled.Memory" Color="Color.Success" Size="Size.Small" />
|
|
}
|
|
else
|
|
{
|
|
<MudText Typo="Typo.body2" Color="Color.Default">—</MudText>
|
|
}
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
<MudLink Href="/admin/agents" Typo="Typo.caption" Class="mt-2 d-block">Tous les agents →</MudLink>
|
|
}
|
|
else
|
|
{
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Aucun agent enregistré.</MudText>
|
|
}
|
|
</MudPaper>
|
|
</MudItem>
|
|
|
|
@* Quick Actions *@
|
|
<MudItem xs="12" md="6">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
<MudText Typo="Typo.h6" Class="mb-4">
|
|
<MudIcon Icon="@Icons.Material.Filled.FlashOn" Class="mr-1" Size="Size.Small" />
|
|
Actions rapides
|
|
</MudText>
|
|
<MudGrid>
|
|
<MudItem xs="6">
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Primary" Href="/events" Class="mb-4" Style="height:80px;">
|
|
<div class="d-flex flex-column align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Notifications" />
|
|
<MudText Typo="Typo.body2">Événements</MudText>
|
|
</div>
|
|
</MudButton>
|
|
</MudItem>
|
|
<MudItem xs="6">
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Secondary" Href="/sites" Class="mb-4" Style="height:80px;">
|
|
<div class="d-flex flex-column align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" />
|
|
<MudText Typo="Typo.body2">Nouveau site</MudText>
|
|
</div>
|
|
</MudButton>
|
|
</MudItem>
|
|
<MudItem xs="6">
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Warning" Href="/admin/agents" Class="mb-4" Style="height:80px;">
|
|
<div class="d-flex flex-column align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Memory" />
|
|
<MudText Typo="Typo.body2">Agents</MudText>
|
|
</div>
|
|
</MudButton>
|
|
</MudItem>
|
|
<MudItem xs="6">
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Info" Href="/audit-logs" Class="mb-4" Style="height:80px;">
|
|
<div class="d-flex flex-column align-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.History" />
|
|
<MudText Typo="Typo.body2">Audit</MudText>
|
|
</div>
|
|
</MudButton>
|
|
</MudItem>
|
|
</MudGrid>
|
|
</MudPaper>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
@* Sites Table *@
|
|
<MudGrid Class="mt-4">
|
|
<MudItem xs="12">
|
|
<MudPaper Elevation="2" Class="pa-4" Style="border-radius: 12px;">
|
|
<div class="d-flex align-center mb-4">
|
|
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
|
<MudIcon Icon="@Icons.Material.Filled.Business" Class="mr-1" Size="Size.Small" />
|
|
Sites
|
|
</MudText>
|
|
<MudTooltip Text="Rafraîchir">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Size="Size.Small" OnClick="@(async () => await LoadData())" />
|
|
</MudTooltip>
|
|
</div>
|
|
|
|
@if (_loading) { for (int i = 0; i < 3; i++) { <MudSkeleton Width="100%" Height="40px" Class="mt-1" /> } }
|
|
else if (_sites?.Count > 0)
|
|
{
|
|
<MudTable Items="@_sites" Hover="true" Striped="true" Elevation="0">
|
|
<HeaderContent>
|
|
<MudTh>Nom</MudTh>
|
|
<MudTh>Adresse</MudTh>
|
|
<MudTh>Statut</MudTh>
|
|
<MudTh>Créé le</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd><MudLink Href="@($"/sites/{context.Id}")">@context.Name</MudLink></MudTd>
|
|
<MudTd>@(context.Address ?? "—")</MudTd>
|
|
<MudTd><MudText Color="@(context.Enabled ? Color.Success : Color.Default)">@(context.Enabled ? "Actif" : "Inactif")</MudText></MudTd>
|
|
<MudTd>@context.CreatedAt.ToString("g")</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
}
|
|
else
|
|
{
|
|
<div class="pa-8 text-center">
|
|
<MudIcon Icon="@Icons.Material.Filled.Business" Size="Size.Large" Color="Color.Secondary" />
|
|
<MudText Typo="Typo.h6" Color="Color.Secondary" Class="mt-4">Aucun site configuré</MudText>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
Commencez par créer un site pour déployer vos agents de surveillance.
|
|
</MudText>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Href="/sites">
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Créer un site
|
|
</MudButton>
|
|
</div>
|
|
}
|
|
</MudPaper>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
@code {
|
|
private StatsResult? _stats;
|
|
private IReadOnlyList<SiteItem>? _sites;
|
|
private bool _loading = true;
|
|
private DateTime _lastRefresh;
|
|
private bool _recentEventsLoading;
|
|
private bool _agentsLoading;
|
|
private List<EventItem>? _recentEvents;
|
|
private int _eventCount24h;
|
|
private List<AgentItem>? _agents;
|
|
private List<CameraStatusEntry>? _cameraStatusData;
|
|
|
|
private readonly List<CameraStatusEntry> _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);
|
|
}
|