2026-07-17 19:08:17 +00:00
|
|
|
@page "/agents/{Id:guid}"
|
2026-07-19 07:25:27 +00:00
|
|
|
@attribute [Authorize(Policy = "Admin.Users")]
|
2026-07-17 19:08:17 +00:00
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
@inject NavigationManager Nav
|
2026-07-18 19:07:01 +00:00
|
|
|
@implements IDisposable
|
2026-07-17 19:08:17 +00:00
|
|
|
|
2026-08-10 22:41:49 +02:00
|
|
|
<MudText Typo="Typo.h1" Class="mb-6">
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Dns" Class="mr-2" />
|
|
|
|
|
Agent : @_agent?.Name
|
|
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
@if (_loading)
|
|
|
|
|
{
|
2026-07-19 07:25:27 +00:00
|
|
|
<LoadingSkeleton LineCount="6" />
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
else if (_agent is null)
|
|
|
|
|
{
|
2026-07-19 07:25:27 +00:00
|
|
|
<EmptyState Icon="@Icons.Material.Filled.Dns"
|
|
|
|
|
Title="Agent introuvable"
|
|
|
|
|
Description="L'agent demandé n'existe pas ou a été supprimé.">
|
|
|
|
|
<ActionContent>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Primary"
|
|
|
|
|
OnClick="@(() => Nav.NavigateTo("/admin/agents"))">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.ArrowBack" Class="mr-1" /> Retour aux agents
|
|
|
|
|
</MudButton>
|
|
|
|
|
</ActionContent>
|
|
|
|
|
</EmptyState>
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-07-19 07:25:27 +00:00
|
|
|
@* ─── Status Bar ─── *@
|
|
|
|
|
<div class="d-flex align-center mb-4">
|
|
|
|
|
<StatusChip Text="@_agent.Status"
|
|
|
|
|
Color="@GetStatusColor(_agent.Status)"
|
|
|
|
|
Icon="@GetStatusIcon(_agent.Status)"
|
|
|
|
|
Size="Size.Medium" />
|
|
|
|
|
<MudSpacer />
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">
|
|
|
|
|
Dernier heartbeat : @(_agent.LastHeartbeat?.ToString("g") ?? "Jamais")
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-07-19 07:25:27 +00:00
|
|
|
<SectionCard Title="Informations" Icon="@Icons.Material.Filled.Info" Elevation="2">
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Hostname</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.Hostname</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Version</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.Version</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Statut</MudText>
|
|
|
|
|
<MudText Color="@GetStatusColor(_agent.Status)" Typo="Typo.body1">
|
|
|
|
|
@GetStatusIcon(_agent.Status) @_agent.Status
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">IP publique</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@(_agent.PublicIp ?? "-")</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Dernier heartbeat</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@(_agent.LastHeartbeat?.ToString("g") ?? "Jamais")</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Enregistré le</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.CreatedAt.ToString("g")</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
2026-07-19 07:25:27 +00:00
|
|
|
</SectionCard>
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-07-19 07:25:27 +00:00
|
|
|
<SectionCard Title="Capacités" Icon="@Icons.Material.Filled.Dns" Elevation="2">
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">CPU</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.CpuCores cœurs</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Mémoire</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@FormatMemory(_agent.MemoryMb)</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">GPU</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">
|
|
|
|
|
<MudIcon Icon="@(_agent.HasGpu ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)"
|
|
|
|
|
Color="@(_agent.HasGpu ? Color.Success : Color.Default)" Size="Size.Small" />
|
|
|
|
|
@(_agent.HasGpu ? _agent.GpuType : "Aucun")
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
2026-07-19 07:25:27 +00:00
|
|
|
</SectionCard>
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
2026-08-10 20:51:57 +02:00
|
|
|
@* ─── Agent Settings (globals hérités + overrides) ─── *@
|
|
|
|
|
<SectionCard Title="Configuration"
|
2026-07-19 07:25:27 +00:00
|
|
|
Icon="@Icons.Material.Filled.Tune"
|
|
|
|
|
Elevation="2"
|
2026-08-10 20:51:57 +02:00
|
|
|
HelpText="Paramètres globaux hérités par cet agent, modifiables pour ce site uniquement. Envoyés en temps réel via SignalR.">
|
2026-07-18 19:07:01 +00:00
|
|
|
|
|
|
|
|
@if (_settingsLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" Size="Size.Small" />
|
|
|
|
|
}
|
|
|
|
|
else if (_settingsError)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">
|
|
|
|
|
Erreur lors du chargement de la configuration
|
|
|
|
|
<MudButton OnClick="@LoadSettingsAsync" Size="Size.Small" Variant="Variant.Text" Class="ml-2">Réessayer</MudButton>
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
2026-08-10 20:51:57 +02:00
|
|
|
else if (_globalSettings.Count == 0 && _settings.Count == 0)
|
2026-07-18 19:07:01 +00:00
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Info" Class="mb-4">
|
2026-08-10 20:51:57 +02:00
|
|
|
Aucun paramètre global exposé aux agents pour le moment.
|
2026-07-18 19:07:01 +00:00
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-08-10 20:51:57 +02:00
|
|
|
@foreach (var category in _globalSettings.GroupBy(s => s.Category).OrderBy(g => g.Key))
|
|
|
|
|
{
|
|
|
|
|
<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="@GetAgentCategoryIcon(category.Key)" Size="Size.Small" Class="mr-1" />
|
|
|
|
|
@category.Key
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined">@category.Count()</MudChip>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<MudGrid>
|
|
|
|
|
@foreach (var setting in category)
|
|
|
|
|
{
|
|
|
|
|
var overridden = IsOverridden(setting.Key);
|
|
|
|
|
var effectiveValue = EffectiveValue(setting.Key, setting.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="@GetAgentTypeIcon(setting.ValueType)" Size="Size.Small"
|
|
|
|
|
Color="@GetAgentTypeColor(setting.ValueType)" Class="mr-2" />
|
|
|
|
|
<div class="flex-grow-1">
|
|
|
|
|
<MudText Typo="Typo.body1" Class="font-weight-medium settings-label">
|
|
|
|
|
@(setting.Description ?? HumanizeAgentKey(setting.Key))
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="settings-key">
|
|
|
|
|
@setting.Key
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
@if (overridden)
|
|
|
|
|
{
|
|
|
|
|
<MudTooltip Text="Réinitialiser à la valeur globale">
|
2026-08-10 22:41:49 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Restore" Size="Size.Small" aria-label="Restaurer"
|
2026-08-10 20:51:57 +02:00
|
|
|
Color="Color.Warning" OnClick="@(() => ExecuteRemoveSettingByKey(setting.Key))" />
|
|
|
|
|
</MudTooltip>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@if (overridden)
|
|
|
|
|
{
|
|
|
|
|
<MudChip T="string" Size="Size.Small" Color="Color.Warning" Class="mb-2">
|
|
|
|
|
Surchargé pour cet agent
|
|
|
|
|
</MudChip>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudChip T="string" Size="Size.Small" Color="Color.Info" Class="mb-2">
|
|
|
|
|
Hérité (global)
|
|
|
|
|
</MudChip>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@switch (setting.ValueType.ToLowerInvariant())
|
|
|
|
|
{
|
|
|
|
|
case "boolean":
|
|
|
|
|
case "bool":
|
|
|
|
|
<div class="d-flex align-center">
|
|
|
|
|
<MudSwitch T="bool"
|
|
|
|
|
Value="@(effectiveValue?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
|
|
|
|
|
ValueChanged="@(v => SaveGlobalOverrideBoolAsync(setting, v))"
|
|
|
|
|
Color="Color.Primary" Class="flex-grow-1" />
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Primary" Class="font-weight-medium">
|
|
|
|
|
@(effectiveValue?.Equals("true", StringComparison.OrdinalIgnoreCase) == true ? "Activé" : "Désactivé")
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
break;
|
|
|
|
|
case "number":
|
|
|
|
|
case "int":
|
|
|
|
|
case "integer":
|
|
|
|
|
case "double":
|
|
|
|
|
<MudTextField T="string" Value="@effectiveValue" Variant="Variant.Outlined" Dense="true"
|
|
|
|
|
ValueChanged="@(v => SaveGlobalOverrideAsync(setting, v))"
|
|
|
|
|
Label="Valeur" Type="InputType.Number" />
|
|
|
|
|
break;
|
|
|
|
|
case "select":
|
|
|
|
|
case "dropdown":
|
|
|
|
|
<MudSelect T="string" Value="@effectiveValue" Variant="Variant.Outlined" Dense="true"
|
|
|
|
|
ValueChanged="@(v => SaveGlobalOverrideAsync(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="@effectiveValue" Variant="Variant.Outlined" Dense="true"
|
|
|
|
|
ValueChanged="@(v => SaveGlobalOverrideAsync(setting, v))" Label="Valeur" />
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
</MudPaper>
|
|
|
|
|
</MudItem>
|
|
|
|
|
}
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
2026-07-18 19:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 20:51:57 +02:00
|
|
|
@if (_settings.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Warning" Class="mt-2">
|
|
|
|
|
@_settings.Count réglage(s) surchargé(s) pour cet agent — la valeur globale est ignorée pour ces clés.
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
2026-07-19 07:25:27 +00:00
|
|
|
</SectionCard>
|
2026-07-18 19:07:01 +00:00
|
|
|
|
2026-07-19 07:25:27 +00:00
|
|
|
<div class="d-flex gap-4 mt-4">
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Default"
|
|
|
|
|
OnClick="@(() => Nav.NavigateTo($"/sites/{_agent.SiteId}/agents"))">
|
|
|
|
|
← Agents du site
|
|
|
|
|
</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Text" Color="Color.Default"
|
|
|
|
|
OnClick="@(() => Nav.NavigateTo("/admin/agents"))">
|
|
|
|
|
← Tous les agents
|
|
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
@* ─── Delete Confirmation Dialog ─── *@
|
|
|
|
|
<MudDialog @bind-Visible="_confirmDeleteVisible" Options="_dialogOptions">
|
|
|
|
|
<TitleContent>
|
|
|
|
|
<MudText Typo="Typo.h6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Warning" Color="Color.Warning" Class="mr-2" />
|
|
|
|
|
Confirmer la suppression
|
|
|
|
|
</MudText>
|
|
|
|
|
</TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<MudText>Supprimer le réglage <strong>@_deletingKey</strong> pour cet agent ?</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2">
|
|
|
|
|
L'agent sera notifié en temps réel via SignalR et utilisera la valeur globale par défaut.
|
|
|
|
|
</MudText>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteVisible = false)">Annuler</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Error"
|
|
|
|
|
OnClick="@ExecuteRemoveSettingAsync"
|
|
|
|
|
Loading="@_deleting"
|
|
|
|
|
Disabled="@_deleting">Supprimer</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
|
|
|
|
@* ─── Add / Edit Dialog ─── *@
|
|
|
|
|
<MudDialog @bind-Visible="_showEditDialog" Options="_dialogOptions">
|
|
|
|
|
<TitleContent>
|
|
|
|
|
<MudText Typo="Typo.h6">@(_editingSetting is null ? "Ajouter un réglage" : "Modifier le réglage")</MudText>
|
|
|
|
|
</TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudTextField Label="Clé"
|
|
|
|
|
@bind-Value="_editKey"
|
|
|
|
|
Disabled="@(_editingSetting is not null)"
|
|
|
|
|
For="@(() => _editKey)"
|
|
|
|
|
Required="true"
|
|
|
|
|
HelperText="Ex: heartbeat.interval.seconds" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudTextField Label="Valeur"
|
|
|
|
|
@bind-Value="_editValue"
|
|
|
|
|
For="@(() => _editValue)"
|
|
|
|
|
Required="true" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showEditDialog = false)">Annuler</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
|
|
|
|
OnClick="@SaveSettingAsync"
|
|
|
|
|
Disabled="@_saving"
|
|
|
|
|
Loading="@_saving">
|
|
|
|
|
@(_editingSetting is null ? "Ajouter" : "Enregistrer")
|
|
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
@code {
|
|
|
|
|
[Parameter] public Guid Id { get; set; }
|
|
|
|
|
|
|
|
|
|
private AgentItem? _agent;
|
|
|
|
|
private bool _loading = true;
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
// Settings
|
|
|
|
|
private List<AgentSettingItem> _settings = [];
|
2026-08-10 20:51:57 +02:00
|
|
|
private List<AppSettingItem> _globalSettings = [];
|
2026-07-18 19:07:01 +00:00
|
|
|
private bool _settingsLoading;
|
|
|
|
|
private bool _settingsError;
|
|
|
|
|
private bool _saving;
|
|
|
|
|
private AgentSettingItem? _editingSetting;
|
|
|
|
|
private string _editKey = string.Empty;
|
|
|
|
|
private string _editValue = string.Empty;
|
|
|
|
|
private bool _showEditDialog;
|
|
|
|
|
private bool _confirmDeleteVisible;
|
|
|
|
|
private string _deletingKey = string.Empty;
|
|
|
|
|
private bool _deleting;
|
|
|
|
|
private readonly DialogOptions _dialogOptions = new()
|
|
|
|
|
{
|
|
|
|
|
MaxWidth = MaxWidth.Small,
|
|
|
|
|
FullWidth = true,
|
|
|
|
|
CloseButton = true
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_agent = await Api.GetAgentAsync(Id);
|
2026-07-18 19:07:01 +00:00
|
|
|
if (_agent is not null)
|
|
|
|
|
await LoadSettingsAsync();
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
private async Task LoadSettingsAsync()
|
|
|
|
|
{
|
|
|
|
|
_settingsError = false;
|
|
|
|
|
_settingsLoading = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-08-10 20:51:57 +02:00
|
|
|
_globalSettings = (await Api.GetSettingsAsync())
|
|
|
|
|
.Where(s => s.AgentScoped)
|
|
|
|
|
.OrderBy(s => s.Category)
|
|
|
|
|
.ThenBy(s => s.Key)
|
|
|
|
|
.ToList();
|
2026-07-18 19:07:01 +00:00
|
|
|
_settings = await Api.GetAgentSettingsAsync(Id);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_settingsError = true;
|
|
|
|
|
_settings = [];
|
2026-08-10 20:51:57 +02:00
|
|
|
_globalSettings = [];
|
2026-07-18 19:07:01 +00:00
|
|
|
}
|
|
|
|
|
finally { _settingsLoading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 20:51:57 +02:00
|
|
|
/// <summary>Returns the effective value for a global setting key (override wins).</summary>
|
|
|
|
|
private string EffectiveValue(string key, string globalValue)
|
|
|
|
|
=> _settings.FirstOrDefault(s => s.Key == key)?.Value ?? globalValue;
|
|
|
|
|
|
|
|
|
|
/// <summary>True when the agent overrides this global key.</summary>
|
|
|
|
|
private bool IsOverridden(string key)
|
|
|
|
|
=> _settings.Any(s => s.Key == key);
|
|
|
|
|
|
|
|
|
|
private async Task SaveGlobalOverrideAsync(AppSettingItem setting, string value)
|
|
|
|
|
{
|
|
|
|
|
_saving = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await Api.SetAgentSettingAsync(Id, new SetAgentSettingRequest(setting.Key, value));
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add($"« {setting.Key} » surchargé pour cet agent — envoyé en temps réel", Severity.Success);
|
|
|
|
|
await LoadSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var error = await response.Content.ReadAsStringAsync();
|
|
|
|
|
Snackbar.Add($"Erreur : {error}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveGlobalOverrideBoolAsync(AppSettingItem setting, bool value)
|
|
|
|
|
=> await SaveGlobalOverrideAsync(setting, value.ToString().ToLowerInvariant());
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
private void OpenAddDialog()
|
|
|
|
|
{
|
|
|
|
|
_editingSetting = null;
|
|
|
|
|
_editKey = string.Empty;
|
|
|
|
|
_editValue = string.Empty;
|
|
|
|
|
_showEditDialog = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenEditDialog(AgentSettingItem setting)
|
|
|
|
|
{
|
|
|
|
|
_editingSetting = setting;
|
|
|
|
|
_editKey = setting.Key;
|
|
|
|
|
_editValue = setting.Value;
|
|
|
|
|
_showEditDialog = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveSettingAsync()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(_editKey)) return;
|
|
|
|
|
|
|
|
|
|
_saving = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var request = new SetAgentSettingRequest(_editKey.Trim(), _editValue);
|
|
|
|
|
var response = await Api.SetAgentSettingAsync(Id, request);
|
|
|
|
|
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add("Réglage enregistré et envoyé à l'agent en temps réel", Severity.Success);
|
|
|
|
|
_showEditDialog = false;
|
|
|
|
|
await LoadSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var error = await response.Content.ReadAsStringAsync();
|
|
|
|
|
Snackbar.Add($"Erreur : {error}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ConfirmRemoveSetting(AgentSettingItem setting)
|
|
|
|
|
{
|
|
|
|
|
_deletingKey = setting.Key;
|
|
|
|
|
_confirmDeleteVisible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ExecuteRemoveSettingAsync()
|
|
|
|
|
{
|
|
|
|
|
_deleting = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await Api.RemoveAgentSettingAsync(Id, _deletingKey);
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
_confirmDeleteVisible = false;
|
|
|
|
|
Snackbar.Add("Réglage supprimé, agent notifié en temps réel", Severity.Success);
|
|
|
|
|
await LoadSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add("Erreur lors de la suppression", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _deleting = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 20:51:57 +02:00
|
|
|
private async Task ExecuteRemoveSettingByKey(string key)
|
|
|
|
|
{
|
|
|
|
|
_deleting = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await Api.RemoveAgentSettingAsync(Id, key);
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add($"« {key} » réinitialisé à la valeur globale — agent notifié", Severity.Success);
|
|
|
|
|
await LoadSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add("Erreur lors de la réinitialisation", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _deleting = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
// No unmanaged resources to dispose
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
private static Color GetStatusColor(string status) => status switch
|
|
|
|
|
{
|
|
|
|
|
"Online" => Color.Success,
|
|
|
|
|
"Offline" => Color.Error,
|
|
|
|
|
"Error" => Color.Warning,
|
|
|
|
|
_ => Color.Default
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string GetStatusIcon(string status) => status switch
|
|
|
|
|
{
|
|
|
|
|
"Online" => "●",
|
|
|
|
|
"Offline" => "○",
|
|
|
|
|
"Error" => "⚠",
|
|
|
|
|
_ => "?"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string FormatMemory(long mb) => mb switch
|
|
|
|
|
{
|
|
|
|
|
> 102400 => $"{mb / 1024:F0} Go",
|
|
|
|
|
> 0 => $"{mb} Mo",
|
|
|
|
|
_ => "-"
|
|
|
|
|
};
|
2026-08-10 20:51:57 +02:00
|
|
|
|
|
|
|
|
// ─── Settings visual helpers ─────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private static Color GetAgentTypeColor(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 GetAgentTypeIcon(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 GetAgentCategoryIcon(string category) => category.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"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,
|
|
|
|
|
"heartbeat" => Icons.Material.Filled.MonitorHeart,
|
|
|
|
|
_ => Icons.Material.Filled.Settings
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string HumanizeAgentKey(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-17 19:08:17 +00:00
|
|
|
}
|