feat(ui): add PersonDetailPage (/persons/{id})

- Header with photo, name, category, watchlist badge, notes
- Face carousel (MudCarousel) with thumbnails
- Associated vehicles table
- 30-day FaceRecognized event history (client-filtered by name)
- Edit/Delete actions with PersonFormDialog
- 10 bUnit tests
This commit is contained in:
Arnaud Dartois committed 2026-10-10 17:50:22 +02:00
1 parent 3ef23aabab
commit 9bc5c1941c
2 files changed
+653

No files matched your search

@@ -0,0 +1,386 @@
@page "/persons/{Id:guid}"
@attribute [Authorize]
@layout MainLayout
@inject HeimdallApiClient Api
@inject ISnackbar Snackbar
@inject NavigationManager Nav
@using Heimdall.Web.Components.Shared
@using Heimdall.Web.Services
@if (_loading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_person is null)
{
<MudAlert Severity="Severity.Warning">Person not found</MudAlert>
}
else
{
<div class="d-flex justify-space-between align-center mb-6">
<div class="d-flex align-center gap-4">
@if (!string.IsNullOrEmpty(_person.PhotoUrl))
{
<img src="@_person.PhotoUrl" alt="@_person.DisplayName"
style="width:80px; height:80px; border-radius:50%; object-fit:cover;" />
}
else
{
<div style="width:80px; height:80px; border-radius:50%; background: var(--mud-palette-primary);
display:flex; align-items:center; justify-content:center;">
<i class="fas fa-user" style="font-size:2rem; color:white;"></i>
</div>
}
<div>
<MudText Typo="Typo.h1" Class="mb-1">@_person.DisplayName</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary">
@FormatCategory(_person.Category) · Created @_person.CreatedAt.ToString("d")
</MudText>
@if (_person.IsWatchlisted)
{
<MudChip T="string" Size="Size.Small" Color="Color.Warning"
Icon="@Icons.Material.Filled.Warning" Class="mt-2">
Watchlisted
</MudChip>
}
</div>
</div>
<div class="d-flex gap-2">
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="@(() => _showForm = true)">
<MudIcon Icon="@Icons.Material.Filled.Edit" Class="mr-1" /> Edit
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="@ConfirmDelete">
<MudIcon Icon="@Icons.Material.Filled.Delete" Class="mr-1" /> Delete
</MudButton>
</div>
</div>
@if (!string.IsNullOrEmpty(_person.Notes))
{
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
<MudText Typo="Typo.h6" Class="mb-2">Notes</MudText>
<MudText Typo="Typo.body1">@_person.Notes</MudText>
</MudPaper>
}
<MudGrid>
@* ─── Faces ─── *@
<MudItem xs="12" md="6">
<MudPaper Elevation="2" Class="pa-6" Style="border-radius: 12px; height: 100%;">
<div class="d-flex justify-space-between align-center mb-4">
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.Portrait" Class="mr-1" />
Registered faces (@_faces.Count)
</MudText>
</div>
@if (_facesLoading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_faces.Count == 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
No face registered. Add a face to improve recognition.
</MudAlert>
}
else
{
<MudCarousel TData="KnownFaceClientItem" @bind-SelectedIndex="_faceIndex">
@foreach (var face in _faces)
{
<MudCarouselItem>
<div class="d-flex flex-column align-center gap-2" style="padding: 16px;">
@if (!string.IsNullOrEmpty(face.ThumbnailUrl))
{
<img src="@face.ThumbnailUrl" alt="Face"
style="width: 200px; height: 200px; border-radius: 50%; object-fit:cover;
border: 4px solid var(--mud-palette-primary);" />
}
else
{
<div style="width: 200px; height: 200px; border-radius: 50%;
background: var(--mud-palette-grey-800);
display:flex; align-items:center; justify-content:center;">
<MudIcon Icon="@Icons.Material.Filled.Portrait" Size="Size.Large" Color="Color.Secondary" />
</div>
}
<MudText Typo="Typo.body2" Color="Color.Secondary">
@if (!string.IsNullOrEmpty(face.SourceEventId))
{
<text>Event: @face.SourceEventId.Substring(0, Math.Min(8, face.SourceEventId.Length))…</text>
}
else
{
<text>Face #@face.Id.ToString()[..8]</text>
}
</MudText>
</div>
</MudCarouselItem>
}
</MudCarousel>
<div class="d-flex justify-center gap-2 mt-4">
@for (int i = 0; i < _faces.Count; i++)
{
var idx = i;
<MudButton Size="Size.Small" Variant="@(i == _faceIndex ? Variant.Filled : Variant.Outlined)"
Color="Color.Primary" OnClick="@(() => _faceIndex = idx)"
Style="min-width: 32px; height: 32px; padding: 0; border-radius: 50%;">
@(i + 1)
</MudButton>
}
</div>
}
</MudPaper>
</MudItem>
@* ─── Vehicles ─── *@
<MudItem xs="12" md="6">
<MudPaper Elevation="2" Class="pa-6" Style="border-radius: 12px; height: 100%;">
<MudText Typo="Typo.h6" Class="mb-4">
<MudIcon Icon="@Icons.Material.Filled.ElectricCar" Class="mr-1" />
Associated vehicles (@_vehicles.Count)
</MudText>
@if (_vehiclesLoading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_vehicles.Count == 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
No vehicle associated with this person.
</MudAlert>
}
else
{
<MudTable Items="@_vehicles" Dense="true" Hover="true">
<HeaderContent>
<MudTh>Plate</MudTh>
<MudTh>Make</MudTh>
<MudTh>Model</MudTh>
<MudTh>Color</MudTh>
<MudTh>Events</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Plate"><code>@context.LicensePlate</code></MudTd>
<MudTd DataLabel="Make">@context.Make</MudTd>
<MudTd DataLabel="Model">@context.Model</MudTd>
<MudTd DataLabel="Color">@context.Color</MudTd>
<MudTd DataLabel="Events">@context.EventCount</MudTd>
</RowTemplate>
</MudTable>
}
</MudPaper>
</MudItem>
</MudGrid>
@* ─── Event history (30 days) ─── *@
<MudPaper Elevation="2" Class="pa-6 mt-6" Style="border-radius: 12px;">
<MudText Typo="Typo.h6" Class="mb-4">
<MudIcon Icon="@Icons.Material.Filled.History" Class="mr-1" />
Detection history (last 30 days)
</MudText>
@if (_eventsLoading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_events.Count == 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
No face detection for the last 30 days.
</MudAlert>
}
else
{
<MudTable Items="@_events" Dense="true" Hover="true">
<HeaderContent>
<MudTh>Date</MudTh>
<MudTh>Type</MudTh>
<MudTh>Camera</MudTh>
<MudTh>Confidence</MudTh>
<MudTh>Snapshot</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Date">@context.OccurredAt.ToLocalTime().ToString("dd/MM HH:mm")</MudTd>
<MudTd DataLabel="Type">
<MudChip T="string" Size="Size.Small" Color="Color.Success" Variant="Variant.Filled">
Face
</MudChip>
</MudTd>
<MudTd DataLabel="Camera">@context.Label</MudTd>
<MudTd DataLabel="Confidence">@((context.Confidence * 100).ToString("0"))%</MudTd>
<MudTd DataLabel="Snapshot">
@if (!string.IsNullOrEmpty(context.SnapshotUrl))
{
<MudIconButton Icon="@Icons.Material.Filled.Image" Size="Size.Small"
aria-label="View snapshot" OnClick="@(() => ShowSnapshot(context))" />
}
</MudTd>
</RowTemplate>
</MudTable>
}
</MudPaper>
<MudButton Variant="Variant.Outlined" Color="Color.Default" Class="mt-4"
OnClick="@(() => Nav.NavigateTo("/persons"))">
← Back to persons
</MudButton>
}
@* ─── Edit form ─── *@
<PersonFormDialog @bind-Visible="_showForm" Existing="_person" OnSaved="@OnPersonUpdated" />
@* ─── Confirm delete ─── *@
<MudOverlay Visible="_confirmDeleteShow" OnClick="@(() => _confirmDeleteShow = false)" />
<MudDialog @bind-Visible="_confirmDeleteShow">
<TitleContent><MudText Typo="Typo.h6">Confirm deletion</MudText></TitleContent>
<DialogContent>
<MudText>Delete the person &quot;@_person?.DisplayName&quot; ?</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2">
This action is irreversible. The @(_person?.FaceCount) registered face(s) will also be deleted.
</MudText>
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">Cancel</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@ExecuteDelete">Delete</MudButton>
</DialogActions>
</MudDialog>
@* ─── Snapshot dialog ─── *@
<MudDialog @bind-Visible="_showSnapshot" Options="_dialogOptions">
<TitleContent>
<MudText Typo="Typo.h6">Snapshot — @_showSnapshotEvent?.Label</MudText>
</TitleContent>
<DialogContent>
<img src="@_showSnapshotEvent?.SnapshotUrl" alt="Snapshot" style="width:100%" class="rounded-lg" />
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Text" OnClick="@(() => _showSnapshot = false)">Close</MudButton>
</DialogActions>
</MudDialog>
@code {
[Parameter] public Guid Id { get; set; }
private PersonClientItem? _person;
private List<KnownFaceClientItem> _faces = [];
private List<VehicleClientItem> _vehicles = [];
private List<EventItem> _events = [];
private bool _loading = true;
private bool _facesLoading = true;
private bool _vehiclesLoading = true;
private bool _eventsLoading = true;
private bool _showForm;
private bool _confirmDeleteShow;
private bool _showSnapshot;
private int _faceIndex;
private EventItem? _showSnapshotEvent;
private readonly DialogOptions _dialogOptions = new()
{
FullWidth = true,
MaxWidth = MaxWidth.Large,
CloseButton = true
};
private DateTime _eventsSince => DateTime.UtcNow.AddDays(-30);
protected override async Task OnInitializedAsync()
{
try
{
_person = await Api.GetPersonAsync(Id);
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _loading = false; }
await LoadFaces();
await LoadVehicles();
await LoadEvents();
}
private async Task LoadFaces()
{
_facesLoading = true;
try
{
_faces = (await Api.GetFacesAsync(Id)) ?? [];
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _facesLoading = false; }
}
private async Task LoadVehicles()
{
_vehiclesLoading = true;
try
{
var all = await Api.GetVehiclesAsync();
_vehicles = (all?.Where(v => v.PersonId == Id).ToList()) ?? [];
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _vehiclesLoading = false; }
}
private async Task LoadEvents()
{
_eventsLoading = true;
try
{
var result = await Api.GetEventsAsync(null, null, page: 1, pageSize: 50,
type: "FaceRecognized", from: _eventsSince);
var all = result?.Items ?? [];
var name = _person?.DisplayName;
_events = string.IsNullOrEmpty(name)
? all
: all.Where(e => e.Label?.Contains(name, StringComparison.OrdinalIgnoreCase) == true).ToList();
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
finally { _eventsLoading = false; }
}
private async Task OnPersonUpdated(PersonClientItem person)
{
_person = person;
await LoadFaces();
}
private void ConfirmDelete() => _confirmDeleteShow = true;
private async Task ExecuteDelete()
{
_confirmDeleteShow = false;
try
{
if (await Api.DeletePersonAsync(Id))
{
Snackbar.Add($"Person \"{_person?.DisplayName}\" deleted", Severity.Success);
Nav.NavigateTo("/persons");
}
else
{
Snackbar.Add("Failed to delete person", Severity.Error);
}
}
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
}
private void ShowSnapshot(EventItem ev)
{
_showSnapshotEvent = ev;
_showSnapshot = true;
}
private static string FormatCategory(string? category) => category switch
{
"family" => "Family",
"employee" => "Employee",
"watchlist" => "Watchlist",
"unknown" => "Unknown",
_ => "—"
};
}