@page "/audit-logs" @attribute [Authorize(Roles = "Admin")] @layout MainLayout @inject HeimdallApiClient Api @inject ISnackbar Snackbar Journal d'audit Filtrer Réinitialiser @if (_loading) { } else { Date Utilisateur Action Type Ressource IP @context.Timestamp.ToString("g") @(context.UserEmail ?? "-") @context.Action @context.ResourceType @context.ResourceId?[..Math.Min(8, context.ResourceId?.Length ?? 0)] @context.IpAddress Aucune entrée d'audit Page @_page sur @_totalPages (@_total entrées) ← Précédent Suivant → } @code { private IReadOnlyList? _logs; private bool _loading = true; private int _page = 1; private int _totalPages = 1; private int _total; private string? _filterResourceType; private string? _filterAction; protected override async Task OnInitializedAsync() => await LoadLogs(); private async Task LoadLogs() { _loading = true; try { var result = await Api.GetAuditLogsAsync(_filterResourceType, _filterAction, _page); if (result is not null) { _logs = result.Items; _total = result.TotalCount; _totalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize)); } } catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); } finally { _loading = false; } } private async Task GoToPage(int p) { _page = p; await LoadLogs(); } private async Task ApplyFilters() { _page = 1; await LoadLogs(); } private async Task ResetFilters() { _filterResourceType = null; _filterAction = null; _page = 1; await LoadLogs(); } private static Color GetActionColor(string action) => action switch { "Site.Created" or "UserCreated" => Color.Success, "UserRolesUpdated" or "UserPasswordReset" => Color.Warning, "UserLocked" => Color.Error, "UserUnlocked" => Color.Info, _ => Color.Default }; }