496 lines
21 KiB
Plaintext
496 lines
21 KiB
Plaintext
@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; }
|
||
|
|
}
|
||
|
|
}
|