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-bell mr-2"></i> @Text["NotificationSettingsSection_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["NotificationSettingsSection_Channels"]</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["NotificationSettingsSection_Description"]
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2">
|
|
|
|
|
<i class="fas fa-paper-plane mr-1" style="color: var(--mud-palette-primary);"></i> ntfy
|
|
|
|
|
</MudText>
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField T="string" Label="@Text["NotificationSettingsSection_NtfyServer"]" Variant="Variant.Outlined"
|
2026-08-12 11:12:28 +02:00
|
|
|
Value="@GetValue("ntfy.baseurl")"
|
2026-08-12 10:46:09 +02:00
|
|
|
ValueChanged="OnBaseUrlChanged"
|
2026-10-25 05:59:18 +01:00
|
|
|
HelperText="@Text["NotificationSettingsSection_NtfyServerHelp"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField T="string" Label="@Text["NotificationSettingsSection_AccessToken"]" Variant="Variant.Outlined"
|
2026-08-12 10:46:09 +02:00
|
|
|
Type="InputType.Password"
|
|
|
|
|
Value="@SecretValue("ntfy.token")"
|
|
|
|
|
ValueChanged="OnTokenChanged"
|
2026-10-25 05:59:18 +01:00
|
|
|
Placeholder="@Text["NotificationSettingsSection_SecretConfigured"]"
|
|
|
|
|
HelperText="@Text["NotificationSettingsSection_AccessTokenHelp"]" />
|
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-envelope mr-1" style="color: var(--mud-palette-primary);"></i> @Text["NotificationSettingsSection_SmtpEmail"]
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField T="string" Label="@Text["NotificationSettingsSection_FromAddress"]" Variant="Variant.Outlined"
|
2026-08-12 11:12:28 +02:00
|
|
|
Value="@GetValue("email.fromaddress")"
|
2026-08-12 10:46:09 +02:00
|
|
|
ValueChanged="OnFromAddressChanged"
|
2026-10-25 05:59:18 +01:00
|
|
|
HelperText="@Text["NotificationSettingsSection_FromAddressHelp"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField T="string" Label="@Text["NotificationSettingsSection_FromName"]" Variant="Variant.Outlined"
|
2026-08-12 11:12:28 +02:00
|
|
|
Value="@GetValue("email.fromname")"
|
2026-08-12 10:46:09 +02:00
|
|
|
ValueChanged="OnFromNameChanged" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="4">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField T="string" Label="@Text["NotificationSettingsSection_SmtpHost"]" Variant="Variant.Outlined"
|
2026-08-12 11:12:28 +02:00
|
|
|
Value="@GetValue("email.smtphost")"
|
2026-08-12 10:46:09 +02:00
|
|
|
ValueChanged="OnSmtpHostChanged"
|
2026-10-25 05:59:18 +01:00
|
|
|
HelperText="@Text["NotificationSettingsSection_SmtpHostHelp"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" md="2">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudNumericField T="int?" Label="@Text["NotificationSettingsSection_SmtpPort"]" Variant="Variant.Outlined"
|
2026-08-12 12:18:52 +02:00
|
|
|
Value="@(int.TryParse(GetValue("email.smtpport"), out var p) ? p : null)"
|
|
|
|
|
ValueChanged="OnSmtpPortChanged" Min="1" Max="65535" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="3">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField T="string" Label="@Text["NotificationSettingsSection_SmtpUsername"]" Variant="Variant.Outlined"
|
2026-08-12 10:46:09 +02:00
|
|
|
Value="@GetValue("email.username")"
|
|
|
|
|
ValueChanged="OnUsernameChanged" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="3">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField T="string" Label="@Text["NotificationSettingsSection_SmtpPassword"]" Variant="Variant.Outlined"
|
2026-08-12 10:46:09 +02:00
|
|
|
Type="InputType.Password"
|
|
|
|
|
Value="@SecretValue("email.password")"
|
|
|
|
|
ValueChanged="OnPasswordChanged"
|
2026-10-25 05:59:18 +01:00
|
|
|
Placeholder="@Text["NotificationSettingsSection_SecretConfigured"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudSwitch T="bool"
|
2026-08-12 11:12:28 +02:00
|
|
|
Value="@(GetValue("email.usessl")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true)"
|
2026-08-12 10:46:09 +02:00
|
|
|
ValueChanged="OnUseSslChanged"
|
|
|
|
|
Color="Color.Primary"
|
2026-10-25 05:59:18 +01:00
|
|
|
Label="@Text["NotificationSettingsSection_UseTls"]"
|
|
|
|
|
HelperText="@Text["NotificationSettingsSection_UseTlsHelp"]" />
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
2026-08-12 11:50:47 +02:00
|
|
|
|
|
|
|
|
<div class="d-flex align-center mt-3">
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Send"
|
|
|
|
|
OnClick="TestNtfyAsync" Disabled="@_testing">
|
2026-10-25 05:59:18 +01:00
|
|
|
@(_testing ? Text["NotificationSettingsSection_Testing"] : Text["NotificationSettingsSection_TestNtfy"])
|
2026-08-12 11:50:47 +02:00
|
|
|
</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Info" Class="ml-2" StartIcon="@Icons.Material.Filled.Email"
|
|
|
|
|
OnClick="TestEmailAsync" Disabled="@_testing">
|
2026-10-25 05:59:18 +01:00
|
|
|
@(_testing ? Text["NotificationSettingsSection_Testing"] : Text["NotificationSettingsSection_TestEmail"])
|
2026-08-12 11:50:47 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
|
|
|
|
@if (_testResult is not null)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="@(_testResult.Success ? Severity.Success : Severity.Error)" Class="mt-3" Variant="Variant.Outlined">
|
|
|
|
|
@_testResult.Message
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
2026-08-12 10:46:09 +02:00
|
|
|
</MudPaper>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
private List<AppSettingItem> _settings = [];
|
2026-08-12 11:50:47 +02:00
|
|
|
private bool _testing;
|
|
|
|
|
private TestActionResult? _testResult;
|
2026-08-12 10:46:09 +02:00
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_settings = await Api.GetSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// API indisponible (ex : test) — on reste sur les défauts.
|
|
|
|
|
_settings = [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string? GetValue(string key)
|
|
|
|
|
=> _settings.FirstOrDefault(s => s.Key == key)?.Value;
|
|
|
|
|
|
|
|
|
|
// Les secrets sont redactés par l'API (***REDACTED***) : afficher vide avec
|
|
|
|
|
// un placeholder pour ne pas laisser croire que la valeur est vide.
|
|
|
|
|
private string SecretValue(string key)
|
|
|
|
|
{
|
|
|
|
|
var v = GetValue(key);
|
|
|
|
|
return v is null or "" or "***REDACTED***" ? string.Empty : v;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 11:12:28 +02:00
|
|
|
private Task OnBaseUrlChanged(string v) => SaveValueAsync("ntfy.baseurl", v);
|
2026-08-12 10:46:09 +02:00
|
|
|
private Task OnTokenChanged(string v) => SaveValueAsync("ntfy.token", v);
|
2026-08-12 11:12:28 +02:00
|
|
|
private Task OnFromAddressChanged(string v) => SaveValueAsync("email.fromaddress", v);
|
|
|
|
|
private Task OnFromNameChanged(string v) => SaveValueAsync("email.fromname", v);
|
|
|
|
|
private Task OnSmtpHostChanged(string v) => SaveValueAsync("email.smtphost", v);
|
2026-08-12 12:18:52 +02:00
|
|
|
private Task OnSmtpPortChanged(int? v) => SaveValueAsync("email.smtpport", v?.ToString() ?? "");
|
2026-08-12 10:46:09 +02:00
|
|
|
private Task OnUsernameChanged(string v) => SaveValueAsync("email.username", v);
|
|
|
|
|
private Task OnPasswordChanged(string v) => SaveValueAsync("email.password", v);
|
2026-08-12 11:12:28 +02:00
|
|
|
private Task OnUseSslChanged(bool v) => SaveValueAsync("email.usessl", v ? "true" : "false");
|
2026-08-12 10:46:09 +02:00
|
|
|
|
2026-08-12 11:50:47 +02:00
|
|
|
private async Task TestNtfyAsync()
|
|
|
|
|
{
|
|
|
|
|
_testing = true;
|
|
|
|
|
_testResult = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
_testResult = await Api.TestNtfyAsync() ?? new TestActionResult(false, Text["NotificationSettingsSection_TestUnavailable"]);
|
2026-08-12 11:50:47 +02:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
_testResult = new TestActionResult(false, string.Format(Text["NotificationSettingsSection_TestFailed"], ex.Message));
|
2026-08-12 11:50:47 +02:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_testing = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task TestEmailAsync()
|
|
|
|
|
{
|
|
|
|
|
_testing = true;
|
|
|
|
|
_testResult = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
_testResult = await Api.TestEmailAsync() ?? new TestActionResult(false, Text["NotificationSettingsSection_TestUnavailable"]);
|
2026-08-12 11:50:47 +02:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
_testResult = new TestActionResult(false, string.Format(Text["NotificationSettingsSection_TestFailed"], ex.Message));
|
2026-08-12 11:50:47 +02:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_testing = 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: "integrations",
|
2026-08-12 12:18:52 +02:00
|
|
|
Description: key, ValueType: "string", AllowedValues: null, AgentScoped: false));
|
2026-08-12 10:46:09 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await Api.UpdateSettingAsync(key, new UpdateAppSettingRequest(
|
|
|
|
|
Value: value, Description: existing.Description ?? key,
|
|
|
|
|
Category: "integrations", ValueType: "string", AllowedValues: null, AgentScoped: null));
|
|
|
|
|
}
|
|
|
|
|
_settings = await Api.GetSettingsAsync();
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Text["NotificationSettingsSection_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["NotificationSettingsSection_SettingUpdateFailed"], ex.Message), Severity.Error);
|
2026-08-12 10:46:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|