2026-07-19 13:21:25 +00:00
|
|
|
@page "/events"
|
|
|
|
|
@attribute [Authorize]
|
|
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
@inject NavigationManager Nav
|
2026-08-10 21:48:53 +02:00
|
|
|
@using Microsoft.AspNetCore.WebUtilities
|
2026-07-19 13:21:25 +00:00
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
<MudText Typo="Typo.h1" Class="mb-2">
|
2026-07-27 20:11:31 +00:00
|
|
|
<i class="fas fa-bell mr-2"></i>
|
2026-07-19 13:21:25 +00:00
|
|
|
Événements
|
|
|
|
|
</MudText>
|
2026-08-10 23:19:09 +02:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
|
|
|
@(_total > 0 ? $"{_total} événement(s) trouvé(s)" : "Historique des détections")
|
|
|
|
|
</MudText>
|
2026-07-19 13:21:25 +00:00
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
@* ─── Barre de filtres fonctionnelle ─── *@
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" sm="12" md="4">
|
|
|
|
|
<MudTextField @bind-Value="_search" Label="Rechercher (label, caméra…)" Variant="Variant.Outlined"
|
|
|
|
|
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
|
|
|
|
|
OnAdornmentClick="@ApplyFilters" OnKeyDown="@HandleSearchKey"
|
|
|
|
|
Immediate="true" Class="mb-2 mb-md-0" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6" md="3">
|
|
|
|
|
<MudSelect T="string" @bind-Value="_selectedType" Label="Type" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-2 mb-md-0">
|
|
|
|
|
<MudSelectItem T="string" Value="@("")">Tous les types</MudSelectItem>
|
|
|
|
|
<MudSelectItem T="string" Value="@("MotionDetected")">Mouvement</MudSelectItem>
|
|
|
|
|
<MudSelectItem T="string" Value="@("PersonDetected")">Personne</MudSelectItem>
|
|
|
|
|
<MudSelectItem T="string" Value="@("VehicleDetected")">Véhicule</MudSelectItem>
|
|
|
|
|
<MudSelectItem T="string" Value="@("FaceRecognized")">Visage</MudSelectItem>
|
|
|
|
|
<MudSelectItem T="string" Value="@("CameraOffline")">Hors ligne</MudSelectItem>
|
|
|
|
|
</MudSelect>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6" md="3">
|
|
|
|
|
<MudDateRangePicker @bind-DateRange="_dateRange" Label="Période" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-2 mb-md-0" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="2" Class="d-flex align-center justify-end">
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ApplyFilters" Class="w-100">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Search" Class="mr-1" Size="Size.Small" /> Filtrer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
2026-07-19 13:21:25 +00:00
|
|
|
</MudPaper>
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
@* ─── 4 états : loading / error / empty / data ─── *@
|
2026-07-19 13:21:25 +00:00
|
|
|
@if (_loading)
|
|
|
|
|
{
|
2026-08-10 23:19:09 +02:00
|
|
|
<MudPaper Elevation="0" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="120px" />
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="120px" Class="mt-2" />
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="120px" Class="mt-2" />
|
|
|
|
|
</MudPaper>
|
|
|
|
|
}
|
|
|
|
|
else if (_error)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Variant="Variant.Filled" Class="mt-4">
|
|
|
|
|
<MudText>Impossible de charger les événements. Réessayez dans un instant.</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadEvents" Class="mt-2">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudAlert>
|
2026-07-19 13:21:25 +00:00
|
|
|
}
|
|
|
|
|
else if (_events is null || _events.Count == 0)
|
|
|
|
|
{
|
2026-08-10 23:19:09 +02:00
|
|
|
<MudPaper Elevation="0" Class="pa-8 text-center" Style="border-radius: var(--hmd-radius-md); border: 1px dashed var(--mud-palette-lines-default);">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.NotificationsOff" Size="Size.Large" Color="Color.Secondary" />
|
|
|
|
|
<MudText Typo="Typo.h6" Color="Color.Secondary" Class="mt-4">Aucun événement trouvé</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
|
|
|
@if (_hasActiveFilters)
|
|
|
|
|
{
|
|
|
|
|
<text>Modifiez vos filtres ou</text>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<text>Les détections apparaîtront ici dès que vos caméras repèrent un mouvement.</text>
|
|
|
|
|
}
|
|
|
|
|
</MudText>
|
|
|
|
|
@if (_hasActiveFilters)
|
|
|
|
|
{
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="@ClearFilters">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Clear" Class="mr-1" /> Effacer les filtres
|
|
|
|
|
</MudButton>
|
|
|
|
|
}
|
|
|
|
|
</MudPaper>
|
2026-07-19 13:21:25 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-08-10 23:19:09 +02:00
|
|
|
@* ─── Timeline : liste structurée avec badges colorés ─── *@
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-2" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
@foreach (var ev in _events)
|
|
|
|
|
{
|
|
|
|
|
<div class="d-flex align-center pa-3 event-row" style="border-bottom: 1px solid var(--mud-palette-lines-default);">
|
|
|
|
|
<div class="d-flex flex-column mr-4" style="min-width: 150px;">
|
|
|
|
|
<MudText Typo="Typo.body2" Class="font-weight-medium">
|
|
|
|
|
@ev.OccurredAt.ToLocalTime().ToString("dd/MM HH:mm")
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">
|
|
|
|
|
@ev.OccurredAt.ToLocalTime().ToString("ss") s
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<MudChip T="string" Size="Size.Small" Color="@GetEventColor(ev.Type)" Variant="Variant.Filled"
|
|
|
|
|
Class="mr-3" Style="min-width: 110px; justify-content: center;">
|
|
|
|
|
@FormatEventType(ev.Type)
|
|
|
|
|
</MudChip>
|
|
|
|
|
|
|
|
|
|
<div class="d-flex flex-column" style="flex:1; min-width:0;">
|
|
|
|
|
<MudLink Href="@($"/cameras/{ev.CameraId}")" Typo="Typo.body2" Class="text-truncate">
|
|
|
|
|
@ev.Label ?? "Caméra " + ev.CameraId.ToString()[..8]
|
|
|
|
|
</MudLink>
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">
|
|
|
|
|
@($"Confiance {(ev.Confidence * 100):0}%")
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-08-10 22:41:49 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Image" Size="Size.Small" aria-label="Voir le snapshot"
|
2026-08-10 23:19:09 +02:00
|
|
|
Disabled="@(ev.SnapshotUrl is null)"
|
|
|
|
|
OnClick="@(() => ShowSnapshot(ev))" />
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</MudPaper>
|
|
|
|
|
|
|
|
|
|
<PaginationBar Page="@_page" TotalPages="@_totalPages" Total="@_total"
|
|
|
|
|
Previous="@(async () => await ChangePageAsync(_page - 1))"
|
|
|
|
|
Next="@(async () => await ChangePageAsync(_page + 1))" />
|
2026-07-19 13:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 21:48:53 +02:00
|
|
|
<MudDialog @bind-Visible="_showSnapshot" Options="_dialogOptions">
|
|
|
|
|
<TitleContent>
|
|
|
|
|
<MudText Typo="Typo.h6">Snapshot — @FormatEventType(_showSnapshotEvent!.Type)</MudText>
|
|
|
|
|
</TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<img src="@_showSnapshotEvent!.SnapshotUrl" alt="Snapshot" style="width:100%" class="rounded-lg" />
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showSnapshot = false)">Fermer</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
2026-07-19 13:21:25 +00:00
|
|
|
|
|
|
|
|
@code {
|
2026-08-10 23:19:09 +02:00
|
|
|
private const int PageSize = 50;
|
|
|
|
|
|
2026-07-19 13:21:25 +00:00
|
|
|
private List<EventItem>? _events;
|
|
|
|
|
private bool _loading;
|
2026-08-10 23:19:09 +02:00
|
|
|
private bool _error;
|
2026-07-19 13:21:25 +00:00
|
|
|
private bool _showSnapshot;
|
|
|
|
|
private EventItem? _showSnapshotEvent;
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
private string _search = "";
|
|
|
|
|
private string _selectedType = "";
|
|
|
|
|
private DateRange? _dateRange;
|
|
|
|
|
private int _page = 1;
|
|
|
|
|
private int _totalPages = 1;
|
|
|
|
|
private int _total;
|
|
|
|
|
|
|
|
|
|
private bool _hasActiveFilters =>
|
|
|
|
|
!string.IsNullOrWhiteSpace(_search) || !string.IsNullOrEmpty(_selectedType) || _dateRange?.Start is not null;
|
|
|
|
|
|
2026-07-19 13:21:25 +00:00
|
|
|
private readonly DialogOptions _dialogOptions = new()
|
|
|
|
|
{
|
|
|
|
|
FullWidth = true,
|
|
|
|
|
MaxWidth = MaxWidth.Large,
|
|
|
|
|
CloseButton = true
|
|
|
|
|
};
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
var uri = Nav.Uri;
|
|
|
|
|
var query = uri.Contains('?') ? uri[(uri.IndexOf('?') + 1)..] : "";
|
|
|
|
|
var q = QueryHelpers.ParseQuery(query).TryGetValue("q", out var qv) ? qv.ToString() : null;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(q)) _search = q;
|
|
|
|
|
await LoadEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ApplyFilters()
|
|
|
|
|
{
|
|
|
|
|
_page = 1;
|
|
|
|
|
await LoadEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ClearFilters()
|
|
|
|
|
{
|
|
|
|
|
_search = "";
|
|
|
|
|
_selectedType = "";
|
|
|
|
|
_dateRange = null;
|
|
|
|
|
_page = 1;
|
|
|
|
|
await LoadEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ChangePageAsync(int page)
|
|
|
|
|
{
|
|
|
|
|
_page = page;
|
|
|
|
|
await LoadEvents();
|
|
|
|
|
}
|
2026-07-19 13:21:25 +00:00
|
|
|
|
|
|
|
|
private async Task LoadEvents()
|
|
|
|
|
{
|
|
|
|
|
_loading = true;
|
2026-08-10 23:19:09 +02:00
|
|
|
_error = false;
|
2026-07-19 13:21:25 +00:00
|
|
|
try
|
|
|
|
|
{
|
2026-08-10 23:19:09 +02:00
|
|
|
var from = _dateRange?.Start is { } start ? start.ToUniversalTime() : (DateTime?)null;
|
|
|
|
|
var to = _dateRange?.End is { } end ? end.ToUniversalTime().AddDays(1) : (DateTime?)null;
|
|
|
|
|
var result = await Api.GetEventsAsync(null, null, _page, PageSize,
|
|
|
|
|
string.IsNullOrWhiteSpace(_search) ? null : _search,
|
|
|
|
|
string.IsNullOrEmpty(_selectedType) ? null : _selectedType,
|
|
|
|
|
from, to);
|
2026-07-19 13:21:25 +00:00
|
|
|
_events = result?.Items ?? [];
|
2026-08-10 23:19:09 +02:00
|
|
|
_total = result?.TotalCount ?? 0;
|
|
|
|
|
_totalPages = Math.Max(1, (int)Math.Ceiling(_total / (double)PageSize));
|
2026-07-19 13:21:25 +00:00
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch {
|
2026-08-10 23:19:09 +02:00
|
|
|
_error = true;
|
2026-08-10 23:33:06 +02:00
|
|
|
Snackbar.Add(UiErrors.OperationFailed(), Severity.Error);
|
2026-07-19 13:21:25 +00:00
|
|
|
}
|
|
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 23:19:09 +02:00
|
|
|
private async Task HandleSearchKey(KeyboardEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == "Enter") await ApplyFilters();
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 13:21:25 +00:00
|
|
|
private void ShowSnapshot(EventItem ev)
|
|
|
|
|
{
|
|
|
|
|
_showSnapshotEvent = ev;
|
|
|
|
|
_showSnapshot = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string FormatEventType(string type) => type switch
|
|
|
|
|
{
|
|
|
|
|
"MotionDetected" => "Mouvement",
|
|
|
|
|
"PersonDetected" => "Personne",
|
|
|
|
|
"VehicleDetected" => "Véhicule",
|
|
|
|
|
"FaceRecognized" => "Visage",
|
|
|
|
|
"CameraOffline" => "Hors ligne",
|
|
|
|
|
_ => type
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static Color GetEventColor(string type) => type switch
|
|
|
|
|
{
|
|
|
|
|
"MotionDetected" => Color.Warning,
|
|
|
|
|
"PersonDetected" => Color.Error,
|
|
|
|
|
"VehicleDetected" => Color.Info,
|
|
|
|
|
"FaceRecognized" => Color.Success,
|
|
|
|
|
_ => Color.Default
|
|
|
|
|
};
|
|
|
|
|
}
|