Heimdall Gitea / Build and tests (pull_request) Failing after 2m10s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
191 lines
8.3 KiB
Plaintext
191 lines
8.3 KiB
Plaintext
@page "/snapshots"
|
|
@using Heimdall.Domain.Enums
|
|
@attribute [Authorize]
|
|
@layout MainLayout
|
|
@inject HeimdallApiClient Api
|
|
@inject ISnackbar Snackbar
|
|
@inject NavigationManager Nav
|
|
@inject UiLanguageService Language
|
|
@inject UiText Text
|
|
|
|
<MudText Typo="Typo.h1" Class="mb-6">
|
|
<i class="fas fa-images mr-2"></i>
|
|
@Text["SnapshotsPage_Title"]
|
|
</MudText>
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4">
|
|
<MudToolBar>
|
|
<MudTextField @bind-Value="_search" Label="@Text["SnapshotsPage_SearchLabel"]" Variant="Variant.Outlined"
|
|
Class="mr-2" style="min-width:300px;" Placeholder="@Text["SnapshotsPage_SearchPlaceholder"]" />
|
|
<MudSelect T="string" @bind-Value="_type" Label="@Text["SnapshotsPage_Type"]" Variant="Variant.Outlined" Clearable="true" Class="mr-2" Style="min-width:180px;">
|
|
<MudSelectItem Value="@nameof(EventType.MotionDetected)">@Text["SnapshotsPage_Motion"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.PersonDetected)">@Text["SnapshotsPage_Person"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.VehicleDetected)">@Text["SnapshotsPage_Vehicle"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.UnknownPerson)">@Text["SnapshotsPage_UnknownPerson"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.FaceRecognized)">@Text["SnapshotsPage_FaceRecognized"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.LicensePlateDetected)">@Text["SnapshotsPage_LicensePlate"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.CameraOffline)">@Text["SnapshotsPage_CameraOffline"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.CameraOnline)">@Text["SnapshotsPage_CameraOnline"]</MudSelectItem>
|
|
<MudSelectItem Value="@nameof(EventType.ManualSnapshot)">@Text["SnapshotsPage_ManualSnapshot"]</MudSelectItem>
|
|
</MudSelect>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ApplyFilters">
|
|
<MudIcon Icon="@Icons.Material.Filled.Search" Class="mr-1" Size="Size.Small" /> @Text["SnapshotsPage_Load"]
|
|
</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">@Text["SnapshotsPage_Empty"]</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
@string.Format(Text["SnapshotsPage_CountFound"], _snapshots.Count)
|
|
</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" aria-label="@Text["SnapshotsPage_OpenSnapshot"]"
|
|
style="cursor: pointer;">
|
|
<img src="@(ev.SnapshotThumbUrl ?? ev.SnapshotUrl)" alt="@Text["SnapshotsPage_SnapshotAlt"]"
|
|
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", Language.Culture)
|
|
</MudText>
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">
|
|
@ev.OccurredAt.ToLocalTime().ToString("g", Language.Culture)
|
|
</MudText>
|
|
</div>
|
|
</MudPaper>
|
|
}
|
|
</div>
|
|
<div class="d-flex align-center justify-center mt-4" style="gap:16px;">
|
|
<MudButton Disabled="@(_page <= 1)" OnClick="@(() => GoToPage(_page - 1))">@Text["SnapshotsPage_Previous"]</MudButton>
|
|
<MudText Typo="Typo.body2">@string.Format(Text["SnapshotsPage_PageInfo"], _page, _totalPages, _total)</MudText>
|
|
<MudButton Disabled="@(_page >= _totalPages)" OnClick="@(() => GoToPage(_page + 1))">@Text["SnapshotsPage_Next"]</MudButton>
|
|
</div>
|
|
}
|
|
|
|
@* 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", Language.Culture)
|
|
<MudLink Href="@($"/cameras/{_lightboxEvent!.CameraId}")" Typo="Typo.caption" Class="ml-4">@Text["SnapshotsPage_ViewCamera"]</MudLink>
|
|
</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
<img src="@_lightboxEvent!.SnapshotUrl" alt="@Text["SnapshotsPage_SnapshotAlt"]" 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">
|
|
@string.Format(Text["SnapshotsPage_ConfidenceAndId"], _lightboxEvent!.Confidence.ToString("P0", Language.Culture), _lightboxEvent!.Id.ToString()[..8])
|
|
</MudText>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="@(() => _showLightbox = false)">@Text["SnapshotsPage_Close"]</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@implements IDisposable
|
|
|
|
@code {
|
|
private string _search = "";
|
|
private string? _type;
|
|
private List<EventItem>? _snapshots;
|
|
private int _page = 1;
|
|
private int _totalPages = 1;
|
|
private int _total;
|
|
private const int PageSize = 48;
|
|
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()
|
|
{
|
|
Language.LanguageChanged += OnLanguageChanged;
|
|
await LoadSnapshots();
|
|
}
|
|
|
|
private async Task LoadSnapshots()
|
|
{
|
|
_loading = true;
|
|
try
|
|
{
|
|
var ct = _cts.Token;
|
|
var result = await Api.GetEventsAsync(null, null, _page, PageSize,
|
|
string.IsNullOrWhiteSpace(_search) ? null : _search, _type, hasSnapshot: true);
|
|
ct.ThrowIfCancellationRequested();
|
|
_snapshots = result?.Items ?? [];
|
|
_total = result?.TotalCount ?? 0;
|
|
_totalPages = Math.Max(1, (int)Math.Ceiling(_total / (double)PageSize));
|
|
}
|
|
catch (OperationCanceledException) when (_cts.IsCancellationRequested) { }
|
|
catch { Snackbar.Add(Text["SnapshotsPage_LoadFailed"], Severity.Error); }
|
|
finally { _loading = false; }
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Language.LanguageChanged -= OnLanguageChanged;
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged);
|
|
|
|
private async Task GoToPage(int page)
|
|
{
|
|
_page = page;
|
|
await LoadSnapshots();
|
|
}
|
|
|
|
private async Task ApplyFilters()
|
|
{
|
|
_page = 1;
|
|
await LoadSnapshots();
|
|
}
|
|
|
|
private void OpenLightbox(EventItem ev)
|
|
{
|
|
_lightboxEvent = ev;
|
|
_showLightbox = true;
|
|
}
|
|
|
|
private string FormatEventType(string type) => type switch
|
|
{
|
|
"ManualSnapshot" => Text["SnapshotsPage_ManualSnapshot"],
|
|
"MotionDetected" => Text["SnapshotsPage_Motion"],
|
|
"PersonDetected" => Text["SnapshotsPage_Person"],
|
|
"VehicleDetected" => Text["SnapshotsPage_Vehicle"],
|
|
"FaceRecognized" => Text["SnapshotsPage_FaceRecognized"],
|
|
"UnknownPerson" => Text["SnapshotsPage_UnknownPerson"],
|
|
"LicensePlateDetected" => Text["SnapshotsPage_LicensePlate"],
|
|
"CameraOffline" => Text["SnapshotsPage_CameraOffline"],
|
|
"CameraOnline" => Text["SnapshotsPage_CameraOnline"],
|
|
_ => type
|
|
};
|
|
}
|