Heimdall Gitea / Build and tests (pull_request) Failing after 2m10s
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
400 lines
18 KiB
Plaintext
400 lines
18 KiB
Plaintext
@page "/sites/{Id:guid}"
|
|
@attribute [Authorize]
|
|
@layout MainLayout
|
|
@inject HeimdallApiClient Api
|
|
@inject ISnackbar Snackbar
|
|
@inject NavigationManager Nav
|
|
@inject IJSRuntime Js
|
|
@inject UiText Text
|
|
@inject UiLanguageService Language
|
|
@implements IDisposable
|
|
|
|
<MudText Typo="Typo.h1" Class="mb-6">
|
|
<i class="fas fa-video mr-2"></i>
|
|
@Text["SiteDetail_TitlePrefix"] @_site?.Name
|
|
</MudText>
|
|
|
|
@if (_loading)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" />
|
|
}
|
|
else if (_site is null)
|
|
{
|
|
<MudAlert Severity="Severity.Warning">@Text["SiteDetail_NotFound"]</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
|
<MudText Typo="Typo.h6" Class="mb-4">@Text["SiteDetail_Information"]</MudText>
|
|
<MudGrid>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["SiteDetail_Name"]</MudText>
|
|
<MudText Typo="Typo.body1">@_site.Name</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["SiteDetail_Address"]</MudText>
|
|
<MudText Typo="Typo.body1">@(_site.Address ?? "-")</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["SiteDetail_Timezone"]</MudText>
|
|
<MudText Typo="Typo.body1">@_site.Timezone</MudText>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["SiteDetail_Status"]</MudText>
|
|
<MudText Color="@(_site.Enabled ? Color.Success : Color.Default)">
|
|
@(_site.Enabled ? "● " + Text["SiteDetail_Active"] : "○ " + Text["SiteDetail_Inactive"])
|
|
</MudText>
|
|
</MudItem>
|
|
</MudGrid>
|
|
</MudPaper>
|
|
|
|
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
|
<div class="d-flex flex-wrap justify-space-between align-center mb-4">
|
|
<MudText Typo="Typo.h6">@Text["SiteDetail_CapacityTitle"]</MudText>
|
|
<MudButtonGroup Variant="Variant.Outlined" Color="Color.Primary">
|
|
<MudButton OnClick="@(() => LoadCapacityHistoryAsync("24h"))" Disabled="@(_capacityHistoryLoading || _capacityRange == "24h")">@Text["SiteDetail_Range24h"]</MudButton>
|
|
<MudButton OnClick="@(() => LoadCapacityHistoryAsync("7d"))" Disabled="@(_capacityHistoryLoading || _capacityRange == "7d")">@Text["SiteDetail_Range7d"]</MudButton>
|
|
</MudButtonGroup>
|
|
</div>
|
|
@if (_capacityHistoryLoading)
|
|
{
|
|
<MudProgressLinear Indeterminate="true" />
|
|
}
|
|
else if (_capacityHistoryError)
|
|
{
|
|
<MudAlert Severity="Severity.Error">@Text["SiteDetail_CapacityLoadError"]</MudAlert>
|
|
}
|
|
else if (_capacityHistory.Count == 0 || !_capacityHistory.Any(point => point.ReportingAgents > 0))
|
|
{
|
|
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">@Text["SiteDetail_CapacityEmpty"]</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
var latestCapacity = _capacityHistory.LastOrDefault(point => point.ReportingAgents > 0);
|
|
@if (latestCapacity is not null)
|
|
{
|
|
@if (latestCapacity.InventoryObservedAtUtc.HasValue)
|
|
{
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mb-2">
|
|
@Text["SiteDetail_LastInventory"] @latestCapacity.InventoryObservedAtUtc.Value.ToLocalTime().ToString("g", Language.Culture).
|
|
</MudText>
|
|
}
|
|
<MudGrid Class="mb-3">
|
|
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">@Text["SiteDetail_ReportingAgents"]</MudText><MudText Typo="Typo.h6">@latestCapacity.ReportingAgents</MudText></MudItem>
|
|
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">@Text["SiteDetail_LogicalCores"]</MudText><MudText Typo="Typo.h6">@(latestCapacity.LogicalCores?.ToString() ?? "—")</MudText></MudItem>
|
|
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">@Text["SiteDetail_TotalRam"]</MudText><MudText Typo="Typo.h6">@FormatCapacity(latestCapacity.MemoryCapacityBytes)</MudText></MudItem>
|
|
<MudItem xs="6" sm="3"><MudText Typo="Typo.caption" Color="Color.Secondary">@Text["SiteDetail_UsedRam"]</MudText><MudText Typo="Typo.h6">@FormatCapacity(latestCapacity.MemoryUsedBytes)</MudText></MudItem>
|
|
</MudGrid>
|
|
}
|
|
<MudGrid>
|
|
<MudItem xs="12" md="6"><MetricHistoryChart Title="@Text["SiteDetail_AverageCpu"]" Points="@CapacitySeries(point => point.AverageCpuUsagePercent)" Minimum="0" Maximum="100" /></MudItem>
|
|
<MudItem xs="12" md="6"><MetricHistoryChart Title="@Text["SiteDetail_SystemMemory"]" Points="@CapacitySeries(MemoryCapacityUsedPercent)" Minimum="0" Maximum="100" /></MudItem>
|
|
<MudItem xs="12" md="6"><MetricHistoryChart Title="@Text["SiteDetail_AverageDisk"]" Points="@CapacitySeries(point => point.AverageDiskUsagePercent)" Minimum="0" Maximum="100" /></MudItem>
|
|
<MudItem xs="12" md="6"><MetricHistoryChart Title="@Text["SiteDetail_AverageGpuTemp"]" Points="@CapacitySeries(point => point.AverageGpuTemperatureCelsius)" Unit=" °C" /></MudItem>
|
|
</MudGrid>
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-2">
|
|
@Text["SiteDetail_MissingSamples"]
|
|
</MudText>
|
|
}
|
|
</MudPaper>
|
|
|
|
@* Token d'enregistrement *@
|
|
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
|
<MudText Typo="Typo.h6" Class="mb-4">
|
|
<MudIcon Icon="@Icons.Material.Filled.Key" Class="mr-1" />
|
|
@Text["SiteDetail_RegistrationToken"]
|
|
</MudText>
|
|
|
|
@if (!string.IsNullOrEmpty(_generatedToken))
|
|
{
|
|
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
|
<strong>@Text["SiteDetail_RegistrationToken"]</strong><br />
|
|
<code class="hmd-code-block mt-2">
|
|
@_generatedToken
|
|
</code>
|
|
<MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
|
⚠ @Text["SiteDetail_TokenCopyWarning"]
|
|
</MudText>
|
|
<MudText Typo="Typo.body2" Class="mt-1">
|
|
@Text["SiteDetail_Expires"] @_tokenExpiresAt.ToString("g", Language.Culture)
|
|
</MudText>
|
|
</MudAlert>
|
|
}
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Warning" OnClick="@GenerateToken" Disabled="@_generating">
|
|
@if (_generating) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" />
|
|
@(!string.IsNullOrEmpty(_generatedToken) ? Text["SiteDetail_Regenerate"] : Text["SiteDetail_GenerateToken"])
|
|
</MudButton>
|
|
|
|
@if (!string.IsNullOrEmpty(_generatedToken))
|
|
{
|
|
<SiteInstallPanel SiteName="@_site.Name" SiteToken="@_generatedToken"
|
|
CentralUrl="@CentralUrl" />
|
|
}
|
|
</MudPaper>
|
|
|
|
@* Identifiants caméras (découverte automatique) *@
|
|
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
|
<div class="d-flex justify-space-between align-center mb-4">
|
|
<MudText Typo="Typo.h6">
|
|
<MudIcon Icon="@Icons.Material.Filled.Lock" Class="mr-1" />
|
|
@Text["SiteDetail_Credentials"]
|
|
</MudText>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
|
OnClick="@(() => _showCredentialDialog = true)">
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["SiteDetail_Add"]
|
|
</MudButton>
|
|
</div>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
@Text["SiteDetail_CredentialDescription"]
|
|
</MudText>
|
|
|
|
@if (_credentialsLoading)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" Size="Size.Small" />
|
|
}
|
|
else if (_credentials.Count == 0)
|
|
{
|
|
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
|
@Text["SiteDetail_NoCredentials"]
|
|
</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudTable Items="@_credentials" Hover="true" Dense="true">
|
|
<HeaderContent>
|
|
<MudTh>@Text["SiteDetail_Label"]</MudTh>
|
|
<MudTh>@Text["SiteDetail_Username"]</MudTh>
|
|
<MudTh>@Text["SiteDetail_LastUsed"]</MudTh>
|
|
<MudTh></MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="@Text["SiteDetail_Label"]">@context.Label</MudTd>
|
|
<MudTd DataLabel="@Text["SiteDetail_Username"]"><code>@context.Username</code></MudTd>
|
|
<MudTd DataLabel="@Text["SiteDetail_LastUsed"]">
|
|
@(context.LastUsedAt?.ToString("g", Language.Culture) ?? Text["SiteDetail_Never"])
|
|
</MudTd>
|
|
<MudTd DataLabel="@Text["SiteDetail_Actions"]">
|
|
<MudTooltip Text="@Text["SiteDetail_DeleteCredentialTooltip"]">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small"
|
|
Color="Color.Error" aria-label="@Text["SiteDetail_DeleteCredential"]"
|
|
OnClick="@(() => DeleteCredential(context))" />
|
|
</MudTooltip>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
}
|
|
</MudPaper>
|
|
|
|
@* Navigation rapide *@
|
|
<MudText Typo="Typo.h6" Class="mb-4">@Text["SiteDetail_Management"]</MudText>
|
|
<MudGrid>
|
|
<MudItem xs="12" sm="6">
|
|
<MudPaper Elevation="3" Class="pa-4 text-center" Style="border-radius: 12px; cursor: pointer;"
|
|
@onclick="@(() => Nav.NavigateTo($"/sites/{Id}/cameras"))">
|
|
<MudIcon Icon="@Icons.Material.Filled.Videocam" Size="Size.Large" Color="Color.Primary" />
|
|
<MudText Typo="Typo.h6" Class="mt-2">@Text["SiteDetail_Cameras"]</MudText>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["SiteDetail_ManageCameras"]</MudText>
|
|
</MudPaper>
|
|
</MudItem>
|
|
<MudItem xs="12" sm="6">
|
|
<MudPaper Elevation="3" Class="pa-4 text-center" Style="border-radius: 12px; cursor: pointer;"
|
|
@onclick="@(() => Nav.NavigateTo($"/sites/{Id}/agents"))">
|
|
<MudIcon Icon="@Icons.Material.Filled.Dns" Size="Size.Large" Color="Color.Secondary" />
|
|
<MudText Typo="Typo.h6" Class="mt-2">@Text["SiteDetail_Agents"]</MudText>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["SiteDetail_ViewAgents"]</MudText>
|
|
</MudPaper>
|
|
</MudItem>
|
|
</MudGrid>
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Default" Class="mt-4"
|
|
OnClick="@(() => Nav.NavigateTo("/sites"))">
|
|
@Text["SiteDetail_BackToSites"]
|
|
</MudButton>
|
|
}
|
|
|
|
@* ─── Ajout d'identifiant caméra ─────────────────────────────────── *@
|
|
<MudOverlay Visible="@_showCredentialDialog" OnClick="@(() => _showCredentialDialog = false)" />
|
|
<MudDialog @bind-Visible="_showCredentialDialog">
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["SiteDetail_AddCredentialTitle"]</MudText></TitleContent>
|
|
<DialogContent>
|
|
<MudTextField @bind-Value="_newCredLabel" Label="@Text["SiteDetail_LabelRequired"]" Variant="Variant.Outlined"
|
|
Class="mb-4" Immediate="true"
|
|
HelperText="@Text["SiteDetail_CredentialHint"]" />
|
|
<MudTextField @bind-Value="_newCredUsername" Label="@Text["SiteDetail_UsernameRequired"]" Variant="Variant.Outlined"
|
|
Class="mb-4" Immediate="true" />
|
|
<MudTextField @bind-Value="_newCredPassword" Label="@Text["SiteDetail_PasswordRequired"]" Variant="Variant.Outlined"
|
|
InputType="InputType.Password" Class="mb-4" Immediate="true" />
|
|
@if (!string.IsNullOrEmpty(_credentialError))
|
|
{
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_credentialError</MudAlert>
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showCredentialDialog = false)">@Text["SiteDetail_Cancel"]</MudButton>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@AddCredential"
|
|
Disabled="@(_savingCredential || string.IsNullOrWhiteSpace(_newCredLabel) || string.IsNullOrWhiteSpace(_newCredUsername) || string.IsNullOrWhiteSpace(_newCredPassword))">
|
|
@if (_savingCredential) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
|
@Text["SiteDetail_Add"]
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[Parameter] public Guid Id { get; set; }
|
|
|
|
private SiteItem? _site;
|
|
private bool _loading = true;
|
|
private List<SiteCapacityHistoryPoint> _capacityHistory = [];
|
|
private bool _capacityHistoryLoading;
|
|
private bool _capacityHistoryError;
|
|
private string _capacityRange = "24h";
|
|
private bool _generating;
|
|
private string? _generatedToken;
|
|
private DateTime _tokenExpiresAt;
|
|
private string _dockerComposeSnippet = "";
|
|
|
|
// ── Identifiants caméras ──────────────────────────────────────
|
|
private List<SiteCredentialItem> _credentials = [];
|
|
private bool _credentialsLoading = true;
|
|
private bool _showCredentialDialog;
|
|
private bool _savingCredential;
|
|
private string _newCredLabel = "";
|
|
private string _newCredUsername = "";
|
|
private string _newCredPassword = "";
|
|
private string _credentialError = "";
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Language.LanguageChanged += OnLanguageChanged;
|
|
try
|
|
{
|
|
_site = await Api.GetSiteAsync(Id);
|
|
if (_site is not null)
|
|
await LoadCapacityHistoryAsync(_capacityRange);
|
|
}
|
|
catch { Snackbar.Add(Text["SiteDetail_OperationFailed"], Severity.Error); }
|
|
finally { _loading = false; }
|
|
|
|
await LoadCredentials();
|
|
}
|
|
|
|
private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged);
|
|
|
|
public void Dispose() => Language.LanguageChanged -= OnLanguageChanged;
|
|
|
|
private async Task LoadCapacityHistoryAsync(string range)
|
|
{
|
|
_capacityRange = range;
|
|
_capacityHistoryLoading = true;
|
|
_capacityHistoryError = false;
|
|
try
|
|
{
|
|
_capacityHistory = await Api.GetSiteCapacityHistoryAsync(Id, range) ?? [];
|
|
}
|
|
catch
|
|
{
|
|
_capacityHistoryError = true;
|
|
_capacityHistory = [];
|
|
}
|
|
finally { _capacityHistoryLoading = false; }
|
|
}
|
|
|
|
private List<MetricChartPoint> CapacitySeries(Func<SiteCapacityHistoryPoint, double?> selector)
|
|
=> _capacityHistory.Select(point => new MetricChartPoint(point.TimestampUtc, selector(point))).ToList();
|
|
|
|
private static double? MemoryCapacityUsedPercent(SiteCapacityHistoryPoint point)
|
|
=> point.MemoryUsedBytes is { } used && point.MemoryCapacityBytes is > 0
|
|
? Math.Clamp(100d * used / point.MemoryCapacityBytes.Value, 0, 100)
|
|
: null;
|
|
|
|
private string FormatCapacity(long? bytes)
|
|
=> bytes is { } value ? FormatBytes(value) : "—";
|
|
|
|
private string FormatBytes(long bytes)
|
|
{
|
|
string[] units = ["B", "KB", "MB", "GB", "TB"];
|
|
var size = (double)bytes;
|
|
var unit = 0;
|
|
while (size >= 1024 && unit < units.Length - 1)
|
|
{
|
|
size /= 1024;
|
|
unit++;
|
|
}
|
|
return size.ToString("0.#", Language.Culture) + " " + units[unit];
|
|
}
|
|
|
|
private async Task LoadCredentials()
|
|
{
|
|
_credentialsLoading = true;
|
|
try
|
|
{
|
|
_credentials = await Api.GetSiteCredentialsAsync(Id);
|
|
}
|
|
catch { Snackbar.Add(Text["SiteDetail_OperationFailed"], Severity.Error); }
|
|
finally { _credentialsLoading = false; }
|
|
}
|
|
|
|
private async Task AddCredential()
|
|
{
|
|
_savingCredential = true;
|
|
_credentialError = "";
|
|
try
|
|
{
|
|
var result = await Api.AddSiteCredentialAsync(Id, _newCredLabel, _newCredUsername, _newCredPassword);
|
|
if (result is null)
|
|
{
|
|
_credentialError = Text["SiteDetail_CredentialAddError"];
|
|
return;
|
|
}
|
|
Snackbar.Add(Text["SiteDetail_CredentialAdded"], Severity.Success);
|
|
_showCredentialDialog = false;
|
|
_newCredLabel = "";
|
|
_newCredUsername = "";
|
|
_newCredPassword = "";
|
|
await LoadCredentials();
|
|
}
|
|
catch { _credentialError = Text["SiteDetail_OperationFailed"]; }
|
|
finally { _savingCredential = false; }
|
|
}
|
|
|
|
private async Task DeleteCredential(SiteCredentialItem credential)
|
|
{
|
|
if (await Api.DeleteSiteCredentialAsync(Id, credential.Id))
|
|
{
|
|
Snackbar.Add(string.Format(Language.Culture, Text["SiteDetail_CredentialDeleted"], credential.Label), Severity.Success);
|
|
await LoadCredentials();
|
|
}
|
|
else
|
|
{
|
|
Snackbar.Add(Text["SiteDetail_DeleteError"], Severity.Error);
|
|
}
|
|
}
|
|
|
|
private async Task GenerateToken()
|
|
{
|
|
_generating = true;
|
|
try
|
|
{
|
|
var result = await Api.GenerateSiteTokenAsync(Id);
|
|
if (result is null)
|
|
{
|
|
Snackbar.Add(Text["SiteDetail_TokenError"], Severity.Error);
|
|
return;
|
|
}
|
|
_generatedToken = result.Token;
|
|
_tokenExpiresAt = result.ExpiresAt;
|
|
_dockerComposeSnippet = GenerateDockerComposeSnippet(_generatedToken);
|
|
Snackbar.Add(Text["SiteDetail_TokenGenerated"], Severity.Warning);
|
|
}
|
|
catch { Snackbar.Add(Text["SiteDetail_OperationFailed"], Severity.Error); }
|
|
finally { _generating = false; }
|
|
}
|
|
|
|
private string GenerateDockerComposeSnippet(string token) => "";
|
|
|
|
/// <summary>URL publique du serveur Heimdall (utilisée dans le compose généré).</summary>
|
|
private string CentralUrl => "https://heimdall.tordais.cc";
|
|
}
|