- UiErrors : messages métier centralisés (LoadFailed/SaveFailed/DeleteFailed/ OperationFailed) — plus aucun ex.Message brut dans l'UI (48 remplacés sur 19 pages), les détails techniques restent dans les logs. - UiFormat : formatage centralisé des statuts (Online → En ligne, Offline → Hors ligne, Disabled → Désactivée…) et types d'événements ; appliqué aux pages Agents (liste + détail) qui affichaient encore les valeurs brutes. - catch (Exception ex) devenus inutiles → catch simple (46 nettoyés). - Boutons = verbes, validation métier déjà en place (Le nom est requis…) couverte par les tests existants. - Tests : adaptés au message métier (Register) et au statut traduit (Agents). 182 tests Web verts.
142 lines
5.1 KiB
Plaintext
142 lines
5.1 KiB
Plaintext
@page "/snapshots"
|
|
@attribute [Authorize]
|
|
@layout MainLayout
|
|
@inject HeimdallApiClient Api
|
|
@inject ISnackbar Snackbar
|
|
@inject NavigationManager Nav
|
|
|
|
<MudText Typo="Typo.h1" Class="mb-6">
|
|
<i class="fas fa-images mr-2"></i>
|
|
Galerie de snapshots
|
|
</MudText>
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4">
|
|
<MudToolBar>
|
|
<MudTextField @bind-Value="_search" Label="Rechercher (type, label, caméra)" Variant="Variant.Outlined"
|
|
Class="mr-2" style="min-width:300px;" Placeholder="ex: Personne, Visage..." />
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@LoadSnapshots">
|
|
<MudIcon Icon="@Icons.Material.Filled.Search" Class="mr-1" Size="Size.Small" /> Charger
|
|
</MudButton>
|
|
</MudToolBar>
|
|
</MudPaper>
|
|
|
|
@if (_loading)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" Class="mt-8" />
|
|
}
|
|
else if (_snapshots is null || _snapshots.Count == 0)
|
|
{
|
|
<MudAlert Severity="Severity.Info" Class="mt-4">Aucun snapshot trouvé.</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
@_snapshots.Count snapshot(s) trouvé(s)
|
|
</MudText>
|
|
|
|
<div class="d-flex flex-wrap" style="gap: 12px;">
|
|
@foreach (var ev in _snapshots)
|
|
{
|
|
<MudPaper Elevation="2" Class="pa-2" Style="border-radius: 8px; width: 240px; cursor: pointer;"
|
|
@key="ev.Id">
|
|
<div @onclick="() => OpenLightbox(ev)" role="button" tabindex="0"
|
|
style="cursor: pointer;">
|
|
<img src="@ev.SnapshotThumbUrl ?? ev.SnapshotUrl" alt="Snapshot"
|
|
style="width:100%;height:160px;object-fit:cover;border-radius:4px;" />
|
|
<MudText Typo="Typo.caption" Class="mt-1" Color="Color.Secondary">
|
|
@FormatEventType(ev.Type) · @ev.Confidence.ToString("P0")
|
|
</MudText>
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">
|
|
@ev.OccurredAt.ToLocalTime().ToString("g")
|
|
</MudText>
|
|
</div>
|
|
</MudPaper>
|
|
}
|
|
</div>
|
|
}
|
|
|
|
@if (_lightboxEvent is not null)
|
|
{
|
|
<MudDialog @bind-Visible="_showLightbox" Options="_lightboxOptions">
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">
|
|
@FormatEventType(_lightboxEvent.Type) · @_lightboxEvent.OccurredAt.ToLocalTime().ToString("g")
|
|
<MudLink Href="@($"/cameras/{_lightboxEvent.CameraId}")" Typo="Typo.caption" Class="ml-4">Voir la caméra</MudLink>
|
|
</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
<img src="@_lightboxEvent.SnapshotUrl" alt="Snapshot" style="width:100%;height:auto;" class="rounded-lg" />
|
|
@if (!string.IsNullOrEmpty(_lightboxEvent.Label))
|
|
{
|
|
<MudText Color="Color.Primary" Typo="Typo.body2" Class="mt-2">@_lightboxEvent.Label</MudText>
|
|
}
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-2">
|
|
Confiance : @_lightboxEvent.Confidence.ToString("P0") · ID : @_lightboxEvent.Id.ToString()[..8]
|
|
</MudText>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="@(() => _showLightbox = false)">Fermer</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
}
|
|
|
|
@implements IDisposable
|
|
|
|
@code {
|
|
private string _search = "";
|
|
private List<EventItem>? _snapshots;
|
|
private bool _loading;
|
|
private bool _showLightbox;
|
|
private EventItem? _lightboxEvent;
|
|
private readonly CancellationTokenSource _cts = new();
|
|
|
|
private readonly DialogOptions _lightboxOptions = new()
|
|
{
|
|
FullWidth = true,
|
|
MaxWidth = MaxWidth.ExtraLarge,
|
|
CloseButton = true
|
|
};
|
|
|
|
protected override async Task OnInitializedAsync() => await LoadSnapshots();
|
|
|
|
private async Task LoadSnapshots()
|
|
{
|
|
_loading = true;
|
|
try
|
|
{
|
|
var ct = _cts.Token;
|
|
var result = await Api.GetEventsAsync(null, null, 1, 100);
|
|
ct.ThrowIfCancellationRequested();
|
|
var items = result?.Items ?? [];
|
|
if (!string.IsNullOrWhiteSpace(_search))
|
|
{
|
|
var q = _search.ToLowerInvariant();
|
|
items = items.Where(e =>
|
|
(e.Label?.ToLowerInvariant().Contains(q) ?? false) ||
|
|
e.Type.ToLowerInvariant().Contains(q)).ToList();
|
|
}
|
|
_snapshots = items.Where(e => e.SnapshotUrl is not null).ToList();
|
|
}
|
|
catch (OperationCanceledException) when (_cts.IsCancellationRequested) { }
|
|
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
|
finally { _loading = false; }
|
|
}
|
|
|
|
public void Dispose() => _cts.Cancel();
|
|
|
|
private void OpenLightbox(EventItem ev)
|
|
{
|
|
_lightboxEvent = ev;
|
|
_showLightbox = true;
|
|
}
|
|
|
|
private static string FormatEventType(string type) => type switch
|
|
{
|
|
"MotionDetected" => "Mouvement",
|
|
"PersonDetected" => "Personne",
|
|
"VehicleDetected" => "Véhicule",
|
|
"FaceRecognized" => "Visage",
|
|
_ => type
|
|
};
|
|
}
|