162 lines
6.2 KiB
Plaintext
162 lines
6.2 KiB
Plaintext
@page "/sites"
|
|||
|
|
@attribute [Authorize]
|
||
|
|
@layout MainLayout
|
||
|
|
@inject HeimdallApiClient Api
|
||
|
|
@inject ISnackbar Snackbar
|
||
|
|
|
||
|
|
<MudText Typo="Typo.h4" Class="mb-6">
|
||
|
|
<MudIcon Icon="@Icons.Material.Filled.Videocam" Class="mr-2" />
|
||
|
|
Sites
|
||
|
|
</MudText>
|
||
|
|
|
||
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)" Class="mb-4">
|
||
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> Nouveau site
|
||
|
|
</MudButton>
|
||
|
|
|
||
|
|
@if (_loading)
|
||
|
|
{
|
||
|
|
<MudProgressCircular Indeterminate="true" />
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
<MudTable Items="@_sites" Hover="true" Striped="true" Elevation="2">
|
||
|
|
<HeaderContent>
|
||
|
|
<MudTh>Nom</MudTh>
|
||
|
|
<MudTh>Adresse</MudTh>
|
||
|
|
<MudTh>Fuseau</MudTh>
|
||
|
|
<MudTh>Statut</MudTh>
|
||
|
|
<MudTh>Actions</MudTh>
|
||
|
|
</HeaderContent>
|
||
|
|
<RowTemplate>
|
||
|
|
<MudTd DataLabel="Nom"><MudLink Href="@($"/sites/{context.Id}")">@context.Name</MudLink></MudTd>
|
||
|
|
<MudTd DataLabel="Adresse">@context.Address</MudTd>
|
||
|
|
<MudTd DataLabel="Fuseau">@context.Timezone</MudTd>
|
||
|
|
<MudTd DataLabel="Statut">
|
||
|
|
<MudText Color="@(context.Enabled ? Color.Success : Color.Default)" Typo="Typo.body2">
|
||
|
|
@(context.Enabled ? "● Actif" : "○ Inactif")
|
||
|
|
</MudText>
|
||
|
|
</MudTd>
|
||
|
|
<MudTd DataLabel="Actions">
|
||
|
|
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy" Size="Size.Small"
|
||
|
|
OnClick="@(() => CopyToken(context.Id))" />
|
||
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
||
|
|
OnClick="@(() => DeleteSite(context.Id, context.Name))" />
|
||
|
|
</MudTd>
|
||
|
|
</RowTemplate>
|
||
|
|
<NoRecordsContent>
|
||
|
|
<MudText Align="Align.Center" Class="py-4">Aucun site.</MudText>
|
||
|
|
</NoRecordsContent>
|
||
|
|
</MudTable>
|
||
|
|
}
|
||
|
|
|
||
|
|
@if (_showCreate)
|
||
|
|
{
|
||
|
|
<MudOverlay Visible="@_showCreate" OnClick="@(() => _showCreate = false)" />
|
||
|
|
<MudDialog @bind-Visible="_showCreate">
|
||
|
|
<TitleContent><MudText Typo="Typo.h6">Nouveau site</MudText></TitleContent>
|
||
|
|
<DialogContent>
|
||
|
|
<MudTextField @bind-Value="_newName" Label="Nom du site *" Variant="Variant.Outlined"
|
||
|
|
Class="mb-4" Required="true" Immediate="true" />
|
||
|
|
<MudTextField @bind-Value="_newAddress" Label="Adresse" Variant="Variant.Outlined" Class="mb-4" />
|
||
|
|
<MudTextField @bind-Value="_newTimezone" Label="Fuseau horaire" Variant="Variant.Outlined"
|
||
|
|
Class="mb-4" HelperText="Ex: Europe/Paris (défaut: UTC)" />
|
||
|
|
@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>Token d'enregistrement :</strong><br />
|
||
|
|
<code class="d-block mt-2 p-2" style="background:#f5f5f5;word-break:break-all;font-size:0.9rem;">
|
||
|
|
@_createdToken
|
||
|
|
</code>
|
||
|
|
<MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
||
|
|
⚠ Copiez ce token maintenant. Il ne sera plus affiché.
|
||
|
|
</MudText>
|
||
|
|
</MudAlert>
|
||
|
|
}
|
||
|
|
</DialogContent>
|
||
|
|
<DialogActions>
|
||
|
|
<MudButton Variant="Variant.Text" OnClick="@CancelCreate">Annuler</MudButton>
|
||
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ConfirmCreate"
|
||
|
|
Disabled="@IsCreateDisabled">
|
||
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
||
|
|
@(!string.IsNullOrEmpty(_createdToken) ? "Fermer" : "Créer")
|
||
|
|
</MudButton>
|
||
|
|
</DialogActions>
|
||
|
|
</MudDialog>
|
||
|
|
}
|
||
|
|
|
||
|
|
@code {
|
||
|
|
private IReadOnlyList<SiteItem>? _sites;
|
||
|
|
private bool _loading = true;
|
||
|
|
private bool _showCreate;
|
||
|
|
private bool _saving;
|
||
|
|
private string _newName = "";
|
||
|
|
private string? _newAddress;
|
||
|
|
private string? _newTimezone;
|
||
|
|
private string _creationError = "";
|
||
|
|
private string _createdToken = "";
|
||
|
|
private bool IsCreateDisabled => _saving || !string.IsNullOrEmpty(_createdToken);
|
||
|
|
|
||
|
|
protected override async Task OnInitializedAsync() => await LoadSites();
|
||
|
|
|
||
|
|
private async Task LoadSites()
|
||
|
|
{
|
||
|
|
_loading = true;
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var result = await Api.GetSitesAsync();
|
||
|
|
_sites = result?.Items;
|
||
|
|
}
|
||
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||
|
|
finally { _loading = false; }
|
||
|
|
}
|
||
|
|
|
||
|
|
private void CancelCreate()
|
||
|
|
{
|
||
|
|
_showCreate = false;
|
||
|
|
_creationError = "";
|
||
|
|
_createdToken = "";
|
||
|
|
_newName = "";
|
||
|
|
_newAddress = null;
|
||
|
|
_newTimezone = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task ConfirmCreate()
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(_newName)) { _creationError = "Le nom est requis"; return; }
|
||
|
|
_saving = true;
|
||
|
|
_creationError = "";
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var result = await Api.CreateSiteAsync(_newName, _newAddress, _newTimezone);
|
||
|
|
if (result is null) { _creationError = "Erreur lors de la création"; return; }
|
||
|
|
_createdToken = result.RegistrationToken ?? "Token non disponible";
|
||
|
|
Snackbar.Add("Site créé avec succès", Severity.Success);
|
||
|
|
await LoadSites();
|
||
|
|
}
|
||
|
|
catch (Exception ex) { _creationError = $"Erreur : {ex.Message}"; }
|
||
|
|
finally { _saving = false; }
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task CopyToken(Guid siteId)
|
||
|
|
{
|
||
|
|
Snackbar.Add("Génération du token...", Severity.Info);
|
||
|
|
// For MVP, the token is generated at creation time
|
||
|
|
// A dedicated token generation endpoint can be called here
|
||
|
|
await Task.CompletedTask;
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task DeleteSite(Guid id, string name)
|
||
|
|
{
|
||
|
|
if (await Api.DeleteSiteAsync(id))
|
||
|
|
{
|
||
|
|
Snackbar.Add($"Site \"{name}\" supprimé", Severity.Success);
|
||
|
|
await LoadSites();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
Snackbar.Add("Erreur lors de la suppression", Severity.Error);
|
||
|
|
}
|
||
|
|
}
|