feat(mvp): complete MVP hardening — API, Web, config system, SignalR, tests
This commit is contained in:
1 parent
3fc42be4b2
commit
c2837af089
59 files changed
+4920
-81
No files matched your search
@@ -54,6 +54,9 @@
|
||||
<MudNavLink Href="/audit-logs" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.History" /> Journal d'audit
|
||||
</MudNavLink>
|
||||
<MudNavLink Href="/settings" Match="NavLinkMatch.Prefix">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Settings" /> Configuration
|
||||
</MudNavLink>
|
||||
}
|
||||
|
||||
<MudDivider Class="my-4" />
|
||||
@@ -77,9 +80,9 @@
|
||||
@code {
|
||||
private bool _drawerOpen = true;
|
||||
|
||||
private void Logout()
|
||||
private async Task Logout()
|
||||
{
|
||||
AuthStateProvider.NotifyLogout();
|
||||
await AuthStateProvider.NotifyLogoutAsync();
|
||||
Navigation.NavigateTo("/login", true);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,15 @@
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_error)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
||||
<MudText>Erreur lors du chargement des agents.</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadAgents" Class="mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
||||
</MudButton>
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@_agents" Hover="true" Striped="true" Elevation="2">
|
||||
@@ -58,15 +67,24 @@ else
|
||||
|
||||
private IReadOnlyList<AgentItem>? _agents;
|
||||
private bool _loading = true;
|
||||
private bool _error;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
protected override async Task OnInitializedAsync() => await LoadAgents();
|
||||
|
||||
private async Task LoadAgents()
|
||||
{
|
||||
_loading = true;
|
||||
_error = false;
|
||||
try
|
||||
{
|
||||
var result = await Api.GetAgentsBySiteAsync(SiteId);
|
||||
_agents = result?.Items;
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_error = true;
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,15 @@
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_error)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
||||
<MudText>Erreur lors du chargement du journal d'audit.</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadLogs" Class="mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
||||
</MudButton>
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@_logs" Hover="true" Striped="true" Elevation="2" Dense="true">
|
||||
@@ -77,6 +86,7 @@ else
|
||||
@code {
|
||||
private IReadOnlyList<AuditLogItem>? _logs;
|
||||
private bool _loading = true;
|
||||
private bool _error;
|
||||
private int _page = 1;
|
||||
private int _totalPages = 1;
|
||||
private int _total;
|
||||
@@ -88,6 +98,7 @@ else
|
||||
private async Task LoadLogs()
|
||||
{
|
||||
_loading = true;
|
||||
_error = false;
|
||||
try
|
||||
{
|
||||
var result = await Api.GetAuditLogsAsync(_filterResourceType, _filterAction, _page);
|
||||
@@ -98,7 +109,11 @@ else
|
||||
_totalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize));
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_error = true;
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,15 @@
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_error)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
||||
<MudText>Erreur lors du chargement des caméras.</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadCameras" Class="mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
||||
</MudButton>
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@_cameras" Hover="true" Striped="true" Elevation="2">
|
||||
@@ -49,7 +58,7 @@ else
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Actions">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
||||
OnClick="@(() => DeleteCamera(context.Id, context.Name))" />
|
||||
OnClick="@(() => ConfirmDeleteCamera(context.Id, context.Name))" />
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
@@ -58,6 +67,22 @@ else
|
||||
</MudTable>
|
||||
}
|
||||
|
||||
@* ─── Confirm delete dialog ───────────────────────────────── *@
|
||||
@if (_confirmDeleteShow)
|
||||
{
|
||||
<MudOverlay Visible="@_confirmDeleteShow" OnClick="@(() => _confirmDeleteShow = false)" />
|
||||
<MudDialog @bind-Visible="_confirmDeleteShow">
|
||||
<TitleContent><MudText Typo="Typo.h6">Confirmer la suppression</MudText></TitleContent>
|
||||
<DialogContent>
|
||||
<MudText>Supprimer la caméra "@_confirmDeleteName" ? Cette action est irréversible.</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">Annuler</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@ExecuteDeleteCamera">Supprimer</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@if (_showCreate)
|
||||
{
|
||||
<MudOverlay Visible="@_showCreate" OnClick="@(() => _showCreate = false)" />
|
||||
@@ -70,9 +95,9 @@ else
|
||||
<MudTextField @bind-Value="_newModel" Label="Modèle" Variant="Variant.Outlined" Class="mb-4" />
|
||||
<MudTextField @bind-Value="_newRtspUrl" Label="URL RTSP" Variant="Variant.Outlined" Class="mb-4"
|
||||
HelperText="Ex: rtsp://192.168.1.100:554/stream1" />
|
||||
@if (!string.IsNullOrEmpty(_error))
|
||||
@if (!string.IsNullOrEmpty(_dialogError))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@_error</MudAlert>
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@_dialogError</MudAlert>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
@@ -90,9 +115,10 @@ else
|
||||
|
||||
private IReadOnlyList<CameraItem>? _cameras;
|
||||
private bool _loading = true;
|
||||
private bool _error;
|
||||
private bool _showCreate;
|
||||
private bool _saving;
|
||||
private string _error = "";
|
||||
private string _dialogError = "";
|
||||
|
||||
private string _newName = "";
|
||||
private string? _newManufacturer;
|
||||
@@ -104,30 +130,52 @@ else
|
||||
private async Task LoadCameras()
|
||||
{
|
||||
_loading = true;
|
||||
_error = false;
|
||||
try
|
||||
{
|
||||
var result = await Api.GetCamerasBySiteAsync(SiteId);
|
||||
_cameras = result?.Items;
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_error = true;
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
private bool _confirmDeleteShow;
|
||||
private Guid _confirmDeleteId;
|
||||
private string _confirmDeleteName = "";
|
||||
|
||||
private void ConfirmDeleteCamera(Guid id, string name)
|
||||
{
|
||||
_confirmDeleteId = id;
|
||||
_confirmDeleteName = name;
|
||||
_confirmDeleteShow = true;
|
||||
}
|
||||
|
||||
private async Task ExecuteDeleteCamera()
|
||||
{
|
||||
_confirmDeleteShow = false;
|
||||
await DeleteCamera(_confirmDeleteId, _confirmDeleteName);
|
||||
}
|
||||
|
||||
private async Task CreateCamera()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_newName)) { _error = "Le nom est requis"; return; }
|
||||
if (string.IsNullOrWhiteSpace(_newName)) { _dialogError = "Le nom est requis"; return; }
|
||||
_saving = true;
|
||||
_error = "";
|
||||
_dialogError = "";
|
||||
try
|
||||
{
|
||||
var result = await Api.CreateCameraAsync(SiteId, _newName, _newRtspUrl, _newManufacturer, _newModel);
|
||||
if (result is null) { _error = "Erreur lors de la création"; return; }
|
||||
if (result is null) { _dialogError = "Erreur lors de la création"; return; }
|
||||
_showCreate = false;
|
||||
ResetForm();
|
||||
Snackbar.Add("Caméra ajoutée", Severity.Success);
|
||||
await LoadCameras();
|
||||
}
|
||||
catch (Exception ex) { _error = $"Erreur : {ex.Message}"; }
|
||||
catch (Exception ex) { _dialogError = $"Erreur : {ex.Message}"; }
|
||||
finally { _saving = false; }
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,15 @@
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_error)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Variant="Variant.Filled">
|
||||
<MudText>Erreur lors du chargement du tableau de bord.</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@(() => { _ = OnInitializedAsync(); })" Class="mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
||||
</MudButton>
|
||||
</MudAlert>
|
||||
}
|
||||
else if (_sites?.Count > 0)
|
||||
{
|
||||
<MudTable Items="@_sites" Hover="true" Striped="true" Elevation="1">
|
||||
@@ -85,9 +94,12 @@
|
||||
private int _activeSites;
|
||||
private IReadOnlyList<SiteItem>? _sites;
|
||||
private bool _loading = true;
|
||||
private bool _error;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_loading = true;
|
||||
_error = false;
|
||||
try
|
||||
{
|
||||
// Load stats + sites in parallel (2 API calls instead of N*2+1)
|
||||
@@ -109,6 +121,7 @@
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_error = true;
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _loading = false; }
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
_errorMessage = "Email ou mot de passe invalide";
|
||||
return;
|
||||
}
|
||||
AuthStateProvider.NotifyLogin(result);
|
||||
await AuthStateProvider.NotifyLoginAsync(result);
|
||||
Snackbar.Add("Connexion réussie", Severity.Success);
|
||||
Navigation.NavigateTo(_returnUrl);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
_errorMessage = "Erreur lors de l'inscription";
|
||||
return;
|
||||
}
|
||||
AuthStateProvider.NotifyLogin(result);
|
||||
await AuthStateProvider.NotifyLoginAsync(result);
|
||||
Snackbar.Add("Compte créé avec succès", Severity.Success);
|
||||
Navigation.NavigateTo("/dashboard");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,496 @@
|
||||
@page "/settings"
|
||||
@attribute [Authorize(Roles = "Admin")]
|
||||
@layout MainLayout
|
||||
@inject HeimdallApiClient Api
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-6">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Settings" Class="mr-2" />
|
||||
Configuration
|
||||
</MudText>
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)" Class="mb-4 mr-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Nouveau paramètre
|
||||
</MudButton>
|
||||
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Info" OnClick="@ReloadAllConfig" Class="mb-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" /> Recharger tous les agents
|
||||
</MudButton>
|
||||
|
||||
@if (_loading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_error)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
||||
<MudText>Erreur lors du chargement de la configuration.</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadSettings" Class="mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
||||
</MudButton>
|
||||
</MudAlert>
|
||||
}
|
||||
else if (_settings is null || _settings.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
||||
<MudText>Aucun paramètre de configuration trouvé.</MudText>
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var category in _groupedSettings)
|
||||
{
|
||||
<MudText Typo="Typo.subtitle1" Class="mb-2 mt-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Folder" Size="Size.Small" Class="mr-1" />
|
||||
@category.Key
|
||||
</MudText>
|
||||
|
||||
<MudTable Items="@category.Value" Hover="true" Striped="true" Elevation="2" Class="mb-4">
|
||||
<HeaderContent>
|
||||
<MudTh>Clé</MudTh>
|
||||
<MudTh>Valeur</MudTh>
|
||||
<MudTh>Type</MudTh>
|
||||
<MudTh>Description</MudTh>
|
||||
<MudTh>Mis à jour</MudTh>
|
||||
<MudTh>Actions</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Clé">
|
||||
<MudText Typo="Typo.body2" Class="font-weight-bold">@context.Key</MudText>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Valeur">
|
||||
@switch (context.ValueType.ToLowerInvariant())
|
||||
{
|
||||
case "boolean":
|
||||
case "bool":
|
||||
<MudSwitch T="bool" @bind-Checked="_switches[context.Key]"
|
||||
Disabled="true" />
|
||||
break;
|
||||
case "number":
|
||||
case "int":
|
||||
case "integer":
|
||||
<MudText Typo="Typo.body2">@context.Value</MudText>
|
||||
break;
|
||||
case "select":
|
||||
case "dropdown":
|
||||
<MudText Typo="Typo.body2" Color="Color.Primary">@context.Value</MudText>
|
||||
break;
|
||||
default:
|
||||
<MudText Typo="Typo.body2" Style="max-width:300px;word-break:break-all;">@context.Value</MudText>
|
||||
break;
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Type">
|
||||
<MudText Typo="Typo.body2" Class="mud-chip mud-chip-text mud-chip-size-small"
|
||||
Style="@($"background:{GetTypeColor(context.ValueType)};color:#fff;padding:2px 8px;border-radius:12px;display:inline-block;")">
|
||||
@context.ValueType
|
||||
</MudText>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Description">
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">
|
||||
@(context.Description ?? "—")
|
||||
</MudText>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Mis à jour">
|
||||
<MudText Typo="Typo.body2">@context.UpdatedAt.ToString("g")</MudText>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Actions">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small"
|
||||
OnClick="@(() => OpenEdit(context))" Class="mr-1" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small"
|
||||
Color="Color.Error" OnClick="@(() => ConfirmDelete(context))" />
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
<MudText Align="Align.Center" Class="py-4">Aucun paramètre dans cette catégorie</MudText>
|
||||
</NoRecordsContent>
|
||||
</MudTable>
|
||||
}
|
||||
}
|
||||
|
||||
@* ─── Dialog: Créer un paramètre ──────────────────────────────────── *@
|
||||
|
||||
@if (_showCreate)
|
||||
{
|
||||
<MudOverlay Visible="@_showCreate" OnClick="@(() => _showCreate = false)" />
|
||||
<MudDialog @bind-Visible="_showCreate">
|
||||
<TitleContent><MudText Typo="Typo.h6">Nouveau paramètre</MudText></TitleContent>
|
||||
<DialogContent>
|
||||
<MudTextField @bind-Value="_createKey" Label="Clé *" Variant="Variant.Outlined"
|
||||
Class="mb-4" Required="true" Immediate="true" />
|
||||
<MudTextField @bind-Value="_createValue" Label="Valeur *" Variant="Variant.Outlined"
|
||||
Class="mb-4" Required="true" Immediate="true" />
|
||||
<MudTextField @bind-Value="_createDescription" Label="Description" Variant="Variant.Outlined"
|
||||
Class="mb-4" Immediate="true" />
|
||||
<MudTextField @bind-Value="_createCategory" Label="Catégorie" Variant="Variant.Outlined"
|
||||
Class="mb-4" Immediate="true" HelperText="Ex: General, Detection, Recording..." />
|
||||
<MudText Typo="Typo.body2" Class="mb-2">Type de valeur</MudText>
|
||||
<MudSelect @bind-Value="_createValueType" Label="Type" Variant="Variant.Outlined" Class="mb-4">
|
||||
<MudSelectItem Value="@("string")">string</MudSelectItem>
|
||||
<MudSelectItem Value="@("boolean")">boolean</MudSelectItem>
|
||||
<MudSelectItem Value="@("number")">number</MudSelectItem>
|
||||
<MudSelectItem Value="@("select")">select</MudSelectItem>
|
||||
</MudSelect>
|
||||
|
||||
@if (_createValueType == "select")
|
||||
{
|
||||
<MudTextField @bind-Value="_createAllowedValues" Label="Valeurs autorisées (séparées par des virgules)"
|
||||
Variant="Variant.Outlined" Class="mb-4" Immediate="true"
|
||||
HelperText="Ex: valeur1,valeur2,valeur3" />
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(_createError))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@_createError</MudAlert>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _showCreate = false)">Annuler</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@CreateSetting" Disabled="@_saving">
|
||||
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
||||
Créer
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Dialog: Modifier un paramètre ───────────────────────────────── *@
|
||||
|
||||
@if (_editSetting is not null && _showEdit)
|
||||
{
|
||||
<MudOverlay Visible="@_showEdit" OnClick="@(() => _showEdit = false)" />
|
||||
<MudDialog @bind-Visible="_showEdit">
|
||||
<TitleContent><MudText Typo="Typo.h6">Paramètre : @_editSetting.Key</MudText></TitleContent>
|
||||
<DialogContent>
|
||||
@if (_editSetting.ValueType.ToLowerInvariant() is "boolean" or "bool")
|
||||
{
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">Valeur</MudText>
|
||||
<MudSwitch T="bool" @bind-Checked="_editBoolValue" Color="Color.Primary" />
|
||||
}
|
||||
else if (_editSetting.ValueType.ToLowerInvariant() is "number" or "int" or "integer")
|
||||
{
|
||||
<MudTextField @bind-Value="_editStringValue" Label="Valeur *" Variant="Variant.Outlined"
|
||||
InputType="InputType.Number" Class="mb-4" Required="true" Immediate="true" />
|
||||
}
|
||||
else if (_editSetting.ValueType.ToLowerInvariant() is "select" or "dropdown"
|
||||
&& !string.IsNullOrEmpty(_editSetting.AllowedValues))
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mb-2">Valeur</MudText>
|
||||
<MudSelect @bind-Value="_editStringValue" Label="Valeur" Variant="Variant.Outlined" Class="mb-4">
|
||||
@foreach (var opt in _editAllowedOptions)
|
||||
{
|
||||
<MudSelectItem Value="@opt">@opt</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTextField @bind-Value="_editStringValue" Label="Valeur *" Variant="Variant.Outlined"
|
||||
Class="mb-4" Required="true" Immediate="true" />
|
||||
}
|
||||
|
||||
<MudTextField @bind-Value="_editDescription" Label="Description" Variant="Variant.Outlined"
|
||||
Class="mb-4" Immediate="true" />
|
||||
<MudTextField @bind-Value="_editCategory" Label="Catégorie" Variant="Variant.Outlined"
|
||||
Class="mb-4" Immediate="true" />
|
||||
<MudText Typo="Typo.body2" Class="mb-2">Type de valeur</MudText>
|
||||
<MudSelect @bind-Value="_editValueType" Label="Type" Variant="Variant.Outlined" Class="mb-4">
|
||||
<MudSelectItem Value="@("string")">string</MudSelectItem>
|
||||
<MudSelectItem Value="@("boolean")">boolean</MudSelectItem>
|
||||
<MudSelectItem Value="@("number")">number</MudSelectItem>
|
||||
<MudSelectItem Value="@("select")">select</MudSelectItem>
|
||||
</MudSelect>
|
||||
|
||||
@if (_editValueType == "select")
|
||||
{
|
||||
<MudTextField @bind-Value="_editAllowedValues" Label="Valeurs autorisées (séparées par des virgules)"
|
||||
Variant="Variant.Outlined" Class="mb-4" Immediate="true"
|
||||
HelperText="Ex: valeur1,valeur2,valeur3" />
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(_editError))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@_editError</MudAlert>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@CloseEdit">Annuler</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@SaveEdit" Disabled="@_saving">
|
||||
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
||||
Enregistrer
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Dialog: Confirmer la suppression ────────────────────────────── *@
|
||||
|
||||
@if (_deleteTarget is not null && _showDeleteConfirm)
|
||||
{
|
||||
<MudOverlay Visible="@_showDeleteConfirm" OnClick="@(() => _showDeleteConfirm = false)" />
|
||||
<MudDialog @bind-Visible="_showDeleteConfirm">
|
||||
<TitleContent><MudText Typo="Typo.h6">Confirmer la suppression</MudText></TitleContent>
|
||||
<DialogContent>
|
||||
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
||||
Êtes-vous sûr de vouloir supprimer le paramètre <strong>@_deleteTarget.Key</strong> ?
|
||||
</MudAlert>
|
||||
@if (!string.IsNullOrEmpty(_deleteTarget.Description))
|
||||
{
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">@_deleteTarget.Description</MudText>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(_deleteError))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mt-2">@_deleteError</MudAlert>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _showDeleteConfirm = false)">Annuler</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@DeleteSetting" Disabled="@_saving">
|
||||
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
||||
Supprimer
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<AppSettingItem>? _settings;
|
||||
private Dictionary<string, List<AppSettingItem>> _groupedSettings = new();
|
||||
private bool _loading = true;
|
||||
private bool _error;
|
||||
private bool _saving;
|
||||
|
||||
// Edit state
|
||||
private AppSettingItem? _editSetting;
|
||||
private bool _showEdit;
|
||||
private string _editStringValue = "";
|
||||
private bool _editBoolValue;
|
||||
private string _editDescription = "";
|
||||
private string _editCategory = "";
|
||||
private string _editValueType = "";
|
||||
private string _editAllowedValues = "";
|
||||
private string[] _editAllowedOptions = [];
|
||||
private string _editError = "";
|
||||
|
||||
// Create state
|
||||
private bool _showCreate;
|
||||
private string _createKey = "";
|
||||
private string _createValue = "";
|
||||
private string _createDescription = "";
|
||||
private string _createCategory = "General";
|
||||
private string _createValueType = "string";
|
||||
private string _createAllowedValues = "";
|
||||
private string _createError = "";
|
||||
|
||||
// Delete state
|
||||
private AppSettingItem? _deleteTarget;
|
||||
private bool _showDeleteConfirm;
|
||||
private string _deleteError = "";
|
||||
|
||||
// Track switch states for display
|
||||
private Dictionary<string, bool> _switches = new();
|
||||
|
||||
protected override async Task OnInitializedAsync() => await LoadSettings();
|
||||
|
||||
private async Task LoadSettings()
|
||||
{
|
||||
_loading = true;
|
||||
_error = false;
|
||||
try
|
||||
{
|
||||
_settings = await Api.GetSettingsAsync();
|
||||
_switches.Clear();
|
||||
foreach (var s in _settings)
|
||||
{
|
||||
if (s.ValueType.ToLowerInvariant() is "boolean" or "bool")
|
||||
_switches[s.Key] = bool.TryParse(s.Value, out var b) && b;
|
||||
}
|
||||
_groupedSettings = _settings
|
||||
.GroupBy(s => string.IsNullOrEmpty(s.Category) ? "General" : s.Category)
|
||||
.OrderBy(g => g.Key)
|
||||
.ToDictionary(g => g.Key, g => g.ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_error = true;
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
private string GetTypeColor(string valueType)
|
||||
{
|
||||
return valueType.ToLowerInvariant() switch
|
||||
{
|
||||
"boolean" or "bool" => "#4caf50",
|
||||
"number" or "int" or "integer" => "#2196f3",
|
||||
"select" or "dropdown" => "#ff9800",
|
||||
_ => "#607d8b"
|
||||
};
|
||||
}
|
||||
|
||||
private Color GetTypeChipColor(string valueType)
|
||||
{
|
||||
return valueType.ToLowerInvariant() switch
|
||||
{
|
||||
"boolean" or "bool" => Color.Success,
|
||||
"number" or "int" or "integer" => Color.Info,
|
||||
"select" or "dropdown" => Color.Warning,
|
||||
_ => Color.Default
|
||||
};
|
||||
}
|
||||
|
||||
// ─── Create ───────────────────────────────────────────────────────
|
||||
|
||||
private async Task CreateSetting()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_createKey) || string.IsNullOrWhiteSpace(_createValue))
|
||||
{ _createError = "Les champs Clé et Valeur sont requis"; return; }
|
||||
_saving = true;
|
||||
_createError = "";
|
||||
try
|
||||
{
|
||||
var allowedValues = _createValueType == "select" && !string.IsNullOrWhiteSpace(_createAllowedValues)
|
||||
? _createAllowedValues
|
||||
: null;
|
||||
|
||||
var result = await Api.CreateSettingAsync(new CreateAppSettingRequest(
|
||||
_createKey.Trim(),
|
||||
_createValue.Trim(),
|
||||
string.IsNullOrWhiteSpace(_createCategory) ? "General" : _createCategory.Trim(),
|
||||
string.IsNullOrWhiteSpace(_createDescription) ? null : _createDescription.Trim(),
|
||||
_createValueType,
|
||||
allowedValues
|
||||
));
|
||||
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
var body = await result.Content.ReadAsStringAsync();
|
||||
_createError = $"Erreur : {result.StatusCode} — {body}";
|
||||
return;
|
||||
}
|
||||
|
||||
_showCreate = false;
|
||||
_createKey = ""; _createValue = ""; _createDescription = "";
|
||||
_createCategory = "General"; _createValueType = "string"; _createAllowedValues = "";
|
||||
Snackbar.Add("Paramètre créé avec succès", Severity.Success);
|
||||
await LoadSettings();
|
||||
}
|
||||
catch (Exception ex) { _createError = $"Erreur : {ex.Message}"; }
|
||||
finally { _saving = false; }
|
||||
}
|
||||
|
||||
// ─── Edit ─────────────────────────────────────────────────────────
|
||||
|
||||
private void OpenEdit(AppSettingItem setting)
|
||||
{
|
||||
_editSetting = setting;
|
||||
_editStringValue = setting.Value;
|
||||
_editBoolValue = bool.TryParse(setting.Value, out var b) && b;
|
||||
_editDescription = setting.Description ?? "";
|
||||
_editCategory = setting.Category;
|
||||
_editValueType = setting.ValueType;
|
||||
_editAllowedValues = setting.AllowedValues ?? "";
|
||||
_editAllowedOptions = (setting.AllowedValues ?? "")
|
||||
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
_editError = "";
|
||||
_showEdit = true;
|
||||
}
|
||||
|
||||
private void CloseEdit()
|
||||
{
|
||||
_showEdit = false;
|
||||
_editSetting = null;
|
||||
}
|
||||
|
||||
private async Task SaveEdit()
|
||||
{
|
||||
if (_editSetting is null) return;
|
||||
_saving = true;
|
||||
_editError = "";
|
||||
try
|
||||
{
|
||||
var newValue = _editSetting.ValueType.ToLowerInvariant() is "boolean" or "bool"
|
||||
? _editBoolValue.ToString().ToLowerInvariant()
|
||||
: _editStringValue.Trim();
|
||||
|
||||
var allowedValues = _editValueType == "select" && !string.IsNullOrWhiteSpace(_editAllowedValues)
|
||||
? _editAllowedValues
|
||||
: null;
|
||||
|
||||
var result = await Api.UpdateSettingAsync(_editSetting.Key, new UpdateAppSettingRequest(
|
||||
newValue,
|
||||
string.IsNullOrWhiteSpace(_editDescription) ? null : _editDescription.Trim(),
|
||||
string.IsNullOrWhiteSpace(_editCategory) ? null : _editCategory.Trim(),
|
||||
_editValueType,
|
||||
allowedValues
|
||||
));
|
||||
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
var body = await result.Content.ReadAsStringAsync();
|
||||
_editError = $"Erreur : {result.StatusCode} — {body}";
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("Paramètre mis à jour", Severity.Success);
|
||||
CloseEdit();
|
||||
await LoadSettings();
|
||||
}
|
||||
catch (Exception ex) { _editError = $"Erreur : {ex.Message}"; }
|
||||
finally { _saving = false; }
|
||||
}
|
||||
|
||||
// ─── Delete ───────────────────────────────────────────────────────
|
||||
|
||||
private void ConfirmDelete(AppSettingItem setting)
|
||||
{
|
||||
_deleteTarget = setting;
|
||||
_deleteError = "";
|
||||
_showDeleteConfirm = true;
|
||||
}
|
||||
|
||||
private async Task DeleteSetting()
|
||||
{
|
||||
if (_deleteTarget is null) return;
|
||||
_saving = true;
|
||||
_deleteError = "";
|
||||
try
|
||||
{
|
||||
var result = await Api.DeleteSettingAsync(_deleteTarget.Key);
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
var body = await result.Content.ReadAsStringAsync();
|
||||
_deleteError = $"Erreur : {result.StatusCode} — {body}";
|
||||
return;
|
||||
}
|
||||
|
||||
_showDeleteConfirm = false;
|
||||
Snackbar.Add("Paramètre supprimé", Severity.Success);
|
||||
_deleteTarget = null;
|
||||
await LoadSettings();
|
||||
}
|
||||
catch (Exception ex) { _deleteError = $"Erreur : {ex.Message}"; }
|
||||
finally { _saving = false; }
|
||||
}
|
||||
|
||||
// ─── Reload ───────────────────────────────────────────────────────
|
||||
|
||||
private async Task ReloadAllConfig()
|
||||
{
|
||||
_saving = true;
|
||||
try
|
||||
{
|
||||
var result = await Api.ReloadAllConfigAsync();
|
||||
if (result.IsSuccessStatusCode)
|
||||
Snackbar.Add("Configuration rechargée sur tous les agents", Severity.Success);
|
||||
else
|
||||
Snackbar.Add($"Erreur lors du rechargement : {result.StatusCode}", Severity.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _saving = false; }
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,15 @@
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_error)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
||||
<MudText>Erreur lors du chargement des sites.</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadSites" Class="mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
||||
</MudButton>
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@_sites" Hover="true" Striped="true" Elevation="2">
|
||||
@@ -40,7 +49,7 @@ else
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Size="Size.Small"
|
||||
OnClick="@(() => CopyToken(context.Id))" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
||||
OnClick="@(() => DeleteSite(context.Id, context.Name))" />
|
||||
OnClick="@(() => ConfirmDeleteSite(context.Id, context.Name))" />
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
@@ -88,6 +97,22 @@ else
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Confirm delete dialog ───────────────────────────────── *@
|
||||
@if (_confirmDeleteShow)
|
||||
{
|
||||
<MudOverlay Visible="@_confirmDeleteShow" OnClick="@(() => _confirmDeleteShow = false)" />
|
||||
<MudDialog @bind-Visible="_confirmDeleteShow">
|
||||
<TitleContent><MudText Typo="Typo.h6">Confirmer la suppression</MudText></TitleContent>
|
||||
<DialogContent>
|
||||
<MudText>Supprimer le site "@_confirmDeleteName" ? Cette action est irréversible.</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">Annuler</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@ExecuteDelete">Supprimer</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Token dialog ──────────────────────────────────────────── *@
|
||||
@if (_showTokenDialog)
|
||||
{
|
||||
@@ -133,6 +158,7 @@ else
|
||||
@code {
|
||||
private IReadOnlyList<SiteItem>? _sites;
|
||||
private bool _loading = true;
|
||||
private bool _error;
|
||||
private bool _showCreate;
|
||||
private bool _saving;
|
||||
private string _newName = "";
|
||||
@@ -154,15 +180,37 @@ else
|
||||
private async Task LoadSites()
|
||||
{
|
||||
_loading = true;
|
||||
_error = false;
|
||||
try
|
||||
{
|
||||
var result = await Api.GetSitesAsync();
|
||||
_sites = result?.Items;
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_error = true;
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
private bool _confirmDeleteShow;
|
||||
private Guid _confirmDeleteId;
|
||||
private string _confirmDeleteName = "";
|
||||
|
||||
private void ConfirmDeleteSite(Guid id, string name)
|
||||
{
|
||||
_confirmDeleteId = id;
|
||||
_confirmDeleteName = name;
|
||||
_confirmDeleteShow = true;
|
||||
}
|
||||
|
||||
private async Task ExecuteDelete()
|
||||
{
|
||||
_confirmDeleteShow = false;
|
||||
await DeleteSite(_confirmDeleteId, _confirmDeleteName);
|
||||
}
|
||||
|
||||
private void CancelCreate()
|
||||
{
|
||||
_showCreate = false;
|
||||
|
||||
@@ -17,6 +17,15 @@
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" />
|
||||
}
|
||||
else if (_error)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
||||
<MudText>Erreur lors du chargement des utilisateurs.</MudText>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadUsers" Class="mt-2">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
||||
</MudButton>
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@_users" Hover="true" Striped="true" Elevation="2">
|
||||
@@ -235,6 +244,7 @@ else
|
||||
@code {
|
||||
private IReadOnlyList<UserItem>? _users;
|
||||
private bool _loading = true;
|
||||
private bool _error;
|
||||
private int _page = 1;
|
||||
private int _totalPages = 1;
|
||||
private int _total;
|
||||
@@ -264,6 +274,7 @@ else
|
||||
private async Task LoadUsers()
|
||||
{
|
||||
_loading = true;
|
||||
_error = false;
|
||||
try
|
||||
{
|
||||
var result = await Api.GetUsersAsync(_page);
|
||||
@@ -274,7 +285,11 @@ else
|
||||
_totalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize));
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
_error = true;
|
||||
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally { _loading = false; }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user