From 0d2f0574c99bad7e912eede69f7e4391aabbef1e Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Sun, 19 Jul 2026 15:19:33 +0000 Subject: [PATCH] feat(ui): add snapshot gallery with lightbox and search filter --- .../Components/Layout/MainLayout.razor | 3 + .../Components/Pages/SnapshotsPage.razor | 130 ++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 src/Heimdall.Web/Components/Pages/SnapshotsPage.razor diff --git a/src/Heimdall.Web/Components/Layout/MainLayout.razor b/src/Heimdall.Web/Components/Layout/MainLayout.razor index 8d5ada2..1ed7ae5 100644 --- a/src/Heimdall.Web/Components/Layout/MainLayout.razor +++ b/src/Heimdall.Web/Components/Layout/MainLayout.razor @@ -70,6 +70,9 @@ Événements + + Snapshots + Journal d'audit diff --git a/src/Heimdall.Web/Components/Pages/SnapshotsPage.razor b/src/Heimdall.Web/Components/Pages/SnapshotsPage.razor new file mode 100644 index 0000000..9b3a4bf --- /dev/null +++ b/src/Heimdall.Web/Components/Pages/SnapshotsPage.razor @@ -0,0 +1,130 @@ +@page "/snapshots" +@attribute [Authorize] +@layout MainLayout +@inject HeimdallApiClient Api +@inject ISnackbar Snackbar +@inject NavigationManager Nav + + + + Galerie de snapshots + + + + + + + Charger + + + + +@if (_loading) +{ + +} +else if (_snapshots is null || _snapshots.Count == 0) +{ + Aucun snapshot trouvé. +} +else +{ + + @_snapshots.Count snapshot(s) trouvé(s) + + +
+ @foreach (var ev in _snapshots) + { + + Snapshot + + @FormatEventType(ev.Type) · @ev.Confidence.ToString("P0") + + + @ev.OccurredAt.ToLocalTime().ToString("g") + + + } +
+} + +@if (_lightboxEvent is not null) +{ + + + + @FormatEventType(_lightboxEvent.Type) · @_lightboxEvent.OccurredAt.ToLocalTime().ToString("g") + Voir la caméra + + + + Snapshot + @if (!string.IsNullOrEmpty(_lightboxEvent.Label)) + { + @_lightboxEvent.Label + } + + Confiance : @_lightboxEvent.Confidence.ToString("P0") · ID : @_lightboxEvent.Id.ToString()[..8] + + + + Fermer + + +} + +@code { + private string _search = ""; + private List? _snapshots; + private bool _loading; + private bool _showLightbox; + private EventItem? _lightboxEvent; + + 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 result = await Api.GetEventsAsync(null, null, 1, 100); + 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 (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); } + finally { _loading = false; } + } + + 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 + }; +}