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
|
|
|
|
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-6">
|
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>
|
|
|
|
|
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4">
|
|
|
|
|
<MudToolBar>
|
|
|
|
|
<MudText Typo="Typo.subtitle2" Class="mr-4">Filtres</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@LoadEvents">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Search" Class="mr-1" Size="Size.Small" /> Actualiser
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudToolBar>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
|
|
|
|
|
@if (_loading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" Class="mt-8" />
|
|
|
|
|
}
|
|
|
|
|
else if (_events is null || _events.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Info" Class="mt-4">
|
|
|
|
|
Aucun événement trouvé.
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_events" Hover="true" Striped="true" Elevation="2">
|
|
|
|
|
<HeaderContent>
|
|
|
|
|
<MudTh>Horodatage</MudTh>
|
|
|
|
|
<MudTh>Caméra</MudTh>
|
|
|
|
|
<MudTh>Type</MudTh>
|
|
|
|
|
<MudTh>Confiance</MudTh>
|
|
|
|
|
<MudTh>Label</MudTh>
|
|
|
|
|
<MudTh>Actions</MudTh>
|
|
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
|
|
|
|
<MudTd DataLabel="Horodatage">
|
|
|
|
|
<MudText Typo="Typo.body2">@context.OccurredAt.ToLocalTime().ToString("g")</MudText>
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd DataLabel="Caméra">
|
|
|
|
|
<MudLink Href="@($"/cameras/{context.CameraId}")">@context.CameraId.ToString()[..8]</MudLink>
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd DataLabel="Type">
|
|
|
|
|
<MudText Color="@GetEventColor(context.Type)">@FormatEventType(context.Type)</MudText>
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd DataLabel="Confiance">
|
|
|
|
|
<MudText>@($"{context.Confidence:P0}")</MudText>
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd DataLabel="Label">@context.Label</MudTd>
|
|
|
|
|
<MudTd DataLabel="Actions">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Image" Size="Size.Small"
|
|
|
|
|
Disabled="@(context.SnapshotUrl is null)"
|
|
|
|
|
OnClick="@(() => ShowSnapshot(context))" />
|
|
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
|
|
|
|
private List<EventItem>? _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
|
|
|
|
|
{
|
2026-08-10 21:48:53 +02:00
|
|
|
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);
|
2026-07-19 13:21:25 +00:00
|
|
|
_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
|
|
|
|
|
};
|
|
|
|
|
}
|