feat(ui): add events page and event timeline on camera detail
This commit is contained in:
1 parent
8ac8baf20a
commit
add9ebf462
4 files changed
+247
-2
No files matched your search
@@ -67,6 +67,9 @@
|
||||
<MudNavLink Href="/admin/claims" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Policy" /> Matrice des permissions
|
||||
</MudNavLink>
|
||||
<MudNavLink Href="/events" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Notifications" /> Événements
|
||||
</MudNavLink>
|
||||
<MudNavLink Href="/audit-logs" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.History" /> Journal d'audit
|
||||
</MudNavLink>
|
||||
|
||||
@@ -66,18 +66,81 @@ else
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="@(() => Nav.NavigateTo($"/sites/{_camera.SiteId}/cameras"))">
|
||||
← Retour aux caméras
|
||||
</MudButton>
|
||||
|
||||
@* Recent Events *@
|
||||
<MudText Typo="Typo.h6" Class="mb-4 mt-8">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Notifications" Class="mr-1" /> Événements récents
|
||||
</MudText>
|
||||
|
||||
@if (_eventsLoading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" Size="Size.Small" />
|
||||
}
|
||||
else if (_events is { Count: > 0 })
|
||||
{
|
||||
<MudTable Items="@_events" Hover="true" Elevation="1">
|
||||
<HeaderContent>
|
||||
<MudTh>Horodatage</MudTh>
|
||||
<MudTh>Type</MudTh>
|
||||
<MudTh>Confiance</MudTh>
|
||||
<MudTh>Label</MudTh>
|
||||
<MudTh></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Horodatage">@context.OccurredAt.ToLocalTime().ToString("g")</MudTd>
|
||||
<MudTd DataLabel="Type">@context.Type</MudTd>
|
||||
<MudTd DataLabel="Confiance">@($"{context.Confidence:P0}")</MudTd>
|
||||
<MudTd DataLabel="Label">@context.Label</MudTd>
|
||||
<MudTd DataLabel="">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Image" Size="Size.Small"
|
||||
Disabled="@(context.SnapshotUrl is null)"
|
||||
OnClick="@(() => _showSnapshotUrl = context.SnapshotUrl)" />
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
<MudLink Href="@($"/sites/{_camera?.SiteId}/events")" Class="mt-2 d-block">
|
||||
Voir tous les événements →
|
||||
</MudLink>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Class="mt-2" Typo="Typo.body2" Color="Color.Default">Aucun événement récent.</MudText>
|
||||
}
|
||||
|
||||
@if (_showSnapshotUrl is not null)
|
||||
{
|
||||
<MudDialog @bind-Visible="@_showSnapshotDialog" Options="_snapshotOptions">
|
||||
<DialogContent>
|
||||
<img src="@_showSnapshotUrl" alt="Snapshot" style="width:100%;height:auto;" class="rounded-lg" />
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => _showSnapshotDialog = false)">Fermer</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid Id { get; set; }
|
||||
|
||||
private CameraItem? _camera;
|
||||
private bool _loading = true;
|
||||
private bool _saving;
|
||||
private string _editName = "";
|
||||
private string? _editRtspUrl;
|
||||
private string _editError = "";
|
||||
private string _editSuccess = "";
|
||||
private bool _loading = true;
|
||||
private bool _saving;
|
||||
|
||||
private List<EventItem>? _events;
|
||||
private bool _eventsLoading;
|
||||
private string? _showSnapshotUrl;
|
||||
private bool _showSnapshotDialog;
|
||||
private readonly DialogOptions _snapshotOptions = new()
|
||||
{
|
||||
FullWidth = true,
|
||||
MaxWidth = MaxWidth.Large,
|
||||
CloseButton = true
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -92,6 +155,10 @@ else
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
finally { _loading = false; }
|
||||
|
||||
try { _eventsLoading = true; _events = await Api.GetRecentEventsAsync(Id, 10); }
|
||||
catch { }
|
||||
finally { _eventsLoading = false; }
|
||||
}
|
||||
|
||||
private async Task SaveCamera()
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
@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
|
||||
};
|
||||
}
|
||||
@@ -402,6 +402,29 @@ public class HeimdallApiClient
|
||||
return await client.GetFromJsonAsync<Dictionary<string, string>>(
|
||||
$"api/settings/agent/{agentId}") ?? [];
|
||||
}
|
||||
|
||||
// ─── Events ────────────────────────────────────────────────────────
|
||||
|
||||
public async Task<EventPageResult?> GetEventsAsync(Guid? cameraId, Guid? siteId, int page = 1, int pageSize = 50)
|
||||
{
|
||||
var client = CreateClient();
|
||||
var query = $"page={page}&pageSize={pageSize}";
|
||||
if (cameraId.HasValue) query += $"&cameraId={cameraId}";
|
||||
if (siteId.HasValue) query += $"&siteId={siteId}";
|
||||
return await client.GetFromJsonAsync<EventPageResult>($"api/events?{query}", Json);
|
||||
}
|
||||
|
||||
public async Task<List<EventItem>?> GetRecentEventsAsync(Guid cameraId, int count = 20)
|
||||
{
|
||||
var client = CreateClient();
|
||||
return await client.GetFromJsonAsync<List<EventItem>>($"api/events/camera/{cameraId}?count={count}", Json);
|
||||
}
|
||||
|
||||
public async Task<EventItem?> GetEventAsync(Guid eventId)
|
||||
{
|
||||
var client = CreateClient();
|
||||
return await client.GetFromJsonAsync<EventItem>($"api/events/{eventId}", Json);
|
||||
}
|
||||
}
|
||||
|
||||
public class CameraItem
|
||||
@@ -507,6 +530,23 @@ public record SetAgentSettingRequest(
|
||||
[property: JsonPropertyName("value")] string Value
|
||||
);
|
||||
|
||||
public record EventItem(
|
||||
[property: JsonPropertyName("id")] Guid Id,
|
||||
[property: JsonPropertyName("cameraId")] Guid CameraId,
|
||||
[property: JsonPropertyName("type")] string Type,
|
||||
[property: JsonPropertyName("confidence")] double Confidence,
|
||||
[property: JsonPropertyName("label")] string? Label,
|
||||
[property: JsonPropertyName("snapshotUrl")] string? SnapshotUrl,
|
||||
[property: JsonPropertyName("snapshotThumbUrl")] string? SnapshotThumbUrl,
|
||||
[property: JsonPropertyName("occurredAt")] DateTime OccurredAt,
|
||||
[property: JsonPropertyName("createdAt")] DateTime CreatedAt);
|
||||
|
||||
public record EventPageResult(
|
||||
[property: JsonPropertyName("items")] List<EventItem> Items,
|
||||
[property: JsonPropertyName("totalCount")] int TotalCount,
|
||||
[property: JsonPropertyName("page")] int Page,
|
||||
[property: JsonPropertyName("pageSize")] int PageSize);
|
||||
|
||||
// ─── Roles & Permissions DTOs ──────────────────────────────────────
|
||||
|
||||
public record RoleItem(
|
||||
|
||||
Reference in new issue
Block a user