2026-08-12 10:46:09 +02:00
|
|
|
@namespace Heimdall.Web.Components.Settings
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
2026-10-25 05:59:18 +01:00
|
|
|
@inject Heimdall.Web.Services.UiText Text
|
2026-08-12 10:46:09 +02:00
|
|
|
|
|
|
|
|
<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">
|
2026-10-25 05:59:18 +01:00
|
|
|
<i class="fas fa-microchip mr-2"></i> @Text["AgentDefaultsSection_Title"]
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudText>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary">@Text["AgentDefaultsSection_Global"]</MudChip>
|
2026-08-12 10:46:09 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["AgentDefaultsSection_Description"]
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2">
|
2026-10-25 05:59:18 +01:00
|
|
|
<i class="fas fa-list mr-1" style="color: var(--mud-palette-primary);"></i> @Text["AgentDefaultsSection_Logs"]
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudSelect T="string" Label="@Text["AgentDefaultsSection_LogLevel"]" Variant="Variant.Outlined"
|
2026-08-12 10:46:09 +02:00
|
|
|
Value="@(GetValue("log.level") ?? "info")"
|
|
|
|
|
ValueChanged="OnLogLevelChanged" Immediate="true"
|
2026-10-25 05:59:18 +01:00
|
|
|
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>
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudSelect>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudNumericField T="int?" Label="@Text["AgentDefaultsSection_LogRetention"]" Variant="Variant.Outlined"
|
2026-08-12 12:18:52 +02:00
|
|
|
Value="@(int.TryParse(GetValue("log.retentiondays"), out var r) ? r : null)"
|
|
|
|
|
ValueChanged="OnRetentionChanged" Min="1" Max="3650"
|
2026-10-25 05:59:18 +01:00
|
|
|
HelperText="@Text["AgentDefaultsSection_LogRetentionHelp"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
|
2026-10-25 05:59:18 +01:00
|
|
|
<i class="fas fa-heartbeat mr-1" style="color: var(--mud-palette-primary);"></i> @Text["AgentDefaultsSection_Heartbeat"]
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudNumericField T="int?" Label="@Text["AgentDefaultsSection_HeartbeatInterval"]" Variant="Variant.Outlined"
|
2026-08-12 12:18:52 +02:00
|
|
|
Value="@(int.TryParse(GetValue("heartbeat.interval.seconds"), out var h) ? h : null)"
|
2026-10-25 02:55:31 +02:00
|
|
|
ValueChanged="OnHeartbeatChanged" Min="5" Max="300"
|
2026-10-25 05:59:18 +01:00
|
|
|
HelperText="@Text["AgentDefaultsSection_HeartbeatHelp"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
|
2026-10-25 05:59:18 +01:00
|
|
|
<i class="fas fa-bug mr-1" style="color: var(--mud-palette-primary);"></i> @Text["AgentDefaultsSection_Diagnostics"]
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudGrid>
|
2026-08-12 12:18:52 +02:00
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudSwitch T="bool"
|
|
|
|
|
Value="@(GetValue("sentry.enabled")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
|
|
|
|
|
ValueChanged="OnSentryEnabledChanged"
|
|
|
|
|
Color="Color.Primary"
|
2026-10-25 05:59:18 +01:00
|
|
|
Label="@Text["AgentDefaultsSection_SendErrors"]"
|
|
|
|
|
HelperText="@Text["AgentDefaultsSection_SendErrorsHelp"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</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);
|
2026-08-12 12:18:52 +02:00
|
|
|
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");
|
2026-08-12 10:46:09 +02:00
|
|
|
|
|
|
|
|
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();
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Text["AgentDefaultsSection_SettingUpdated"], key), Severity.Success);
|
2026-08-12 10:46:09 +02:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Text["AgentDefaultsSection_SettingUpdateFailed"], ex.Message), Severity.Error);
|
2026-08-12 10:46:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|