107 lines
3.3 KiB
Plaintext
107 lines
3.3 KiB
Plaintext
@page "/sites/{SiteId:guid}/agents"
|
|
@attribute [Authorize]
|
|
@layout MainLayout
|
|
@inject HeimdallApiClient Api
|
|
@inject ISnackbar Snackbar
|
|
@inject NavigationManager Nav
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-6">
|
|
<MudIcon Icon="@Icons.Material.Filled.Dns" Class="mr-2" />
|
|
Agents du site
|
|
</MudText>
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="@(() => Nav.NavigateTo("/sites"))" Class="mb-4">
|
|
← Retour aux sites
|
|
</MudButton>
|
|
|
|
@if (_loading)
|
|
{
|
|
<MudProgressCircular Indeterminate="true" />
|
|
}
|
|
else if (_error)
|
|
{
|
|
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
|
<MudText>Erreur lors du chargement des agents.</MudText>
|
|
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadAgents" Class="mt-2">
|
|
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
|
</MudButton>
|
|
</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudTable Items="@_agents" Hover="true" Striped="true" Elevation="2">
|
|
<HeaderContent>
|
|
<MudTh>Nom</MudTh>
|
|
<MudTh>Hostname</MudTh>
|
|
<MudTh>Version</MudTh>
|
|
<MudTh>Statut</MudTh>
|
|
<MudTh>Dernier heartbeat</MudTh>
|
|
<MudTh>IP</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Nom">
|
|
<MudLink Href="@($"/agents/{context.Id}")">@context.Name</MudLink>
|
|
</MudTd>
|
|
<MudTd DataLabel="Hostname">@context.Hostname</MudTd>
|
|
<MudTd DataLabel="Version">@context.Version</MudTd>
|
|
<MudTd DataLabel="Statut">
|
|
<MudText Color="@GetStatusColor(context.Status)" Typo="Typo.body2">
|
|
@GetStatusIcon(context.Status) @context.Status
|
|
</MudText>
|
|
</MudTd>
|
|
<MudTd DataLabel="Dernier heartbeat">
|
|
@(context.LastHeartbeat?.ToString("g") ?? "Jamais")
|
|
</MudTd>
|
|
<MudTd DataLabel="IP">@context.PublicIp</MudTd>
|
|
</RowTemplate>
|
|
<NoRecordsContent>
|
|
<MudText Align="Align.Center" Class="py-4">
|
|
Aucun agent enregistré. Utilisez un token d'enregistrement pour connecter un agent.
|
|
</MudText>
|
|
</NoRecordsContent>
|
|
</MudTable>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public Guid SiteId { get; set; }
|
|
|
|
private IReadOnlyList<AgentItem>? _agents;
|
|
private bool _loading = true;
|
|
private bool _error;
|
|
|
|
protected override async Task OnInitializedAsync() => await LoadAgents();
|
|
|
|
private async Task LoadAgents()
|
|
{
|
|
_loading = true;
|
|
_error = false;
|
|
try
|
|
{
|
|
var result = await Api.GetAgentsBySiteAsync(SiteId);
|
|
_agents = result?.Items;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_error = true;
|
|
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
|
}
|
|
finally { _loading = false; }
|
|
}
|
|
|
|
private static Color GetStatusColor(string status) => status switch
|
|
{
|
|
"Online" => Color.Success,
|
|
"Offline" => Color.Error,
|
|
"Error" => Color.Warning,
|
|
_ => Color.Default
|
|
};
|
|
|
|
private static string GetStatusIcon(string status) => status switch
|
|
{
|
|
"Online" => "●",
|
|
"Offline" => "○",
|
|
"Error" => "⚠",
|
|
_ => "?"
|
|
};
|
|
}
|