130 lines
4.5 KiB
Plaintext
130 lines
4.5 KiB
Plaintext
@page "/cameras/{Id:guid}"
|
|||
|
|
@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.Videocam" Class="mr-2" />
|
||
|
|
Caméra : @_camera?.Name
|
||
|
|
</MudText>
|
||
|
|
|
||
|
|
@if (_loading)
|
||
|
|
{
|
||
|
|
<MudProgressCircular Indeterminate="true" />
|
||
|
|
}
|
||
|
|
else if (_camera is null)
|
||
|
|
{
|
||
|
|
<MudAlert Severity="Severity.Warning">Caméra introuvable</MudAlert>
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
<MudPaper Elevation="2" Class="pa-6 mb-6" Style="border-radius: 12px;">
|
||
|
|
<MudText Typo="Typo.h6" Class="mb-4">Informations</MudText>
|
||
|
|
<MudGrid>
|
||
|
|
<MudItem xs="12" sm="6">
|
||
|
|
<MudTextField @bind-Value="_editName" Label="Nom" Variant="Variant.Outlined" Class="mb-4" Immediate="true" />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" sm="6">
|
||
|
|
<MudTextField @bind-Value="_editRtspUrl" Label="URL RTSP" Variant="Variant.Outlined" Class="mb-4" Immediate="true" />
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" sm="6">
|
||
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Fabricant</MudText>
|
||
|
|
<MudText Typo="Typo.body1">@(_camera.Manufacturer ?? "-")</MudText>
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" sm="6">
|
||
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Modèle</MudText>
|
||
|
|
<MudText Typo="Typo.body1">@(_camera.Model ?? "-")</MudText>
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" sm="6">
|
||
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Statut</MudText>
|
||
|
|
<MudText Color="@GetStatusColor(_camera.Status)">
|
||
|
|
@GetStatusIcon(_camera.Status) @_camera.Status
|
||
|
|
</MudText>
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" sm="6">
|
||
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Créée le</MudText>
|
||
|
|
<MudText Typo="Typo.body1">@_camera.CreatedAt.ToString("g")</MudText>
|
||
|
|
</MudItem>
|
||
|
|
</MudGrid>
|
||
|
|
</MudPaper>
|
||
|
|
|
||
|
|
@if (!string.IsNullOrEmpty(_editError))
|
||
|
|
{
|
||
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_editError</MudAlert>
|
||
|
|
}
|
||
|
|
@if (!string.IsNullOrEmpty(_editSuccess))
|
||
|
|
{
|
||
|
|
<MudAlert Severity="Severity.Success" Class="mb-4">@_editSuccess</MudAlert>
|
||
|
|
}
|
||
|
|
|
||
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@SaveCamera" Disabled="@_saving" Class="mr-2">
|
||
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
||
|
|
<MudIcon Icon="@Icons.Material.Filled.Save" Class="mr-1" /> Enregistrer
|
||
|
|
</MudButton>
|
||
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="@(() => Nav.NavigateTo($"/sites/{_camera.SiteId}/cameras"))">
|
||
|
|
← Retour aux caméras
|
||
|
|
</MudButton>
|
||
|
|
}
|
||
|
|
|
||
|
|
@code {
|
||
|
|
[Parameter] public Guid Id { get; set; }
|
||
|
|
|
||
|
|
private CameraItem? _camera;
|
||
|
|
private bool _loading = true;
|
||
|
|
private bool _saving;
|
||
|
|
private string _editName = "";
|
||
|
|
private string? _editRtspUrl;
|
||
|
|
private string _editError = "";
|
||
|
|
private string _editSuccess = "";
|
||
|
|
|
||
|
|
protected override async Task OnInitializedAsync()
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
_camera = await Api.GetCameraAsync(Id);
|
||
|
|
if (_camera is not null)
|
||
|
|
{
|
||
|
|
_editName = _camera.Name;
|
||
|
|
_editRtspUrl = _camera.RtspUrl;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
||
|
|
finally { _loading = false; }
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task SaveCamera()
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(_editName)) { _editError = "Le nom est requis"; return; }
|
||
|
|
_saving = true;
|
||
|
|
_editError = "";
|
||
|
|
_editSuccess = "";
|
||
|
|
try
|
||
|
|
{
|
||
|
|
if (await Api.UpdateCameraAsync(Id, _editName, _editRtspUrl, null))
|
||
|
|
{
|
||
|
|
_editSuccess = "Caméra mise à jour";
|
||
|
|
if (_camera is not null) _camera.Name = _editName;
|
||
|
|
}
|
||
|
|
else _editError = "Erreur lors de la mise à jour";
|
||
|
|
}
|
||
|
|
catch (Exception ex) { _editError = $"Erreur : {ex.Message}"; }
|
||
|
|
finally { _saving = false; }
|
||
|
|
}
|
||
|
|
|
||
|
|
private static Color GetStatusColor(string status) => status switch
|
||
|
|
{
|
||
|
|
"Online" => Color.Success,
|
||
|
|
"Offline" => Color.Error,
|
||
|
|
"Disabled" => Color.Default,
|
||
|
|
_ => Color.Warning
|
||
|
|
};
|
||
|
|
|
||
|
|
private static string GetStatusIcon(string status) => status switch
|
||
|
|
{
|
||
|
|
"Online" => "●",
|
||
|
|
"Offline" => "○",
|
||
|
|
_ => "?"
|
||
|
|
};
|
||
|
|
}
|