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

231 lines
9.3 KiB
Plaintext
Raw Normal View History

2026-10-10 17:50:02 +02:00
@page "/persons"
@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
2026-10-10 17:50:02 +02:00
<MudText Typo="Typo.h1" Class="mb-1">
<i class="fas fa-users mr-2"></i>
@Text["PersonsListPage_Title"]
2026-10-10 17:50:02 +02:00
</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
@(_total > 0 ? string.Format(Text["PersonsListPage_CountRegistered"], _total) : Text["PersonsListPage_Description"])
2026-10-10 17:50:02 +02:00
</MudText>
@* ─── Filters ─── *@
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-md);">
<MudGrid>
<MudItem xs="12" sm="6" md="5">
<MudTextField @bind-Value="Search" Label="@Text["PersonsListPage_SearchLabel"]" Variant="Variant.Outlined"
2026-10-10 17:50:02 +02:00
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
Immediate="true" Class="mb-2 mb-md-0" />
</MudItem>
<MudItem xs="12" sm="6" md="4">
<MudSelect T="string" @bind-Value="_statusFilter" Label="@Text["PersonsListPage_Status"]" Variant="Variant.Outlined"
2026-10-10 17:50:02 +02:00
Class="mb-2 mb-md-0">
<MudSelectItem T="string" Value="@("")">@Text["PersonsListPage_All"]</MudSelectItem>
<MudSelectItem T="string" Value="@("known")">@Text["PersonsListPage_Known"]</MudSelectItem>
<MudSelectItem T="string" Value="@("unknown")">@Text["PersonsListPage_Unknown"]</MudSelectItem>
2026-10-10 17:50:02 +02:00
</MudSelect>
</MudItem>
<MudItem xs="12" sm="6" md="3" Class="d-flex align-center">
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ApplyFilters" Class="w-100">
<MudIcon Icon="@Icons.Material.Filled.Search" Class="mr-1" Size="Size.Small" /> @Text["PersonsListPage_Filter"]
2026-10-10 17:50:02 +02:00
</MudButton>
</MudItem>
</MudGrid>
</MudPaper>
@* ─── 4 states ─── *@
@if (_loading)
{
<MudGrid>
@for (int i = 0; i < 4; i++)
{
<MudItem xs="12" sm="6" md="3">
<MudPaper Elevation="0" Style="border-radius: var(--hmd-radius-md);">
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="200px" />
</MudPaper>
</MudItem>
}
</MudGrid>
}
else if (_error)
{
<MudAlert Severity="Severity.Error" Variant="Variant.Filled" Class="mb-4">
<MudText>@Text["PersonsListPage_LoadFailed"]</MudText>
2026-10-10 17:50:02 +02:00
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadPersons" Class="mt-2">
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> @Text["PersonsListPage_Retry"]
2026-10-10 17:50:02 +02:00
</MudButton>
</MudAlert>
}
else if (_Filtered is null || _Filtered.Count == 0)
{
<MudPaper Elevation="0" Class="pa-8 text-center" Style="border-radius: var(--hmd-radius-md); border: 1px dashed var(--mud-palette-lines-default);">
<MudIcon Icon="@Icons.Material.Filled.PersonSearch" Size="Size.Large" Color="Color.Secondary" />
<MudText Typo="Typo.h6" Color="Color.Secondary" Class="mt-4">
@(_persons is null || _persons.Count == 0
? Text["PersonsListPage_EmptyTitle"]
: Text["PersonsListPage_NoMatches"])
2026-10-10 17:50:02 +02:00
</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
@if (_persons is null || _persons.Count == 0)
{
<text>@Text["PersonsListPage_EmptyDescription"]</text>
2026-10-10 17:50:02 +02:00
}
else
{
<text>@Text["PersonsListPage_NoMatchesDescription"]</text>
2026-10-10 17:50:02 +02:00
}
</MudText>
@if (_persons is null || _persons.Count == 0)
{
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showForm = true)">
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["PersonsListPage_AddPerson"]
2026-10-10 17:50:02 +02:00
</MudButton>
}
</MudPaper>
}
else
{
<div class="d-flex justify-space-between align-center mb-4">
<MudText Typo="Typo.body2" Color="Color.Secondary">
@string.Format(Text["PersonsListPage_CountShown"], _Filtered.Count)
2026-10-10 17:50:02 +02:00
</MudText>
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showForm = true)">
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["PersonsListPage_Add"]
2026-10-10 17:50:02 +02:00
</MudButton>
</div>
<MudGrid>
@foreach (var person in _Filtered)
{
<MudItem xs="12" sm="6" md="4" lg="3">
<MudCard Elevation="2" Style="border-radius: var(--hmd-radius-md); cursor: pointer; height: 100%;"
@onclick="@(() => Nav.NavigateTo($"/persons/{person.Id}"))">
<div class="d-flex align-center pa-4 gap-3">
@if (!string.IsNullOrEmpty(person.PhotoUrl))
{
<MudAvatar Image="@person.PhotoUrl" Style="width:48px; height:48px;" />
}
else
{
<MudAvatar Style="width:48px; height:48px; background: var(--mud-palette-primary);">
<i class="fas fa-user"></i>
</MudAvatar>
}
<div class="d-flex flex-column" style="min-width:0;">
<MudText Typo="Typo.h6" Class="text-truncate">@person.DisplayName</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary">
@FormatCategory(person.Category)
</MudText>
</div>
@if (person.IsWatchlisted)
{
<MudSpacer />
<MudChip T="string" Size="Size.Small" Color="Color.Warning"
Icon="@Icons.Material.Filled.Warning">
@Text["PersonsListPage_Watchlisted"]
2026-10-10 17:50:02 +02:00
</MudChip>
}
</div>
<MudCardActions Justify="Justify.FlexEnd" Class="pa-4 pt-0">
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined"
Icon="@Icons.Material.Filled.CollectionsBookmark">
@string.Format(Text["PersonsListPage_FaceCount"], person.FaceCount)
2026-10-10 17:50:02 +02:00
</MudChip>
<MudText Typo="Typo.caption" Color="Color.Secondary">
@string.Format(Text["PersonsListPage_Created"], person.CreatedAt.ToString("d", Language.Culture))
2026-10-10 17:50:02 +02:00
</MudText>
</MudCardActions>
</MudCard>
</MudItem>
}
</MudGrid>
}
@* ─── Create form ─── *@
<PersonFormDialog @bind-Visible="_showForm" Existing="null" OnSaved="@OnPersonCreated" />
@code {
private List<PersonClientItem>? _persons;
private List<PersonClientItem>? _Filtered;
private bool _loading = true;
private bool _error;
private bool _showForm;
private string _search = "";
private string _statusFilter = "";
private int _total = 0;
private string Search
{
get => _search;
set
{
_search = value;
ApplyFilters();
}
}
protected override async Task OnInitializedAsync()
{
Language.LanguageChanged += OnLanguageChanged;
await LoadPersons();
}
2026-10-10 17:50:02 +02:00
private async Task LoadPersons()
{
_loading = true;
_error = false;
try
{
_persons = await Api.GetPersonsAsync();
_total = _persons?.Count ?? 0;
ApplyFilters();
}
catch { _error = true; Snackbar.Add(Text["PersonsListPage_LoadFailed"], Severity.Error); }
2026-10-10 17:50:02 +02:00
finally { _loading = false; }
}
private void ApplyFilters()
{
if (_persons is null) { _Filtered = null; return; }
var q = _search?.Trim();
_Filtered = _persons
.Where(p => string.IsNullOrEmpty(q)
|| p.DisplayName.Contains(q, StringComparison.OrdinalIgnoreCase))
.Where(p => string.IsNullOrEmpty(_statusFilter)
|| (_statusFilter == "known" && p.Category != "unknown")
|| (_statusFilter == "unknown" && p.Category == "unknown"))
.OrderBy(p => p.DisplayName)
.ToList();
}
private async Task OnPersonCreated(PersonClientItem person)
{
_persons ??= [];
_persons.Insert(0, person);
ApplyFilters();
_total = _persons.Count;
Nav.NavigateTo($"/persons/{person.Id}");
}
private string FormatCategory(string? category) => category switch
2026-10-10 17:50:02 +02:00
{
"family" => Text["PersonsListPage_Family"],
"employee" => Text["PersonsListPage_Employee"],
"watchlist" => Text["PersonsListPage_Watchlist"],
"unknown" => Text["PersonsListPage_Unknown"],
2026-10-10 17:50:02 +02:00
_ => "—"
};
private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged);
public void Dispose() => Language.LanguageChanged -= OnLanguageChanged;
}