2026-07-18 18:58:20 +00:00
|
|
|
@page "/settings"
|
2026-07-19 07:04:25 +00:00
|
|
|
@attribute [Authorize(Policy = "Admin.Manage")]
|
2026-07-18 18:58:20 +00:00
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
<div class="d-flex align-center mb-4">
|
|
|
|
|
<MudText Typo="Typo.h4" Class="flex-grow-1">
|
2026-07-27 20:11:31 +00:00
|
|
|
<i class="fas fa-cog mr-2"></i>
|
2026-07-19 07:12:40 +00:00
|
|
|
Configuration
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudTooltip Text="Ajouter un nouveau paramètre">
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)" Class="mr-2">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Nouveau
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudTooltip>
|
|
|
|
|
<MudTooltip Text="Forcer le rechargement de la configuration sur tous les agents">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Color="Color.Info" OnClick="@ReloadAllConfig" />
|
|
|
|
|
</MudTooltip>
|
|
|
|
|
</div>
|
2026-07-18 18:58:20 +00:00
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
@* Search + Category filter *@
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: 8px;">
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" sm="6">
|
|
|
|
|
<MudTextField @bind-Value="_searchQuery" Label="Rechercher par clé ou valeur"
|
|
|
|
|
Variant="Variant.Outlined" Immediate="true" Class="mb-0"
|
|
|
|
|
Placeholder="Ex: detection, heartbeat, log..."
|
|
|
|
|
Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="4">
|
|
|
|
|
<MudSelect @bind-Value="_categoryFilter" Label="Catégorie" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-0" Clearable="true">
|
|
|
|
|
<MudSelectItem T="string" Value="@null">Toutes les catégories</MudSelectItem>
|
|
|
|
|
@foreach (var cat in _availableCategories)
|
|
|
|
|
{
|
2026-07-20 10:03:12 +00:00
|
|
|
<MudSelectItem Value="@cat" @key="cat">@cat</MudSelectItem>
|
2026-07-19 07:12:40 +00:00
|
|
|
}
|
|
|
|
|
</MudSelect>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="2" Class="d-flex align-center">
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@ResetFilters" Class="mb-0">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Clear" Size="Size.Small" Class="mr-1" /> Effacer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</MudPaper>
|
2026-07-18 18:58:20 +00:00
|
|
|
|
|
|
|
|
@if (_loading)
|
|
|
|
|
{
|
2026-07-19 07:12:40 +00:00
|
|
|
<MudPaper Elevation="1" Class="pa-4" Style="border-radius: 8px;">
|
|
|
|
|
<MudSkeleton Width="200px" Height="24px" />
|
|
|
|
|
<MudSkeleton Width="100%" Height="40px" Class="mt-2" />
|
|
|
|
|
<MudSkeleton Width="100%" Height="40px" Class="mt-1" />
|
|
|
|
|
<MudSkeleton Width="100%" Height="40px" Class="mt-1" />
|
|
|
|
|
</MudPaper>
|
2026-07-18 18:58:20 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
2026-07-19 07:12:40 +00:00
|
|
|
<MudPaper Class="pa-8 text-center" Style="border-radius: 12px;">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Settings" Size="Size.Large" Color="Color.Secondary" />
|
|
|
|
|
<MudText Typo="Typo.h6" Color="Color.Secondary" Class="mt-4">Aucun paramètre configuré</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
|
|
|
Créez votre premier paramètre pour commencer à personnaliser la configuration.
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Nouveau paramètre
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudPaper>
|
2026-07-18 18:58:20 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-07-19 07:12:40 +00:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">
|
|
|
|
|
@_filteredSettings.Sum(g => g.Value.Count) paramètre(s) affiché(s)
|
|
|
|
|
@if (!string.IsNullOrEmpty(_searchQuery) || _categoryFilter is not null)
|
|
|
|
|
{
|
|
|
|
|
<text>(filtrés)</text>
|
|
|
|
|
}
|
|
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
@foreach (var category in _filteredSettings)
|
2026-07-18 18:58:20 +00:00
|
|
|
{
|
2026-08-10 20:28:42 +02:00
|
|
|
<div class="settings-category mb-4" @key="category.Key">
|
|
|
|
|
<div class="d-flex align-center mb-2 mt-2">
|
|
|
|
|
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
|
|
|
|
<MudIcon Icon="@GetCategoryIcon(category.Key)" Size="Size.Small" Class="mr-1" />
|
|
|
|
|
@category.Key
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined">@category.Value.Count</MudChip>
|
|
|
|
|
</div>
|
2026-07-18 18:58:20 +00:00
|
|
|
|
2026-08-10 20:28:42 +02:00
|
|
|
<MudGrid>
|
|
|
|
|
@foreach (var setting in category.Value)
|
|
|
|
|
{
|
|
|
|
|
<MudItem xs="12" sm="6" lg="4" @key="setting.Key">
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 settings-card" Style="border-radius: 12px; height: 100%;">
|
|
|
|
|
<div class="d-flex align-center mb-2">
|
|
|
|
|
<MudIcon Icon="@GetTypeIcon(setting.ValueType)" Size="Size.Small"
|
|
|
|
|
Color="@GetTypeColorEnum(setting.ValueType)" Class="mr-2" />
|
|
|
|
|
<div class="flex-grow-1">
|
|
|
|
|
<MudText Typo="Typo.body1" Class="font-weight-medium settings-label">
|
|
|
|
|
@(setting.Description ?? HumanizeKey(setting.Key))
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="settings-key">
|
|
|
|
|
@setting.Key
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
<MudTooltip Text="Supprimer">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small"
|
|
|
|
|
Color="Color.Error" OnClick="@(() => ConfirmDelete(setting))" />
|
|
|
|
|
</MudTooltip>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@switch (setting.ValueType.ToLowerInvariant())
|
|
|
|
|
{
|
|
|
|
|
case "boolean":
|
|
|
|
|
case "bool":
|
|
|
|
|
<div class="d-flex align-center">
|
|
|
|
|
<MudSwitch T="bool"
|
|
|
|
|
Value="@(setting.Value?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
|
|
|
|
|
ValueChanged="@(v => SaveBoolInline(setting, v))"
|
|
|
|
|
Color="Color.Primary" Class="flex-grow-1" />
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Primary" Class="font-weight-medium">
|
|
|
|
|
@(setting.Value?.Equals("true", StringComparison.OrdinalIgnoreCase) == true ? "Activé" : "Désactivé")
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
break;
|
|
|
|
|
case "number":
|
|
|
|
|
case "int":
|
|
|
|
|
case "integer":
|
|
|
|
|
case "double":
|
|
|
|
|
<MudTextField T="string" Value="@setting.Value" Variant="Variant.Outlined" Dense="true"
|
|
|
|
|
ValueChanged="@(v => SaveInline(setting, v))"
|
|
|
|
|
Label="Valeur" Type="InputType.Number" />
|
|
|
|
|
break;
|
|
|
|
|
case "select":
|
|
|
|
|
case "dropdown":
|
|
|
|
|
<MudSelect T="string" Value="@setting.Value" Variant="Variant.Outlined" Dense="true"
|
|
|
|
|
ValueChanged="@(v => SaveInline(setting, v))" Label="Valeur">
|
|
|
|
|
@foreach (var opt in (setting.AllowedValues ?? "").Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
|
|
|
|
{
|
|
|
|
|
<MudSelectItem Value="@opt" @key="opt">@opt</MudSelectItem>
|
|
|
|
|
}
|
|
|
|
|
</MudSelect>
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
<MudTextField T="string" Value="@setting.Value" Variant="Variant.Outlined" Dense="true"
|
|
|
|
|
ValueChanged="@(v => SaveInline(setting, v))" Label="Valeur" />
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2 d-flex align-center">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Schedule" Size="Size.Small" Class="mr-1" />
|
|
|
|
|
@setting.UpdatedAt.ToString("g")
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
</MudItem>
|
|
|
|
|
}
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</div>
|
2026-07-18 18:58:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@* ─── Dialog: Créer un paramètre ──────────────────────────────────── *@
|
|
|
|
|
@if (_showCreate)
|
|
|
|
|
{
|
|
|
|
|
<MudOverlay Visible="@_showCreate" OnClick="@(() => _showCreate = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_showCreate">
|
2026-07-19 07:12:40 +00:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Nouveau paramètre
|
|
|
|
|
</MudText></TitleContent>
|
2026-07-18 18:58:20 +00:00
|
|
|
<DialogContent>
|
2026-07-19 07:12:40 +00:00
|
|
|
<form @onsubmit="CreateSetting" method="post">
|
|
|
|
|
<MudTextField @bind-Value="_createKey" Label="Clé *" Variant="Variant.Outlined"
|
|
|
|
|
Class="mb-4" Required="true" Immediate="true"
|
|
|
|
|
Placeholder="Ex: detection.threshold" />
|
|
|
|
|
<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..."
|
|
|
|
|
Placeholder="General" />
|
|
|
|
|
<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>
|
2026-07-18 18:58:20 +00:00
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
@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" />
|
|
|
|
|
}
|
2026-07-18 18:58:20 +00:00
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
@if (!string.IsNullOrEmpty(_createError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_createError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" ButtonType="ButtonType.Submit"
|
|
|
|
|
Disabled="@_saving" Class="hidden">
|
|
|
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
|
|
|
Créer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</form>
|
2026-07-18 18:58:20 +00:00
|
|
|
</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">
|
2026-07-19 07:12:40 +00:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Edit" Class="mr-1" /> @_editSetting.Key
|
|
|
|
|
</MudText></TitleContent>
|
2026-07-18 18:58:20 +00:00
|
|
|
<DialogContent>
|
2026-07-19 07:12:40 +00:00
|
|
|
<form @onsubmit="SaveEdit" method="post">
|
|
|
|
|
@if (_editSetting.ValueType.ToLowerInvariant() is "boolean" or "bool")
|
|
|
|
|
{
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-2">Valeur</MudText>
|
2026-08-10 16:46:08 +02:00
|
|
|
<MudSwitch T="bool" @bind-Value="_editBoolValue" Color="Color.Primary" />
|
2026-07-19 07:12:40 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
2026-07-20 10:03:12 +00:00
|
|
|
<MudSelectItem Value="@opt" @key="opt">@opt</MudSelectItem>
|
2026-07-19 07:12:40 +00:00
|
|
|
}
|
|
|
|
|
</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>
|
2026-07-18 18:58:20 +00:00
|
|
|
</MudSelect>
|
|
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
@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" />
|
|
|
|
|
}
|
2026-07-18 18:58:20 +00:00
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
@if (!string.IsNullOrEmpty(_editError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_editError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" ButtonType="ButtonType.Submit"
|
|
|
|
|
Disabled="@_saving" Class="hidden">
|
|
|
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
|
|
|
Enregistrer
|
|
|
|
|
</MudButton>
|
|
|
|
|
</form>
|
2026-07-18 18:58:20 +00:00
|
|
|
</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">
|
2026-07-19 07:12:40 +00:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Class="mr-1" /> Confirmer la suppression
|
|
|
|
|
</MudText></TitleContent>
|
2026-07-18 18:58:20 +00:00
|
|
|
<DialogContent>
|
|
|
|
|
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
|
|
|
|
Êtes-vous sûr de vouloir supprimer le paramètre <strong>@_deleteTarget.Key</strong> ?
|
2026-07-19 07:12:40 +00:00
|
|
|
@if (_deleteTarget.Description is not null)
|
|
|
|
|
{
|
|
|
|
|
<br /><MudText Typo="Typo.body2" Color="Color.Secondary">@_deleteTarget.Description</MudText>
|
|
|
|
|
}
|
|
|
|
|
<br /><MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Warning" Size="Size.Small" Class="mr-1" />
|
|
|
|
|
Cette action est irréversible. Les agents seront notifiés du changement en temps réel.
|
|
|
|
|
</MudText>
|
2026-07-18 18:58:20 +00:00
|
|
|
</MudAlert>
|
|
|
|
|
@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();
|
2026-07-19 07:12:40 +00:00
|
|
|
private Dictionary<string, List<AppSettingItem>> _filteredSettings = new();
|
|
|
|
|
private List<string> _availableCategories = [];
|
2026-07-18 18:58:20 +00:00
|
|
|
private bool _loading = true;
|
|
|
|
|
private bool _error;
|
|
|
|
|
private bool _saving;
|
|
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
// Search / Filter
|
|
|
|
|
private string _searchQuery = "";
|
|
|
|
|
private string? _categoryFilter;
|
|
|
|
|
|
2026-07-18 18:58:20 +00:00
|
|
|
// 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());
|
2026-07-19 07:12:40 +00:00
|
|
|
_availableCategories = [.. _groupedSettings.Keys.OrderBy(x => x)];
|
|
|
|
|
ApplyFilters();
|
2026-07-18 18:58:20 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_error = true;
|
|
|
|
|
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
private void ApplyFilters()
|
|
|
|
|
{
|
|
|
|
|
var query = _searchQuery?.Trim().ToLowerInvariant() ?? "";
|
|
|
|
|
_filteredSettings = _groupedSettings
|
|
|
|
|
.Where(g => _categoryFilter is null || g.Key == _categoryFilter)
|
|
|
|
|
.ToDictionary(g => g.Key, g =>
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(query)) return g.Value;
|
|
|
|
|
return g.Value.Where(s =>
|
|
|
|
|
s.Key.Contains(query, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
(s.Value?.Contains(query, StringComparison.OrdinalIgnoreCase) ?? false) ||
|
|
|
|
|
(s.Description?.Contains(query, StringComparison.OrdinalIgnoreCase) ?? false)
|
|
|
|
|
).ToList();
|
|
|
|
|
})
|
|
|
|
|
.Where(g => g.Value.Count > 0)
|
|
|
|
|
.ToDictionary(g => g.Key, g => g.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetFilters()
|
|
|
|
|
{
|
|
|
|
|
_searchQuery = "";
|
|
|
|
|
_categoryFilter = null;
|
|
|
|
|
ApplyFilters();
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 18:58:20 +00:00
|
|
|
private string GetTypeColor(string valueType)
|
|
|
|
|
{
|
|
|
|
|
return valueType.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"boolean" or "bool" => "#4caf50",
|
|
|
|
|
"number" or "int" or "integer" => "#2196f3",
|
|
|
|
|
"select" or "dropdown" => "#ff9800",
|
|
|
|
|
_ => "#607d8b"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 20:28:42 +02:00
|
|
|
private static Color GetTypeColorEnum(string valueType) => valueType.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"boolean" or "bool" => Color.Success,
|
|
|
|
|
"number" or "int" or "integer" or "double" => Color.Info,
|
|
|
|
|
"select" or "dropdown" => Color.Warning,
|
|
|
|
|
_ => Color.Secondary
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string GetTypeIcon(string valueType) => valueType.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"boolean" or "bool" => Icons.Material.Filled.ToggleOn,
|
|
|
|
|
"number" or "int" or "integer" or "double" => Icons.Material.Filled.Tag,
|
|
|
|
|
"select" or "dropdown" => Icons.Material.Filled.ArrowDropDownCircle,
|
|
|
|
|
_ => Icons.Material.Filled.TextFields
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string GetCategoryIcon(string category) => category.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"general" or "general" => Icons.Material.Filled.Settings,
|
|
|
|
|
"detection" => Icons.Material.Filled.Visibility,
|
|
|
|
|
"recording" => Icons.Material.Filled.Videocam,
|
|
|
|
|
"logging" or "log" => Icons.Material.Filled.BugReport,
|
|
|
|
|
"network" => Icons.Material.Filled.Wifi,
|
|
|
|
|
"storage" => Icons.Material.Filled.Storage,
|
|
|
|
|
"notification" or "notifications" => Icons.Material.Filled.Notifications,
|
|
|
|
|
_ => Icons.Material.Filled.Folder
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string HumanizeKey(string key)
|
|
|
|
|
{
|
|
|
|
|
var parts = key.Split('.', '_', '-');
|
|
|
|
|
return string.Join(' ', parts.Select(p => p.Length <= 2
|
|
|
|
|
? p.ToUpperInvariant()
|
|
|
|
|
: char.ToUpperInvariant(p[0]) + p[1..]));
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 18:58:20 +00:00
|
|
|
// ─── 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 = "";
|
2026-07-19 07:12:40 +00:00
|
|
|
Snackbar.Add("Paramètre créé avec succès — notifié aux agents en temps réel", Severity.Success);
|
2026-07-18 18:58:20 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
Snackbar.Add("Paramètre mis à jour — notifié aux agents en temps réel", Severity.Success);
|
2026-07-18 18:58:20 +00:00
|
|
|
CloseEdit();
|
|
|
|
|
await LoadSettings();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _editError = $"Erreur : {ex.Message}"; }
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 20:28:42 +02:00
|
|
|
// ─── Inline edit (table) ─────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private async Task SaveInline(AppSettingItem setting, string value)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.UpdateSettingAsync(setting.Key, new UpdateAppSettingRequest(
|
|
|
|
|
value?.Trim() ?? "",
|
|
|
|
|
string.IsNullOrWhiteSpace(setting.Description) ? null : setting.Description.Trim(),
|
|
|
|
|
string.IsNullOrWhiteSpace(setting.Category) ? null : setting.Category.Trim(),
|
|
|
|
|
setting.ValueType,
|
|
|
|
|
string.IsNullOrWhiteSpace(setting.AllowedValues) ? null : setting.AllowedValues
|
|
|
|
|
));
|
|
|
|
|
if (result.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add($"« {setting.Key} » mis à jour — notifié aux agents", Severity.Success);
|
|
|
|
|
await LoadSettings();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var body = await result.Content.ReadAsStringAsync();
|
|
|
|
|
Snackbar.Add($"Erreur : {result.StatusCode} — {body}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveBoolInline(AppSettingItem setting, bool value)
|
|
|
|
|
=> await SaveInline(setting, value.ToString().ToLowerInvariant());
|
|
|
|
|
|
2026-07-18 18:58:20 +00:00
|
|
|
// ─── 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;
|
2026-07-19 07:12:40 +00:00
|
|
|
Snackbar.Add("Paramètre supprimé — rechargement config envoyé aux agents", Severity.Success);
|
2026-07-18 18:58:20 +00:00
|
|
|
_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)
|
2026-07-19 07:12:40 +00:00
|
|
|
Snackbar.Add("Configuration rechargée sur tous les agents en temps réel", Severity.Success);
|
2026-07-18 18:58:20 +00:00
|
|
|
else
|
|
|
|
|
Snackbar.Add($"Erreur lors du rechargement : {result.StatusCode}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
}
|