2026-07-19 15:19:33 +00:00
|
|
|
@page "/snapshots"
|
|
|
|
|
@attribute [Authorize]
|
|
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
@inject NavigationManager Nav
|
|
|
|
|
|
2026-08-10 22:41:49 +02:00
|
|
|
<MudText Typo="Typo.h1" Class="mb-6">
|
2026-07-27 20:11:31 +00:00
|
|
|
<i class="fas fa-images mr-2"></i>
|
2026-07-19 15:19:33 +00:00
|
|
|
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;"
|
2026-08-10 13:17:27 +02:00
|
|
|
@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>
|
2026-07-19 15:19:33 +00:00
|
|
|
</MudPaper>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-15 02:45:39 +02:00
|
|
|
@* Lightbox toujours rendu : la visibilité est pilotée uniquement par @bind-Visible.
|
|
|
|
|
Le pattern @if (_lightboxEvent is not null) { <MudDialog ...> } détruisait le composant
|
|
|
|
|
au lieu de le cacher → dialog orphelin, bouton Fermer inopérant (issue #94).
|
|
|
|
|
Le contenu n'est rendu que quand le dialog est visible (OpenLightbox définit
|
|
|
|
|
_lightboxEvent avant de passer _showLightbox à true) — accès via `!`. *@
|
|
|
|
|
<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>
|
2026-07-19 15:19:33 +00:00
|
|
|
|
2026-07-19 15:49:46 +00:00
|
|
|
@implements IDisposable
|
|
|
|
|
|
2026-07-19 15:19:33 +00:00
|
|
|
@code {
|
|
|
|
|
private string _search = "";
|
|
|
|
|
private List<EventItem>? _snapshots;
|
|
|
|
|
private bool _loading;
|
|
|
|
|
private bool _showLightbox;
|
|
|
|
|
private EventItem? _lightboxEvent;
|
2026-07-19 15:49:46 +00:00
|
|
|
private readonly CancellationTokenSource _cts = new();
|
2026-07-19 15:19:33 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2026-07-19 15:54:13 +00:00
|
|
|
var ct = _cts.Token;
|
2026-07-19 15:19:33 +00:00
|
|
|
var result = await Api.GetEventsAsync(null, null, 1, 100);
|
2026-07-19 15:54:13 +00:00
|
|
|
ct.ThrowIfCancellationRequested();
|
2026-07-19 15:19:33 +00:00
|
|
|
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();
|
|
|
|
|
}
|
2026-07-19 15:54:13 +00:00
|
|
|
catch (OperationCanceledException) when (_cts.IsCancellationRequested) { }
|
2026-08-10 23:33:06 +02:00
|
|
|
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
2026-07-19 15:19:33 +00:00
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 15:54:13 +00:00
|
|
|
public void Dispose() => _cts.Cancel();
|
|
|
|
|
|
2026-07-19 15:19:33 +00:00
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|