Files
Heimdall/src/Heimdall.Web/Components/Pages/PersonDetailPage.razor
T

418 lines
18 KiB
Plaintext
Raw Normal View History

@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
@inject UiLanguageService Language
@inject UiText Text
@implements IDisposable
@if (_loading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_person is null)
{
<MudAlert Severity="Severity.Warning">@Text["PersonDetailPage_NotFound"]</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) · @string.Format(Text["PersonDetailPage_Created"], _person.CreatedAt.ToString("d", Language.Culture))
</MudText>
@if (_person.IsWatchlisted)
{
<MudChip T="string" Size="Size.Small" Color="Color.Warning"
Icon="@Icons.Material.Filled.Warning" Class="mt-2">
@Text["PersonDetailPage_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" /> @Text["PersonDetailPage_Edit"]
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="@ConfirmDelete">
<MudIcon Icon="@Icons.Material.Filled.Delete" Class="mr-1" /> @Text["PersonDetailPage_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">@Text["PersonDetailPage_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" />
@string.Format(Text["PersonDetailPage_RegisteredFaces"], _faces.Count)
</MudText>
</div>
@if (_facesLoading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_faces.Count == 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
@Text["PersonDetailPage_NoFaces"]
</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="@Text["PersonDetailPage_FaceAlt"]"
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>@Text["PersonDetailPage_Event"]: @face.SourceEventId.Substring(0, Math.Min(8, face.SourceEventId.Length))…</text>
}
else
{
<text>@Text["PersonDetailPage_FaceNumber"] #@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" />
@string.Format(Text["PersonDetailPage_AssociatedVehicles"], _vehicles.Count)
</MudText>
@if (_vehiclesLoading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_vehicles.Count == 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
@Text["PersonDetailPage_NoVehicles"]
</MudAlert>
}
else
{
<MudTable Items="@_vehicles" Dense="true" Hover="true">
<HeaderContent>
<MudTh>@Text["PersonDetailPage_Plate"]</MudTh>
<MudTh>@Text["PersonDetailPage_Make"]</MudTh>
<MudTh>@Text["PersonDetailPage_Model"]</MudTh>
<MudTh>@Text["PersonDetailPage_Color"]</MudTh>
<MudTh>@Text["PersonDetailPage_Events"]</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="@Text["PersonDetailPage_Plate"]"><code>@context.LicensePlate</code></MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_Make"]">@context.Make</MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_Model"]">@context.Model</MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_Color"]">@context.Color</MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_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" />
@Text["PersonDetailPage_DetectionHistory"]
</MudText>
@if (_eventsLoading)
{
<MudProgressCircular Indeterminate="true" />
}
else if (_events.Count == 0)
{
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
@Text["PersonDetailPage_NoRecentDetections"]
</MudAlert>
}
else
{
<MudTable Items="@_events" Dense="true" Hover="true">
<HeaderContent>
<MudTh>@Text["PersonDetailPage_Date"]</MudTh>
<MudTh>@Text["PersonDetailPage_Type"]</MudTh>
<MudTh>@Text["PersonDetailPage_Camera"]</MudTh>
<MudTh>@Text["PersonDetailPage_Confidence"]</MudTh>
<MudTh>@Text["PersonDetailPage_Snapshot"]</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="@Text["PersonDetailPage_Date"]">@context.OccurredAt.ToLocalTime().ToString("g", Language.Culture)</MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_Type"]">
<MudChip T="string" Size="Size.Small" Color="Color.Success" Variant="Variant.Filled">
@Text["PersonDetailPage_Face"]
</MudChip>
</MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_Camera"]">@context.Label</MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_Confidence"]">@context.Confidence.ToString("P0", Language.Culture)</MudTd>
<MudTd DataLabel="@Text["PersonDetailPage_Snapshot"]">
@if (!string.IsNullOrEmpty(context.SnapshotUrl))
{
<MudIconButton Icon="@Icons.Material.Filled.Image" Size="Size.Small"
aria-label="@Text["PersonDetailPage_ViewSnapshot"]" OnClick="@(() => ShowSnapshot(context))" />
}
</MudTd>
</RowTemplate>
</MudTable>
@if (_events.Count < _eventsTotalCount)
{
<MudButton Variant="Variant.Text" Color="Color.Primary" Class="mt-2"
Disabled="@_eventsLoading" OnClick="@LoadMoreEvents">
@string.Format(Text["PersonDetailPage_LoadMore"], _events.Count, _eventsTotalCount)
</MudButton>
}
}
</MudPaper>
<MudButton Variant="Variant.Outlined" Color="Color.Default" Class="mt-4"
OnClick="@(() => Nav.NavigateTo("/persons"))">
← @Text["PersonDetailPage_BackToPersons"]
</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">@Text["PersonDetailPage_ConfirmDelete"]</MudText></TitleContent>
<DialogContent>
<MudText>@string.Format(Text["PersonDetailPage_DeletePrompt"], _person?.DisplayName)</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2">
@string.Format(Text["PersonDetailPage_DeleteWarning"], _person?.FaceCount)
</MudText>
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">@Text["PersonDetailPage_Cancel"]</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@ExecuteDelete">@Text["PersonDetailPage_Delete"]</MudButton>
</DialogActions>
</MudDialog>
@* ─── Snapshot dialog ─── *@
<MudDialog @bind-Visible="_showSnapshot" Options="_dialogOptions">
<TitleContent>
<MudText Typo="Typo.h6">@Text["PersonDetailPage_SnapshotTitle"] — @_showSnapshotEvent?.Label</MudText>
</TitleContent>
<DialogContent>
<img src="@_showSnapshotEvent?.SnapshotUrl" alt="@Text["PersonDetailPage_SnapshotAlt"]" style="width:100%" class="rounded-lg" />
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Text" OnClick="@(() => _showSnapshot = false)">@Text["PersonDetailPage_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 int _eventsTotalCount;
private int _eventsPage = 1;
private const int EventsPageSize = 50;
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()
{
Language.LanguageChanged += OnLanguageChanged;
try
{
_person = await Api.GetPersonAsync(Id);
}
catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
{
// La vue dédiée affiche l'état introuvable sans lancer les lectures associées.
}
catch { Snackbar.Add(Text["PersonDetailPage_OperationFailed"], Severity.Error); }
finally { _loading = false; }
if (_person is not null)
{
await LoadFaces();
await LoadVehicles();
await LoadEvents();
}
}
private async Task LoadFaces()
{
_facesLoading = true;
try
{
_faces = (await Api.GetFacesAsync(Id)) ?? [];
}
catch { Snackbar.Add(Text["PersonDetailPage_OperationFailed"], Severity.Error); }
finally { _facesLoading = false; }
}
private async Task LoadVehicles()
{
_vehiclesLoading = true;
try
{
_vehicles = await Api.GetVehiclesAsync(Id) ?? [];
}
catch { Snackbar.Add(Text["PersonDetailPage_OperationFailed"], Severity.Error); }
finally { _vehiclesLoading = false; }
}
private async Task LoadEvents(bool append = false)
{
_eventsLoading = true;
try
{
if (!append)
{
_eventsPage = 1;
_events = [];
}
var result = await Api.GetEventsAsync(null, null, page: _eventsPage, pageSize: EventsPageSize,
type: "FaceRecognized", from: _eventsSince, personId: Id);
if (result is not null)
{
_eventsTotalCount = result.TotalCount;
_events.AddRange(result.Items);
_eventsPage++;
}
}
catch { Snackbar.Add(Text["PersonDetailPage_OperationFailed"], Severity.Error); }
finally { _eventsLoading = false; }
}
private Task LoadMoreEvents() => LoadEvents(append: true);
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(string.Format(Text["PersonDetailPage_DeleteSuccess"], _person?.DisplayName), Severity.Success);
Nav.NavigateTo("/persons");
}
else
{
Snackbar.Add(Text["PersonDetailPage_DeleteFailed"], Severity.Error);
}
}
catch { Snackbar.Add(Text["PersonDetailPage_OperationFailed"], Severity.Error); }
}
private void ShowSnapshot(EventItem ev)
{
_showSnapshotEvent = ev;
_showSnapshot = true;
}
private string FormatCategory(string? category) => category switch
{
"family" => Text["PersonDetailPage_Family"],
"employee" => Text["PersonDetailPage_Employee"],
"watchlist" => Text["PersonDetailPage_Watchlist"],
"unknown" => Text["PersonDetailPage_Unknown"],
_ => "—"
};
private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged);
public void Dispose() => Language.LanguageChanged -= OnLanguageChanged;
}