Heimdall Gitea / Detect CI scope (push) Successful in 27s
Heimdall Gitea / Build and tests (push) Successful in 20m48s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 7m28s
Heimdall Gitea / Build and scan agent image (push) Successful in 11m12s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m59s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m43s
Heimdall Gitea / CI policy (push) Successful in 2s
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
481 lines
20 KiB
Plaintext
481 lines
20 KiB
Plaintext
@page "/sites"
|
|
@attribute [Authorize]
|
|
@layout MainLayout
|
|
@inject HeimdallApiClient Api
|
|
@inject AuthState Auth
|
|
@inject ISnackbar Snackbar
|
|
@inject UiText Text
|
|
@inject UiLanguageService Language
|
|
@inject NavigationManager Nav
|
|
@implements IDisposable
|
|
|
|
<MudText Typo="Typo.h1" Class="mb-1">
|
|
<i class="fas fa-video mr-2"></i>
|
|
@Text["SitesPage_Title"]
|
|
</MudText>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
@Text["SitesPage_Description"]
|
|
</MudText>
|
|
|
|
<div class="d-flex justify-space-between align-center mb-4">
|
|
@if (CanCreateSite)
|
|
{
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OpenCreate">
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["SitesPage_NewSite"]
|
|
</MudButton>
|
|
}
|
|
</div>
|
|
|
|
@if (_loading)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" />
|
|
}
|
|
else if (_error)
|
|
{
|
|
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
|
<MudText>@Text["SitesPage_LoadError"]</MudText>
|
|
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadSites" Class="mt-2">
|
|
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> @Text["SitesPage_Retry"]
|
|
</MudButton>
|
|
</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudTable Items="@_sites" Hover="true" Striped="true" Elevation="2">
|
|
<HeaderContent>
|
|
<MudTh>@Text["SitesPage_Name"]</MudTh>
|
|
<MudTh>@Text["SitesPage_Address"]</MudTh>
|
|
<MudTh>@Text["SitesPage_Timezone"]</MudTh>
|
|
<MudTh>@Text["SitesPage_Status"]</MudTh>
|
|
<MudTh>@Text["SitesPage_Actions"]</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="@Text["SitesPage_Name"]"><MudLink Href="@($"/sites/{context.Id}")">@context.Name</MudLink></MudTd>
|
|
<MudTd DataLabel="@Text["SitesPage_Address"]">@context.Address</MudTd>
|
|
<MudTd DataLabel="@Text["SitesPage_Timezone"]">@context.Timezone</MudTd>
|
|
<MudTd DataLabel="@Text["SitesPage_Status"]">
|
|
<StatusChip Text="@(context.Enabled ? Text["SitesPage_Active"] : Text["SitesPage_Inactive"])"
|
|
Color="@(context.Enabled ? Color.Success : Color.Default)"
|
|
Icon="@(context.Enabled ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)" />
|
|
</MudTd>
|
|
<MudTd DataLabel="@Text["SitesPage_Actions"]">
|
|
<MudTooltip Text="@Text["SitesPage_EditTooltip"]">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small" aria-label="@Text["SitesPage_EditTitle"]"
|
|
OnClick="@(() => OpenEdit(context))" />
|
|
</MudTooltip>
|
|
<MudTooltip Text="@Text["SitesPage_InstallTooltip"]">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Download" Size="Size.Small" Color="Color.Info" aria-label="@Text["SitesPage_DownloadConfig"]"
|
|
OnClick="@(() => CopyToken(context.Id, context.Name))" />
|
|
</MudTooltip>
|
|
<MudTooltip Text="@Text["SitesPage_DeleteTooltip"]">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error" aria-label="@Text["SitesPage_DeleteSite"]"
|
|
OnClick="@(() => ConfirmDeleteSite(context.Id, context.Name))" />
|
|
</MudTooltip>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
<NoRecordsContent>
|
|
<MudText Align="Align.Center" Class="py-4">@Text["SitesPage_NoSites"]</MudText>
|
|
</NoRecordsContent>
|
|
</MudTable>
|
|
}
|
|
|
|
@if (CanCreateSite)
|
|
{
|
|
<MudOverlay Visible="@_showCreate" OnClick="@(() => _showCreate = false)" />
|
|
<MudDialog @bind-Visible="_showCreate">
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["SitesPage_NewSite"]</MudText></TitleContent>
|
|
<DialogContent>
|
|
<MudTextField @bind-Value="_newName" Label="@Text["SitesPage_NameRequired"]" Variant="Variant.Outlined"
|
|
Class="mb-4" Required="true" Immediate="true" />
|
|
<MudTextField @bind-Value="_newAddress" Label="@Text["SitesPage_Address"]" Variant="Variant.Outlined" Class="mb-4" />
|
|
<TimezoneAutocomplete @bind-Value="_newTimezone" Class="mb-4"
|
|
HelperText="@Text["SitesPage_TimezoneHelper"]" />
|
|
<MudTextField @bind-Value="_newNtfyTopic" Label="@Text["SitesPage_NtfyLabel"]" Variant="Variant.Outlined" Class="mb-4"
|
|
HelperText="@Text["SitesPage_NtfyHelper"]" />
|
|
@if (!string.IsNullOrEmpty(_creationError))
|
|
{
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_creationError</MudAlert>
|
|
}
|
|
@if (!string.IsNullOrEmpty(_createdToken))
|
|
{
|
|
<MudAlert Severity="Severity.Success" Class="mb-4">
|
|
<strong>@Text["SitesPage_RegistrationToken"]</strong><br />
|
|
<code class="hmd-code-block mt-2">
|
|
@_createdToken
|
|
</code>
|
|
<MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
|
⚠ @Text["SitesPage_TokenCopyWarning"]
|
|
</MudText>
|
|
</MudAlert>
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Text" OnClick="@CancelCreate">@Text["SitesPage_Cancel"]</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ConfirmCreate"
|
|
Disabled="@IsCreateDisabled">
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
@(!string.IsNullOrEmpty(_createdToken) ? Text["SitesPage_Close"] : Text["SitesPage_Create"])
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
}
|
|
|
|
@* ─── Confirm delete dialog ───────────────────────────────── *@
|
|
<MudOverlay Visible="@_confirmDeleteShow" OnClick="@(() => _confirmDeleteShow = false)" />
|
|
<MudDialog @bind-Visible="_confirmDeleteShow">
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["SitesPage_ConfirmDeleteTitle"]</MudText></TitleContent>
|
|
<DialogContent>
|
|
<MudText>@string.Format(Language.Culture, Text["SitesPage_DeleteConfirm"], _confirmDeleteName)</MudText>
|
|
@if (_cascadeInfoLoading)
|
|
{
|
|
<MudProgressCircular Size="Size.Small" Class="mt-2" />
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="ml-2 d-inline">@Text["SitesPage_CascadeLoading"]</MudText>
|
|
}
|
|
else if (_cascadeInfo is not null)
|
|
{
|
|
<MudAlert Severity="Severity.Warning" Variant="Variant.Outlined" Class="mt-3">
|
|
<MudText Typo="Typo.body2">
|
|
@Text["SitesPage_DeleteCascadeDescription"]
|
|
</MudText>
|
|
<MudText Typo="Typo.body2" Class="mt-1">
|
|
• <strong>@_cascadeInfo.AgentCount</strong> @Text["SitesPage_AgentCount"]
|
|
</MudText>
|
|
<MudText Typo="Typo.body2">
|
|
• <strong>@_cascadeInfo.CameraCount</strong> @Text["SitesPage_CameraCount"]
|
|
</MudText>
|
|
</MudAlert>
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">@Text["SitesPage_Cancel"]</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@ExecuteDelete"
|
|
Disabled="@_cascadeInfoLoading">@Text["SitesPage_Delete"]</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@* ─── Edit dialog ───────────────────────────────────────────── *@
|
|
<MudOverlay Visible="@_showEdit" OnClick="@(() => _showEdit = false)" />
|
|
<MudDialog @bind-Visible="_showEdit">
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["SitesPage_EditTitle"]</MudText></TitleContent>
|
|
<DialogContent>
|
|
<MudTextField @bind-Value="_editName" Label="@Text["SitesPage_NameRequired"]" Variant="Variant.Outlined"
|
|
Class="mb-4" Required="true" Immediate="true" />
|
|
<MudTextField @bind-Value="_editAddress" Label="@Text["SitesPage_Address"]" Variant="Variant.Outlined" Class="mb-4" />
|
|
<TimezoneAutocomplete @bind-Value="_editTimezone" Class="mb-4"
|
|
HelperText="@Text["SitesPage_TimezoneHelper"]" />
|
|
<MudTextField @bind-Value="_editNtfyTopic" Label="@Text["SitesPage_NtfyLabel"]" Variant="Variant.Outlined" Class="mb-4"
|
|
HelperText="@Text["SitesPage_NtfyHelper"]" />
|
|
<MudSelect T="bool?" Value="_editAutoUpdate" ValueChanged="OnAutoUpdateOverrideChanged"
|
|
Label="@Text["SitesPage_AutoUpdate"]" Variant="Variant.Outlined" Class="mb-4"
|
|
HelperText="@Text["SitesPage_AutoUpdateHelper"]">
|
|
<MudSelectItem T="bool?" Value="@((bool?)null)">@Text["SitesPage_AutoUpdateInherit"]</MudSelectItem>
|
|
<MudSelectItem T="bool?" Value="@((bool?)true)">@Text["SitesPage_AutoUpdateEnabled"]</MudSelectItem>
|
|
<MudSelectItem T="bool?" Value="@((bool?)false)">@Text["SitesPage_AutoUpdateDisabled"]</MudSelectItem>
|
|
</MudSelect>
|
|
@if (!string.IsNullOrEmpty(_editError))
|
|
{
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_editError</MudAlert>
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showEdit = false)">@Text["SitesPage_Cancel"]</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@SaveEdit" Disabled="@_editing">
|
|
@if (_editing) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
@Text["SitesPage_Save"]
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@* ─── Install agent dialog (façon Pangolin) ─────────────────── *@
|
|
<MudOverlay Visible="@_showInstall" OnClick="@(() => _showInstall = false)" />
|
|
<MudDialog @bind-Visible="_showInstall" Options="new DialogOptions { MaxWidth = MaxWidth.Large, FullWidth = true }">
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">@string.Format(Language.Culture, Text["SitesPage_InstallTitle"], _installSiteName)</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
@if (_tokenLoading)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" Class="mb-4" />
|
|
<MudText>@Text["SitesPage_TokenGenerating"]</MudText>
|
|
}
|
|
else if (!string.IsNullOrEmpty(_tokenError))
|
|
{
|
|
<MudAlert Severity="Severity.Error">@_tokenError</MudAlert>
|
|
}
|
|
else if (!string.IsNullOrEmpty(_generatedToken))
|
|
{
|
|
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
|
<MudText Typo="Typo.body2" Class="mb-2">
|
|
@Text["SitesPage_TokenExpiresWarning"]
|
|
</MudText>
|
|
<code class="hmd-code-block">
|
|
@_generatedToken
|
|
</code>
|
|
</MudAlert>
|
|
<SiteInstallPanel SiteName="@_installSiteName" SiteToken="@_generatedToken"
|
|
CentralUrl="@CentralUrl" />
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showInstall = false)">@Text["SitesPage_Close"]</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@* ─── Token dialog (génération simple depuis le tableau) ─────── *@
|
|
<MudOverlay Visible="@_showTokenDialog" OnClick="@(() => _showTokenDialog = false)" />
|
|
<MudDialog @bind-Visible="_showTokenDialog">
|
|
<TitleContent>
|
|
<MudText Typo="Typo.h6">@Text["SitesPage_RegistrationToken"]</MudText>
|
|
</TitleContent>
|
|
<DialogContent>
|
|
@if (_tokenLoading)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" Class="mb-4" />
|
|
<MudText>@Text["SitesPage_TokenGenerating"]</MudText>
|
|
}
|
|
else if (!string.IsNullOrEmpty(_tokenError))
|
|
{
|
|
<MudAlert Severity="Severity.Error">@_tokenError</MudAlert>
|
|
}
|
|
else if (!string.IsNullOrEmpty(_generatedToken))
|
|
{
|
|
<MudAlert Severity="Severity.Info">
|
|
<MudText Typo="Typo.body2" Class="mb-2">
|
|
@Text["SitesPage_TokenUsage"]
|
|
</MudText>
|
|
<code class="hmd-code-block mt-2">
|
|
@_generatedToken
|
|
</code>
|
|
<MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
|
⚠ @Text["SitesPage_TokenExpiresCopy"]
|
|
</MudText>
|
|
</MudAlert>
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
|
OnClick="@(() => _showTokenDialog = false)">
|
|
@Text["Close"]
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
private bool CanCreateSite => Auth.HasPermission("Site.Write");
|
|
|
|
private void OpenCreate()
|
|
{
|
|
if (CanCreateSite)
|
|
_showCreate = true;
|
|
}
|
|
private IReadOnlyList<SiteItem>? _sites;
|
|
private bool _loading = true;
|
|
private bool _error;
|
|
private bool _showCreate;
|
|
private bool _saving;
|
|
private string _newName = "";
|
|
private string? _newAddress;
|
|
private string? _newTimezone;
|
|
private string? _newNtfyTopic;
|
|
private string _creationError = "";
|
|
private string _createdToken = "";
|
|
private bool IsCreateDisabled => _saving || !string.IsNullOrEmpty(_createdToken);
|
|
|
|
// Token generation / install dialog
|
|
private bool _showInstall;
|
|
private bool _showTokenDialog;
|
|
private bool _tokenLoading;
|
|
private string _generatedToken = "";
|
|
private string _tokenError = "";
|
|
private Guid _tokenSiteId;
|
|
private string _installSiteName = "";
|
|
|
|
// Edit dialog
|
|
private bool _showEdit;
|
|
private bool _editing;
|
|
private Guid _editId;
|
|
private string _editName = "";
|
|
private string? _editAddress;
|
|
private string? _editTimezone;
|
|
private string? _editNtfyTopic;
|
|
private bool? _editAutoUpdate;
|
|
private string _editError = "";
|
|
|
|
/// <summary>Origin exposed by the browser that operators use to reach Central.</summary>
|
|
private string CentralUrl => Nav.BaseUri.TrimEnd('/');
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Language.LanguageChanged += OnLanguageChanged;
|
|
await LoadSites();
|
|
}
|
|
|
|
private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged);
|
|
|
|
public void Dispose() => Language.LanguageChanged -= OnLanguageChanged;
|
|
|
|
private async Task LoadSites()
|
|
{
|
|
_loading = true;
|
|
_error = false;
|
|
try
|
|
{
|
|
var result = await Api.GetSitesAsync();
|
|
_sites = result?.Items;
|
|
}
|
|
catch {
|
|
_error = true;
|
|
Snackbar.Add(Text["SitesPage_OperationFailed"], Severity.Error);
|
|
}
|
|
finally { _loading = false; }
|
|
}
|
|
|
|
private bool _confirmDeleteShow;
|
|
private Guid _confirmDeleteId;
|
|
private string _confirmDeleteName = "";
|
|
private SiteCascadeInfo? _cascadeInfo;
|
|
private bool _cascadeInfoLoading;
|
|
|
|
private async Task ConfirmDeleteSite(Guid id, string name)
|
|
{
|
|
_confirmDeleteId = id;
|
|
_confirmDeleteName = name;
|
|
_cascadeInfo = null;
|
|
_cascadeInfoLoading = true;
|
|
_confirmDeleteShow = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
_cascadeInfo = await Api.GetSiteCascadeInfoAsync(id);
|
|
}
|
|
catch
|
|
{
|
|
// If we can't load cascade info, still allow deletion
|
|
_cascadeInfo = null;
|
|
}
|
|
finally
|
|
{
|
|
_cascadeInfoLoading = false;
|
|
}
|
|
}
|
|
|
|
private async Task ExecuteDelete()
|
|
{
|
|
_confirmDeleteShow = false;
|
|
await DeleteSite(_confirmDeleteId, _confirmDeleteName);
|
|
}
|
|
|
|
private void CancelCreate()
|
|
{
|
|
_showCreate = false;
|
|
_creationError = "";
|
|
_createdToken = "";
|
|
_newName = "";
|
|
_newAddress = null;
|
|
_newTimezone = null;
|
|
_newNtfyTopic = null;
|
|
}
|
|
|
|
private async Task ConfirmCreate()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(_newName)) { _creationError = Text["SitesPage_NameRequiredError"]; return; }
|
|
_saving = true;
|
|
_creationError = "";
|
|
try
|
|
{
|
|
var result = await Api.CreateSiteAsync(_newName, _newAddress, _newTimezone, _newNtfyTopic);
|
|
if (!result.Succeeded)
|
|
{
|
|
_creationError = string.IsNullOrWhiteSpace(result.ErrorMessage)
|
|
? Text["SitesPage_CreateError"]
|
|
: result.ErrorMessage;
|
|
return;
|
|
}
|
|
_createdToken = result.Data?.RegistrationToken ?? Text["SitesPage_TokenUnavailable"];
|
|
Snackbar.Add(Text["SitesPage_Created"], Severity.Success);
|
|
await LoadSites();
|
|
}
|
|
catch { _creationError = Text["SitesPage_OperationFailed"]; }
|
|
finally { _saving = false; }
|
|
}
|
|
|
|
private async Task CopyToken(Guid siteId, string siteName)
|
|
{
|
|
_tokenSiteId = siteId;
|
|
_installSiteName = siteName;
|
|
_tokenLoading = true;
|
|
_tokenError = "";
|
|
_generatedToken = "";
|
|
_showInstall = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
var result = await Api.GenerateSiteTokenAsync(siteId);
|
|
if (result is null)
|
|
{
|
|
_tokenError = Text["SitesPage_TokenGenerationError"];
|
|
}
|
|
else
|
|
{
|
|
_generatedToken = result.Token;
|
|
Snackbar.Add(Text["SitesPage_TokenGenerated"], Severity.Success);
|
|
}
|
|
}
|
|
catch {
|
|
_tokenError = Text["SitesPage_OperationFailed"];
|
|
}
|
|
finally
|
|
{
|
|
_tokenLoading = false;
|
|
}
|
|
}
|
|
|
|
private void OpenEdit(SiteItem site)
|
|
{
|
|
_editId = site.Id;
|
|
_editName = site.Name;
|
|
_editAddress = site.Address;
|
|
_editTimezone = site.Timezone;
|
|
_editNtfyTopic = site.NtfyTopic;
|
|
_editAutoUpdate = site.AutoUpdateEnabled;
|
|
_editError = "";
|
|
_showEdit = true;
|
|
}
|
|
|
|
private async Task SaveEdit()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(_editName)) { _editError = Text["SitesPage_NameRequiredError"]; return; }
|
|
_editing = true;
|
|
_editError = "";
|
|
try
|
|
{
|
|
var ok = await Api.UpdateSiteAsync(_editId, _editName, _editAddress, _editTimezone, _editNtfyTopic, _editAutoUpdate);
|
|
if (!ok) { _editError = Text["SitesPage_UpdateError"]; return; }
|
|
Snackbar.Add(Text["SitesPage_Updated"], Severity.Success);
|
|
_showEdit = false;
|
|
await LoadSites();
|
|
}
|
|
catch { _editError = Text["SitesPage_OperationFailed"]; }
|
|
finally { _editing = false; }
|
|
}
|
|
|
|
private Task OnAutoUpdateOverrideChanged(bool? value)
|
|
{
|
|
_editAutoUpdate = value;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private async Task DeleteSite(Guid id, string name)
|
|
{
|
|
if (await Api.DeleteSiteAsync(id))
|
|
{
|
|
Snackbar.Add(string.Format(Language.Culture, Text["SitesPage_Deleted"], name), Severity.Success);
|
|
await LoadSites();
|
|
}
|
|
else
|
|
Snackbar.Add(Text["SitesPage_DeleteError"], Severity.Error);
|
|
}
|
|
}
|