135 lines
4.2 KiB
Plaintext
135 lines
4.2 KiB
Plaintext
@page "/events"
|
|||
|
|
@attribute [Authorize]
|
||
|
|
@layout MainLayout
|
||
|
|
@inject HeimdallApiClient Api
|
||
|
|
@inject ISnackbar Snackbar
|
||
|
|
@inject NavigationManager Nav
|
||
|
|
|
||
|
|
<MudText Typo="Typo.h4" Class="mb-6">
|
||
|
|
<MudIcon Icon="@Icons.Material.Filled.Notifications" Class="mr-2" />
|
||
|
|
É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>
|
||
|
|
}
|
||
|
|
|
||
|
|
@if (_showSnapshotEvent is not null)
|
||
|
|
{
|
||
|
|
<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>
|
||
|
|
}
|
||
|
|
|
||
|
|
@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
|
||
|
|
{
|
||
|
|
var result = await Api.GetEventsAsync(null, null, 1);
|
||
|
|
_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
|
||
|
|
};
|
||
|
|
}
|