feat(ui): écran Configuration en cartes visuelles par catégorie
Fini la table clé/valeur : chaque paramètre est une carte avec libellé lisible (description ou clé humanisée), icône de type, clé en sous-titre monospace, et contrôle visuel adapté (switch Activé/Désactivé, champ nombre, select, texte) avec sauvegarde inline. Recherche + filtre catégorie conservés. Tests adaptés à l'édition inline.
This commit is contained in:
1 parent
dce668c012
commit
d697a94257
3 files changed
+170
-77
No files matched your search
@@ -89,76 +89,84 @@ else
|
||||
|
||||
@foreach (var category in _filteredSettings)
|
||||
{
|
||||
<MudText Typo="Typo.subtitle1" Class="mb-2 mt-4" @key="category.Key">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Folder" Size="Size.Small" Class="mr-1" />
|
||||
@category.Key
|
||||
<MudChip T="string" Size="Size.Small" Class="ml-2">@category.Value.Count</MudChip>
|
||||
</MudText>
|
||||
<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>
|
||||
|
||||
<MudTable Items="@category.Value" Hover="true" Striped="true" Elevation="2" Class="mb-4" Dense="true">
|
||||
<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-Value="_switches[context.Key]"
|
||||
Disabled="true" Color="Color.Primary" />
|
||||
break;
|
||||
case "number":
|
||||
case "int":
|
||||
case "integer":
|
||||
<MudText Typo="Typo.body2" Class="font-weight-bold">@context.Value</MudText>
|
||||
break;
|
||||
case "select":
|
||||
case "dropdown":
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Tertiary">@context.Value</MudChip>
|
||||
break;
|
||||
default:
|
||||
<MudText Typo="Typo.body2" Style="max-width:300px;word-break:break-all;">@context.Value</MudText>
|
||||
break;
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Type">
|
||||
<MudChip T="string" Size="Size.Small" Class="settings-type-chip"
|
||||
Style="@($"background:{GetTypeColor(context.ValueType)}")">
|
||||
@context.ValueType
|
||||
</MudChip>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Description">
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">
|
||||
@(context.Description ?? "—")
|
||||
</MudText>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Mis à jour">
|
||||
<MudText Typo="Typo.body2" Color="Color.Secondary">@context.UpdatedAt.ToString("g")</MudText>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Actions">
|
||||
<MudTooltip Text="Modifier ce paramètre">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small"
|
||||
OnClick="@(() => OpenEdit(context))" Class="mr-1" />
|
||||
</MudTooltip>
|
||||
<MudTooltip Text="Supprimer ce paramètre">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small"
|
||||
Color="Color.Error" OnClick="@(() => ConfirmDelete(context))" />
|
||||
</MudTooltip>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
<MudText Align="Align.Center" Class="py-4">Aucun paramètre dans cette catégorie</MudText>
|
||||
</NoRecordsContent>
|
||||
</MudTable>
|
||||
<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>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,6 +447,42 @@ else
|
||||
};
|
||||
}
|
||||
|
||||
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..]));
|
||||
}
|
||||
|
||||
// ─── Create ───────────────────────────────────────────────────────
|
||||
|
||||
private async Task CreateSetting()
|
||||
@@ -540,6 +584,39 @@ else
|
||||
finally { _saving = false; }
|
||||
}
|
||||
|
||||
// ─── 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());
|
||||
|
||||
// ─── Delete ───────────────────────────────────────────────────────
|
||||
|
||||
private void ConfirmDelete(AppSettingItem setting)
|
||||
|
||||
@@ -306,6 +306,25 @@ code {
|
||||
font-weight: 500 !important;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
transition: box-shadow 0.2s ease, transform 0.15s ease;
|
||||
}
|
||||
|
||||
.settings-card:hover {
|
||||
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12) !important;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.settings-label {
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.settings-key {
|
||||
font-family: var(--mud-font-monospace), monospace;
|
||||
font-size: 0.72rem;
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════════
|
||||
Empty states
|
||||
═══════════════════════════════════════════════════════════════════ */
|
||||
|
||||
@@ -120,18 +120,14 @@ public class SettingsPageTests : PageTestBase
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("log.level"));
|
||||
|
||||
// Icon-buttons : [0]=refresh (header), [1]=edit, [2]=delete
|
||||
cut.FindAll("button.mud-icon-button")[1].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("log.level"));
|
||||
|
||||
cut.FindAll(".mud-dialog input")[0].Input("debug");
|
||||
cut.Find("form").Submit();
|
||||
// Édition inline : le champ texte de la carte sauvegarde directement (pas de dialog)
|
||||
cut.FindAll(".settings-card .mud-input input")[0].Change("debug");
|
||||
|
||||
cut.WaitForAssertion(() =>
|
||||
{
|
||||
var snackbar = Services.GetRequiredService<ISnackbar>();
|
||||
snackbar.ShownSnackbars.Select(m => m.Message?.ToString() ?? "")
|
||||
.ShouldContain(m => m.Contains("Paramètre mis à jour", StringComparison.OrdinalIgnoreCase));
|
||||
.ShouldContain(m => m.Contains("mis à jour", StringComparison.OrdinalIgnoreCase));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,7 +141,8 @@ public class SettingsPageTests : PageTestBase
|
||||
var cut = RenderPage<SettingsPage>();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("log.level"));
|
||||
|
||||
cut.FindAll("button.mud-icon-button")[2].Click();
|
||||
// Icon-buttons : [0]=refresh (header), [1]=delete (carte)
|
||||
cut.FindAll("button.mud-icon-button")[1].Click();
|
||||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Confirmer la suppression"));
|
||||
|
||||
cut.FindAll("button").Single(b => b.TextContent.Trim() == "Supprimer").Click();
|
||||
|
||||
Reference in new issue
Block a user