@page "/events"
@attribute [Authorize]
@layout MainLayout
@inject HeimdallApiClient Api
@inject ISnackbar Snackbar
@inject NavigationManager Nav
@using Microsoft.AspNetCore.WebUtilities
Événements
Filtres
Actualiser
@if (_loading)
{
}
else if (_events is null || _events.Count == 0)
{
Aucun événement trouvé.
}
else
{
Horodatage
Caméra
Type
Confiance
Label
Actions
@context.OccurredAt.ToLocalTime().ToString("g")
@context.CameraId.ToString()[..8]
@FormatEventType(context.Type)
@($"{context.Confidence:P0}")
@context.Label
}
Snapshot — @FormatEventType(_showSnapshotEvent!.Type)
Fermer
@code {
private List? _events;
private bool _loading;
private bool _showSnapshot;
private EventItem? _showSnapshotEvent;
private readonly DialogOptions _dialogOptions = new()
{
FullWidth = true,
MaxWidth = MaxWidth.Large,
CloseButton = true
};
protected override async Task OnInitializedAsync() => await LoadEvents();
private async Task LoadEvents()
{
_loading = true;
try
{
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;
var result = await Api.GetEventsAsync(null, null, 1, 50, q);
_events = result?.Items ?? [];
}
catch (Exception ex)
{
Snackbar.Add($"Erreur: {ex.Message}", Severity.Error);
}
finally { _loading = false; }
}
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
};
}