Files
Heimdall/src/Heimdall.Web/Components/Settings/AgentDefaultsSection.razor
T
Arnaud Dartois 8d35518d1a
Heimdall Gitea / Detect CI scope (pull_request) Successful in 5s
Heimdall Gitea / Build and tests (pull_request) Failing after 2m11s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 3s
feat(agent): add Pangolin-style native installs and updates
2026-10-26 11:38:29 +01:00

135 lines
6.3 KiB
Plaintext

@namespace Heimdall.Web.Components.Settings
@inject HeimdallApiClient Api
@inject ISnackbar Snackbar
@inject Heimdall.Web.Services.UiText Text
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-lg);">
<div class="d-flex align-center mb-3">
<MudText Typo="Typo.h6" Class="flex-grow-1">
<i class="fas fa-microchip mr-2"></i> @Text["AgentDefaultsSection_Title"]
</MudText>
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary">@Text["AgentDefaultsSection_Global"]</MudChip>
</div>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
@Text["AgentDefaultsSection_Description"]
</MudText>
<MudText Typo="Typo.subtitle2" Class="mb-2">
<i class="fas fa-list mr-1" style="color: var(--mud-palette-primary);"></i> @Text["AgentDefaultsSection_Logs"]
</MudText>
<MudGrid>
<MudItem xs="12" md="6">
<MudSelect T="string" Label="@Text["AgentDefaultsSection_LogLevel"]" Variant="Variant.Outlined"
Value="@(GetValue("log.level") ?? "info")"
ValueChanged="OnLogLevelChanged" Immediate="true"
HelperText="@Text["AgentDefaultsSection_LogLevelHelp"]">
<MudSelectItem Value="@("trace")">@Text["AgentDefaultsSection_LogTrace"]</MudSelectItem>
<MudSelectItem Value="@("debug")">@Text["AgentDefaultsSection_LogDebug"]</MudSelectItem>
<MudSelectItem Value="@("info")">@Text["AgentDefaultsSection_LogInfo"]</MudSelectItem>
<MudSelectItem Value="@("warn")">@Text["AgentDefaultsSection_LogWarn"]</MudSelectItem>
<MudSelectItem Value="@("error")">@Text["AgentDefaultsSection_LogError"]</MudSelectItem>
</MudSelect>
</MudItem>
<MudItem xs="12" md="6">
<MudNumericField T="int?" Label="@Text["AgentDefaultsSection_LogRetention"]" Variant="Variant.Outlined"
Value="@(int.TryParse(GetValue("log.retentiondays"), out var r) ? r : null)"
ValueChanged="OnRetentionChanged" Min="1" Max="3650"
HelperText="@Text["AgentDefaultsSection_LogRetentionHelp"]" />
</MudItem>
</MudGrid>
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
<i class="fas fa-heartbeat mr-1" style="color: var(--mud-palette-primary);"></i> @Text["AgentDefaultsSection_Heartbeat"]
</MudText>
<MudGrid>
<MudItem xs="12" md="6">
<MudNumericField T="int?" Label="@Text["AgentDefaultsSection_HeartbeatInterval"]" Variant="Variant.Outlined"
Value="@(int.TryParse(GetValue("heartbeat.interval.seconds"), out var h) ? h : null)"
ValueChanged="OnHeartbeatChanged" Min="5" Max="300"
HelperText="@Text["AgentDefaultsSection_HeartbeatHelp"]" />
</MudItem>
</MudGrid>
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
<i class="fas fa-arrows-rotate mr-1" style="color: var(--mud-palette-primary);"></i> @Text["AgentDefaultsSection_Updates"]
</MudText>
<MudGrid>
<MudItem xs="12">
<MudSwitch T="bool"
Value="@(GetValue("autoupdateenabled")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
ValueChanged="OnAutoUpdateChanged"
Color="Color.Primary"
Label="@Text["AgentDefaultsSection_AutoUpdate"]"
HelperText="@Text["AgentDefaultsSection_AutoUpdateHelp"]" />
</MudItem>
</MudGrid>
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
<i class="fas fa-bug mr-1" style="color: var(--mud-palette-primary);"></i> @Text["AgentDefaultsSection_Diagnostics"]
</MudText>
<MudGrid>
<MudItem xs="12">
<MudSwitch T="bool"
Value="@(GetValue("sentry.enabled")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
ValueChanged="OnSentryEnabledChanged"
Color="Color.Primary"
Label="@Text["AgentDefaultsSection_SendErrors"]"
HelperText="@Text["AgentDefaultsSection_SendErrorsHelp"]" />
</MudItem>
</MudGrid>
</MudPaper>
@code {
private List<AppSettingItem> _settings = [];
protected override async Task OnInitializedAsync()
{
try
{
_settings = await Api.GetSettingsAsync();
}
catch
{
_settings = [];
}
}
private string? GetValue(string key)
=> _settings.FirstOrDefault(s => s.Key == key)?.Value;
private Task OnLogLevelChanged(string v) => SaveValueAsync("log.level", v);
private Task OnRetentionChanged(int? v) => SaveValueAsync("log.retentiondays", v?.ToString() ?? "");
private Task OnHeartbeatChanged(int? v) => SaveValueAsync("heartbeat.interval.seconds", v?.ToString() ?? "");
private Task OnSentryEnabledChanged(bool v) => SaveValueAsync("sentry.enabled", v ? "true" : "false");
private Task OnAutoUpdateChanged(bool v) => SaveValueAsync("autoupdateenabled", v ? "true" : "false");
private async Task SaveValueAsync(string key, string? value)
{
value ??= string.Empty;
var existing = _settings.FirstOrDefault(s => s.Key == key);
try
{
if (existing is null)
{
await Api.CreateSettingAsync(new CreateAppSettingRequest(
Key: key, Value: value,
Category: "agent",
Description: key, ValueType: "string", AllowedValues: null, AgentScoped: true));
}
else
{
await Api.UpdateSettingAsync(key, new UpdateAppSettingRequest(
Value: value, Description: existing.Description ?? key,
Category: "agent", ValueType: "string", AllowedValues: null, AgentScoped: null));
}
_settings = await Api.GetSettingsAsync();
Snackbar.Add(string.Format(Text["AgentDefaultsSection_SettingUpdated"], key), Severity.Success);
}
catch (Exception ex)
{
Snackbar.Add(string.Format(Text["AgentDefaultsSection_SettingUpdateFailed"], ex.Message), Severity.Error);
}
}
}