feat(ui): add snapshot gallery with lightbox and search filter
This commit is contained in:
1 parent
76b261378c
commit
0d2f0574c9
2 files changed
+133
No files matched your search
@@ -70,6 +70,9 @@
|
||||
<MudNavLink Href="/events" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Notifications" /> Événements
|
||||
</MudNavLink>
|
||||
<MudNavLink Href="/snapshots" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.PhotoLibrary" /> Snapshots
|
||||
</MudNavLink>
|
||||
<MudNavLink Href="/audit-logs" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.History" /> Journal d'audit
|
||||
</MudNavLink>
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
@page "/snapshots"
|
||||
@attribute [Authorize]
|
||||
@layout MainLayout
|
||||
@inject HeimdallApiClient Api
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-6">
|
||||
<MudIcon Icon="@Icons.Material.Filled.PhotoLibrary" Class="mr-2" />
|
||||
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;"
|
||||
OnClick="@(() => OpenLightbox(ev))">
|
||||
<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>
|
||||
</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>
|
||||
}
|
||||
|
||||
@code {
|
||||
private string _search = "";
|
||||
private List<EventItem>? _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
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user