2026-07-17 06:30:09 +00:00
|
|
|
@page "/sites/{SiteId:guid}/cameras"
|
|
|
|
|
@attribute [Authorize]
|
|
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
@inject NavigationManager Nav
|
2026-10-25 05:59:18 +01:00
|
|
|
@inject UiText Text
|
|
|
|
|
@inject UiLanguageService Language
|
|
|
|
|
@implements IDisposable
|
2026-07-17 06:30:09 +00:00
|
|
|
|
2026-08-10 22:53:21 +02:00
|
|
|
<MudText Typo="Typo.h1" Class="mb-2">
|
2026-07-27 20:11:31 +00:00
|
|
|
<i class="fas fa-video mr-2"></i>
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_Title"]
|
2026-07-17 06:30:09 +00:00
|
|
|
</MudText>
|
2026-08-10 22:53:21 +02:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
|
|
|
@if (_cameras is not null)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
@string.Format(Language.Culture, Text["CamerasPage_CameraCount"], _cameras.Count) <span class="mx-1">·</span>
|
|
|
|
|
@string.Format(Language.Culture, Text["CamerasPage_OnlineCount"], _cameras.Count(c => c.Status == "Online"))
|
2026-08-10 22:53:21 +02:00
|
|
|
}
|
|
|
|
|
</MudText>
|
2026-07-17 06:30:09 +00:00
|
|
|
|
2026-08-10 22:53:21 +02:00
|
|
|
<div class="d-flex align-center mb-4">
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Default" OnClick="@(() => Nav.NavigateTo("/sites"))" Class="mr-2">
|
2026-08-10 22:53:21 +02:00
|
|
|
← Retour aux sites
|
|
|
|
|
</MudButton>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTooltip Text="@Text["CamerasPage_Refresh"]">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Color="Color.Inherit" aria-label="@Text["CamerasPage_Refresh"]"
|
2026-08-26 17:24:15 +02:00
|
|
|
OnClick="@RefreshCurrentTab" />
|
2026-08-10 22:53:21 +02:00
|
|
|
</MudTooltip>
|
|
|
|
|
</div>
|
2026-07-17 06:30:09 +00:00
|
|
|
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudTabs Elevation="0" Rounded="true" ApplyEffectsToContainer="true" PanelClass="pa-0" @bind-ActiveIndex="_activeTab">
|
|
|
|
|
@* ─── Onglet 1 : Caméras ──────────────────────────────────── *@
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTabPanel Text="@Text["CamerasPage_CamerasTab"]" Icon="@Icons.Material.Filled.Videocam">
|
2026-08-26 17:24:15 +02:00
|
|
|
<div class="pa-4">
|
|
|
|
|
<div class="d-flex align-center mb-4">
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["CamerasPage_AddCamera"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@if (_loadingCameras)
|
2026-08-10 22:53:21 +02:00
|
|
|
{
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudGrid>
|
|
|
|
|
@for (var i = 0; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
<MudItem xs="12" sm="6" md="4" xl="3">
|
|
|
|
|
<MudPaper Elevation="0" Style="border-radius: var(--hmd-radius-lg);">
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="140px" />
|
|
|
|
|
<div class="pa-3">
|
|
|
|
|
<MudSkeleton Width="60%" />
|
|
|
|
|
<MudSkeleton Width="40%" Height="16px" />
|
|
|
|
|
</div>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
</MudItem>
|
|
|
|
|
}
|
|
|
|
|
</MudGrid>
|
2026-08-10 22:53:21 +02:00
|
|
|
}
|
2026-08-26 17:24:15 +02:00
|
|
|
else if (_camerasError)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Variant="Variant.Filled" Class="mt-4">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText>@Text["CamerasPage_LoadError"]</MudText>
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@(() => LoadCameras(silent: false))" Class="mt-2">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> @Text["CamerasPage_Retry"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else if (_cameras is null || _cameras.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
<MudPaper Elevation="0" Class="pa-8 text-center" Style="border-radius: var(--hmd-radius-lg); border: 1px dashed var(--mud-palette-lines-default);">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Videocam" Size="Size.Large" Color="Color.Secondary" />
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.h6" Color="Color.Secondary" Class="mt-4">@Text["CamerasPage_NoCameras"]</MudText>
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_NoCamerasHelp"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(() => _showCreate = true)">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["CamerasPage_AddCamera"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudContainer MaxWidth="MaxWidth.False" Class="px-0">
|
|
|
|
|
<MudGrid>
|
|
|
|
|
@foreach (var camera in _cameras)
|
|
|
|
|
{
|
|
|
|
|
<MudItem xs="12" sm="6" md="4" xl="3">
|
|
|
|
|
<CameraTile Camera="@camera"
|
|
|
|
|
SnapshotUrl="@GetSnapshot(camera.Id)"
|
|
|
|
|
LoadingSnapshot="@IsSnapshotLoading(camera.Id)"
|
2026-10-25 00:54:36 +02:00
|
|
|
SnapshotRequesting="@IsSnapshotRequesting(camera.Id)"
|
2026-08-26 17:24:15 +02:00
|
|
|
OnSnapshot="@(() => TakeSnapshot(camera))"
|
|
|
|
|
OnDelete="@(() => ConfirmDeleteCamera(camera.Id, camera.Name))"
|
|
|
|
|
OnToggleStatus="@(() => ToggleCamera(camera))" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
}
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</MudContainer>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
</MudTabPanel>
|
|
|
|
|
|
|
|
|
|
@* ─── Onglet 2 : Découverte ────────────────────────────────── *@
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTabPanel Text="@Text["CamerasPage_DiscoveryTab"]" Icon="@Icons.Material.Filled.Radar">
|
2026-08-26 17:24:15 +02:00
|
|
|
<div class="pa-4">
|
|
|
|
|
<div class="d-flex align-center mb-4">
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ScanNow" Disabled="@_scanning">
|
|
|
|
|
@if (_scanning) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Radar" Class="mr-1" /> @Text["CamerasPage_ScanNow"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@if (_scanning)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Info" Class="mb-4">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_ScanPending"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@if (_loadingDiscoveries)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" />
|
|
|
|
|
}
|
|
|
|
|
else if (_discoveries.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
<MudPaper Elevation="2" Class="pa-6 text-center" Style="border-radius: 12px;">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.VideocamOff" Size="Size.Large" Color="Color.Default" />
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.h6" Class="mt-2">@Text["CamerasPage_NoDiscoveries"]</MudText>
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_NoDiscoveriesHelp"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudText>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_discoveries" Hover="true" Striped="true" Elevation="2">
|
|
|
|
|
<HeaderContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTh>@Text["CamerasPage_IpAddress"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CamerasPage_VendorModel"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CamerasPage_Type"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CamerasPage_Ports"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CamerasPage_DetectedAt"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CamerasPage_Actions"]</MudTh>
|
2026-08-26 17:24:15 +02:00
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CamerasPage_IpAddress"]">
|
2026-08-26 17:24:15 +02:00
|
|
|
<strong>@context.IpAddress</strong>
|
|
|
|
|
@if (!string.IsNullOrEmpty(context.MacAddress))
|
|
|
|
|
{
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@context.MacAddress</MudText>
|
|
|
|
|
}
|
|
|
|
|
</MudTd>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CamerasPage_VendorModel"]">
|
2026-08-26 17:24:15 +02:00
|
|
|
@if (!string.IsNullOrEmpty(context.Vendor) || !string.IsNullOrEmpty(context.OnvifHardware))
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.body2">@(context.Vendor ?? Text["CamerasPage_Unknown"])</MudText>
|
2026-08-26 17:24:15 +02:00
|
|
|
@if (!string.IsNullOrEmpty(context.OnvifHardware))
|
|
|
|
|
{
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@context.OnvifHardware</MudText>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!string.IsNullOrEmpty(context.HttpServerHeader))
|
|
|
|
|
{
|
|
|
|
|
<MudText Typo="Typo.body2">@context.HttpServerHeader</MudText>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["CamerasPage_Unknown"]</MudText>
|
2026-08-26 17:24:15 +02:00
|
|
|
}
|
|
|
|
|
</MudTd>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CamerasPage_Type"]">
|
2026-08-26 17:24:15 +02:00
|
|
|
<StatusChip Text="@FormatType(context.DetectedType)" Color="@TypeColor(context.DetectedType)"
|
|
|
|
|
Icon="@Icons.Material.Filled.Videocam" />
|
|
|
|
|
</MudTd>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CamerasPage_Ports"]">
|
2026-08-26 17:24:15 +02:00
|
|
|
@if (context.OpenPorts.Length == 0) { <MudText Typo="Typo.body2">-</MudText> }
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<div class="d-flex flex-wrap" style="gap: 4px;">
|
|
|
|
|
@foreach (var port in context.OpenPorts)
|
|
|
|
|
{
|
|
|
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined">@port</MudChip>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</MudTd>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CamerasPage_DetectedAt"]">@context.ProbedAt.ToLocalTime().ToString("g", Language.Culture)</MudTd>
|
|
|
|
|
<MudTd DataLabel="@Text["CamerasPage_Actions"]">
|
|
|
|
|
<MudTooltip Text="@Text["CamerasPage_AddDiscoveredTooltip"]">
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.AddCircle" Color="Color.Success"
|
2026-10-25 05:59:18 +01:00
|
|
|
aria-label="@Text["CamerasPage_ConfirmCamera"]"
|
2026-08-26 17:24:15 +02:00
|
|
|
OnClick="@(() => OpenConfirm(context))" />
|
|
|
|
|
</MudTooltip>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTooltip Text="@Text["CamerasPage_IgnoreTooltip"]">
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Cancel" Color="Color.Default"
|
2026-10-25 05:59:18 +01:00
|
|
|
aria-label="@Text["CamerasPage_IgnoreDiscovery"]"
|
2026-08-26 17:24:15 +02:00
|
|
|
OnClick="@(() => Reject(context))" />
|
|
|
|
|
</MudTooltip>
|
|
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
</MudTabPanel>
|
|
|
|
|
|
|
|
|
|
@* ─── Onglet 3 : Identifiants ──────────────────────────────── *@
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTabPanel Text="@Text["CamerasPage_CredentialsTab"]" Icon="@Icons.Material.Filled.Lock">
|
2026-08-26 17:24:15 +02:00
|
|
|
<div class="pa-4">
|
|
|
|
|
<div class="d-flex justify-space-between align-center mb-4">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_CredentialsDescription"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small"
|
|
|
|
|
OnClick="@(() => _showCredentialDialog = true)">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["CamerasPage_Add"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@if (_credentialsLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" Size="Size.Small" />
|
|
|
|
|
}
|
|
|
|
|
else if (_credentials.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_NoCredentials"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_credentials" Hover="true" Dense="true">
|
|
|
|
|
<HeaderContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTh>@Text["CamerasPage_Label"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CamerasPage_Username"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CamerasPage_LastUsed"]</MudTh>
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudTh></MudTh>
|
|
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CamerasPage_Label"]">@context.Label</MudTd>
|
|
|
|
|
<MudTd DataLabel="@Text["CamerasPage_Username"]"><code>@context.Username</code></MudTd>
|
|
|
|
|
<MudTd DataLabel="@Text["CamerasPage_LastUsed"]">
|
|
|
|
|
@(context.LastUsedAt?.ToString("g", Language.Culture) ?? Text["CamerasPage_Never"])
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudTd>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CamerasPage_Actions"]">
|
|
|
|
|
<MudTooltip Text="@Text["CamerasPage_DeleteCredentialTooltip"]">
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small"
|
2026-10-25 05:59:18 +01:00
|
|
|
Color="Color.Error" aria-label="@Text["CamerasPage_DeleteCredential"]"
|
2026-08-26 17:24:15 +02:00
|
|
|
OnClick="@(() => DeleteCredential(context))" />
|
|
|
|
|
</MudTooltip>
|
|
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
</MudTabPanel>
|
|
|
|
|
</MudTabs>
|
2026-07-17 06:30:09 +00:00
|
|
|
|
2026-07-18 18:58:20 +00:00
|
|
|
@* ─── Confirm delete dialog ───────────────────────────────── *@
|
2026-08-10 22:53:21 +02:00
|
|
|
<MudOverlay Visible="@_confirmDeleteShow" OnClick="@(() => _confirmDeleteShow = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_confirmDeleteShow">
|
2026-10-25 05:59:18 +01:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["CamerasPage_ConfirmDeleteTitle"]</MudText></TitleContent>
|
2026-08-10 22:53:21 +02:00
|
|
|
<DialogContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText>@string.Format(Language.Culture, Text["CamerasPage_ConfirmDeleteBody"], _confirmDeleteName)</MudText>
|
2026-08-10 22:53:21 +02:00
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">@Text["CamerasPage_Cancel"]</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@ExecuteDeleteCamera">@Text["CamerasPage_Delete"]</MudButton>
|
2026-08-10 22:53:21 +02:00
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
2026-07-18 18:58:20 +00:00
|
|
|
|
2026-08-26 17:24:15 +02:00
|
|
|
@* ─── Create camera dialog ──────────────────────────────────── *@
|
2026-08-10 22:53:21 +02:00
|
|
|
<MudOverlay Visible="@_showCreate" OnClick="@(() => _showCreate = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_showCreate">
|
2026-10-25 05:59:18 +01:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["CamerasPage_AddCamera"]</MudText></TitleContent>
|
2026-08-10 22:53:21 +02:00
|
|
|
<DialogContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField @bind-Value="_newName" Label="@Text["CamerasPage_NameRequired"]" Variant="Variant.Outlined"
|
2026-08-10 22:53:21 +02:00
|
|
|
Class="mb-4" Required="true" Immediate="true" />
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField @bind-Value="_newManufacturer" Label="@Text["CamerasPage_Manufacturer"]" Variant="Variant.Outlined" Class="mb-4" />
|
|
|
|
|
<MudTextField @bind-Value="_newModel" Label="@Text["CamerasPage_Model"]" Variant="Variant.Outlined" Class="mb-4" />
|
|
|
|
|
<MudTextField @bind-Value="_newRtspUrl" Label="@Text["CamerasPage_RtspUrl"]" Variant="Variant.Outlined" Class="mb-4"
|
|
|
|
|
HelperText="@Text["CamerasPage_RtspHint"]" />
|
2026-08-10 22:53:21 +02:00
|
|
|
@if (!string.IsNullOrEmpty(_dialogError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_dialogError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showCreate = false)">@Text["CamerasPage_Cancel"]</MudButton>
|
2026-08-10 22:53:21 +02:00
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@CreateCamera" Disabled="@_saving">
|
|
|
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_Add"]
|
2026-08-10 22:53:21 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
2026-07-17 06:30:09 +00:00
|
|
|
|
2026-08-26 17:24:15 +02:00
|
|
|
@* ─── Discovery confirm dialog ────────────────────────────────── *@
|
|
|
|
|
<MudOverlay Visible="@_confirmShow" OnClick="@(() => _confirmShow = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_confirmShow" Options="new DialogOptions { MaxWidth = MaxWidth.Medium, FullWidth = true }">
|
|
|
|
|
<TitleContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.h6">@string.Format(Language.Culture, Text["CamerasPage_ConfirmTitle"], _confirm?.IpAddress)</MudText>
|
2026-08-26 17:24:15 +02:00
|
|
|
</TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
@if (_confirm is not null)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField @bind-Value="_confirmName" Label="@Text["CamerasPage_CameraNameRequired"]" Variant="Variant.Outlined"
|
2026-08-26 17:24:15 +02:00
|
|
|
Class="mb-4" Immediate="true" />
|
|
|
|
|
|
|
|
|
|
@if (!string.IsNullOrEmpty(_selectedStreamUrl))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Success" Variant="Variant.Outlined" Class="mb-4">
|
|
|
|
|
<MudText Typo="Typo.body2" Class="mb-1">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.CheckCircle" Class="mr-1" Size="Size.Small" />
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_MainStreamDetected"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2"><code>@_selectedStreamUrl</code></MudText>
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Warning" Class="mb-4">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_NoStreamDetected"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mb-4">
|
2026-10-25 05:59:18 +01:00
|
|
|
@(_confirm.Vendor ?? Text["CamerasPage_UnknownVendor"])
|
2026-08-26 17:24:15 +02:00
|
|
|
@if (!string.IsNullOrEmpty(_confirm.OnvifHardware)) { <text>· @_confirm.OnvifHardware</text> }
|
|
|
|
|
@if (!string.IsNullOrEmpty(_confirm.MacAddress)) { <text>· @_confirm.MacAddress</text> }
|
|
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
@if (_confirm.HasScreenshot)
|
|
|
|
|
{
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mb-1">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_StreamPreview"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudText>
|
|
|
|
|
<div class="mb-4" style="border: 1px solid var(--mud-palette-lines-default); border-radius: 8px; overflow: hidden;">
|
2026-10-25 05:59:18 +01:00
|
|
|
<img src="/api/discovery/results/@_confirm.Id/screenshot" alt="@Text["CamerasPage_StreamPreviewAlt"]"
|
2026-08-26 17:24:15 +02:00
|
|
|
style="width: 100%; display: block;" />
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@if (!string.IsNullOrEmpty(_confirmError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_confirmError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmShow = false)">@Text["CamerasPage_Cancel"]</MudButton>
|
2026-08-26 17:24:15 +02:00
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Success" OnClick="@ConfirmCamera"
|
|
|
|
|
Disabled="@(_confirming || string.IsNullOrWhiteSpace(_confirmName) || string.IsNullOrEmpty(_selectedStreamUrl))">
|
|
|
|
|
@if (_confirming) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_AddCamera"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
|
|
|
|
@* ─── Add credential dialog ──────────────────────────────────── *@
|
|
|
|
|
<MudOverlay Visible="@_showCredentialDialog" OnClick="@(() => _showCredentialDialog = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_showCredentialDialog">
|
2026-10-25 05:59:18 +01:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["CamerasPage_AddCredentialTitle"]</MudText></TitleContent>
|
2026-08-26 17:24:15 +02:00
|
|
|
<DialogContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField @bind-Value="_newCredLabel" Label="@Text["CamerasPage_LabelRequired"]" Variant="Variant.Outlined"
|
2026-08-26 17:24:15 +02:00
|
|
|
Class="mb-4" Immediate="true"
|
2026-10-25 05:59:18 +01:00
|
|
|
HelperText="@Text["CamerasPage_CredentialHint"]" />
|
|
|
|
|
<MudTextField @bind-Value="_newCredUsername" Label="@Text["CamerasPage_UsernameRequired"]" Variant="Variant.Outlined"
|
2026-08-26 17:24:15 +02:00
|
|
|
Class="mb-4" Immediate="true" />
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField @bind-Value="_newCredPassword" Label="@Text["CamerasPage_PasswordRequired"]" Variant="Variant.Outlined"
|
2026-08-26 17:24:15 +02:00
|
|
|
InputType="InputType.Password" Class="mb-4" Immediate="true" />
|
|
|
|
|
@if (!string.IsNullOrEmpty(_credentialError))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">@_credentialError</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showCredentialDialog = false)">@Text["CamerasPage_Cancel"]</MudButton>
|
2026-08-26 17:24:15 +02:00
|
|
|
<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" /> }
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CamerasPage_Add"]
|
2026-08-26 17:24:15 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
2026-07-17 06:30:09 +00:00
|
|
|
@code {
|
|
|
|
|
[Parameter] public Guid SiteId { get; set; }
|
|
|
|
|
|
2026-08-26 17:24:15 +02:00
|
|
|
private int _activeTab;
|
|
|
|
|
|
|
|
|
|
// ── Caméras ────────────────────────────────────────────────────
|
2026-07-17 06:30:09 +00:00
|
|
|
private IReadOnlyList<CameraItem>? _cameras;
|
2026-08-26 17:24:15 +02:00
|
|
|
private bool _loadingCameras = true;
|
|
|
|
|
private bool _camerasError;
|
2026-07-17 06:30:09 +00:00
|
|
|
private bool _showCreate;
|
|
|
|
|
private bool _saving;
|
2026-07-18 18:58:20 +00:00
|
|
|
private string _dialogError = "";
|
2026-07-17 06:30:09 +00:00
|
|
|
|
2026-08-10 22:53:21 +02:00
|
|
|
private readonly Dictionary<Guid, string?> _snapshots = [];
|
|
|
|
|
private readonly Dictionary<Guid, bool> _snapshotLoading = [];
|
2026-10-25 00:54:36 +02:00
|
|
|
private readonly Dictionary<Guid, bool> _snapshotRequesting = [];
|
2026-10-25 01:00:32 +02:00
|
|
|
private readonly Dictionary<Guid, Guid> _pendingSnapshotRequests = [];
|
2026-08-10 22:53:21 +02:00
|
|
|
private CancellationTokenSource? _refreshCts;
|
|
|
|
|
private bool _disposed;
|
|
|
|
|
|
2026-07-17 06:30:09 +00:00
|
|
|
private string _newName = "";
|
|
|
|
|
private string? _newManufacturer;
|
|
|
|
|
private string? _newModel;
|
|
|
|
|
private string? _newRtspUrl;
|
|
|
|
|
|
2026-08-26 17:24:15 +02:00
|
|
|
// ── Découverte ─────────────────────────────────────────────────
|
|
|
|
|
private List<PendingDiscoveryItem> _discoveries = [];
|
|
|
|
|
private bool _loadingDiscoveries = true;
|
|
|
|
|
private bool _scanning;
|
|
|
|
|
|
|
|
|
|
private PendingDiscoveryItem? _confirm;
|
|
|
|
|
private bool _confirmShow;
|
|
|
|
|
private bool _confirming;
|
|
|
|
|
private string _confirmName = "";
|
|
|
|
|
private string _selectedStreamUrl = "";
|
|
|
|
|
private string _confirmError = "";
|
|
|
|
|
private Guid? _siteAgentId;
|
|
|
|
|
|
|
|
|
|
// ── Identifiants ───────────────────────────────────────────────
|
|
|
|
|
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 = "";
|
|
|
|
|
|
2026-08-10 22:53:21 +02:00
|
|
|
protected override async Task OnInitializedAsync()
|
2026-07-17 06:30:09 +00:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Language.LanguageChanged += OnLanguageChanged;
|
2026-08-26 17:24:15 +02:00
|
|
|
// Load all three tabs data in parallel
|
|
|
|
|
var tasks = new[]
|
|
|
|
|
{
|
|
|
|
|
LoadCameras(),
|
|
|
|
|
LoadDiscoveries(),
|
|
|
|
|
LoadSiteAgent(),
|
|
|
|
|
LoadCredentials()
|
|
|
|
|
};
|
|
|
|
|
await Task.WhenAll(tasks);
|
2026-08-11 11:59:18 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-25 06:03:46 +01:00
|
|
|
private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged);
|
|
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
private bool _autoRefreshStarted;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if (firstRender && !_autoRefreshStarted)
|
|
|
|
|
{
|
|
|
|
|
_autoRefreshStarted = true;
|
|
|
|
|
await StartAutoRefresh();
|
|
|
|
|
}
|
2026-08-10 22:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task StartAutoRefresh()
|
|
|
|
|
{
|
|
|
|
|
_refreshCts = new CancellationTokenSource();
|
2026-07-17 06:30:09 +00:00
|
|
|
try
|
|
|
|
|
{
|
2026-08-10 22:53:21 +02:00
|
|
|
while (!_refreshCts.Token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(30), _refreshCts.Token);
|
|
|
|
|
if (!_disposed) await LoadCameras(silent: true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (OperationCanceledException) { /* arrêt volontaire */ }
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-26 17:24:15 +02:00
|
|
|
private async Task RefreshCurrentTab()
|
|
|
|
|
{
|
|
|
|
|
switch (_activeTab)
|
|
|
|
|
{
|
|
|
|
|
case 0: await LoadCameras(silent: false); break;
|
|
|
|
|
case 1: await LoadDiscoveries(); break;
|
|
|
|
|
case 2: await LoadCredentials(); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Caméras ────────────────────────────────────────────────────
|
2026-08-10 22:53:21 +02:00
|
|
|
|
|
|
|
|
private async Task LoadCameras(bool silent = false)
|
|
|
|
|
{
|
2026-08-26 17:24:15 +02:00
|
|
|
if (!silent) { _loadingCameras = true; _camerasError = false; }
|
2026-08-10 22:53:21 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.GetCamerasBySiteAsync(SiteId, pageSize: 100);
|
2026-07-17 06:30:09 +00:00
|
|
|
_cameras = result?.Items;
|
2026-08-10 22:53:21 +02:00
|
|
|
if (_cameras is not null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var camera in _cameras)
|
|
|
|
|
{
|
|
|
|
|
if (_snapshots.ContainsKey(camera.Id)) continue;
|
|
|
|
|
_snapshots[camera.Id] = null;
|
|
|
|
|
_ = LoadSnapshotAsync(camera.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-25 01:00:32 +02:00
|
|
|
await RefreshPendingSnapshotRequestsAsync();
|
2026-07-17 06:30:09 +00:00
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch {
|
2026-08-26 17:24:15 +02:00
|
|
|
_camerasError = true;
|
2026-10-25 05:59:18 +01:00
|
|
|
if (!silent) Snackbar.Add(Text["CamerasPage_OperationFailed"], Severity.Error);
|
2026-08-10 22:53:21 +02:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2026-08-26 17:24:15 +02:00
|
|
|
if (!silent) _loadingCameras = false;
|
2026-08-10 22:53:21 +02:00
|
|
|
if (!_disposed) await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadSnapshotAsync(Guid cameraId)
|
|
|
|
|
{
|
|
|
|
|
_snapshotLoading[cameraId] = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var events = await Api.GetRecentEventsAsync(cameraId, 1);
|
|
|
|
|
var latest = events?.FirstOrDefault(e => !string.IsNullOrEmpty(e.SnapshotThumbUrl ?? e.SnapshotUrl));
|
|
|
|
|
_snapshots[cameraId] = latest is null
|
|
|
|
|
? null
|
|
|
|
|
: (latest.SnapshotThumbUrl ?? latest.SnapshotUrl);
|
|
|
|
|
}
|
|
|
|
|
catch { /* vignette indisponible → placeholder */ }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_snapshotLoading[cameraId] = false;
|
|
|
|
|
if (!_disposed) await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string? GetSnapshot(Guid id) => _snapshots.TryGetValue(id, out var url) ? url : null;
|
|
|
|
|
|
|
|
|
|
private bool IsSnapshotLoading(Guid id) => _snapshotLoading.TryGetValue(id, out var loading) && loading;
|
|
|
|
|
|
2026-10-25 00:54:36 +02:00
|
|
|
private bool IsSnapshotRequesting(Guid id) => _snapshotRequesting.TryGetValue(id, out var requesting) && requesting;
|
|
|
|
|
|
2026-10-25 01:00:32 +02:00
|
|
|
private async Task RefreshPendingSnapshotRequestsAsync()
|
|
|
|
|
{
|
|
|
|
|
foreach (var (cameraId, requestId) in _pendingSnapshotRequests.ToArray())
|
|
|
|
|
{
|
|
|
|
|
if (IsSnapshotRequesting(cameraId)) continue;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var status = await Api.GetCameraSnapshotStatusAsync(cameraId, requestId);
|
|
|
|
|
if (status?.Status == "Failed")
|
|
|
|
|
{
|
|
|
|
|
_pendingSnapshotRequests.Remove(cameraId);
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(status.Reason ?? Text["CamerasPage_CaptureFailed"], Severity.Error);
|
2026-10-25 01:00:32 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TimedOut is a UI deadline, but Agent's durable outbox may still deliver later.
|
|
|
|
|
if (status?.Status != "Completed") continue;
|
|
|
|
|
|
|
|
|
|
var snapshot = await Api.GetEventAsync(requestId);
|
|
|
|
|
if (snapshot is null || string.IsNullOrEmpty(snapshot.SnapshotUrl)) continue;
|
|
|
|
|
|
|
|
|
|
_snapshots[cameraId] = snapshot.SnapshotThumbUrl ?? snapshot.SnapshotUrl;
|
|
|
|
|
_pendingSnapshotRequests.Remove(cameraId);
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_SnapshotAvailable"], Severity.Success);
|
2026-10-25 01:00:32 +02:00
|
|
|
}
|
|
|
|
|
catch { /* Réessayer lors de la prochaine actualisation de la grille. */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 22:53:21 +02:00
|
|
|
private async Task TakeSnapshot(CameraItem camera)
|
|
|
|
|
{
|
2026-10-25 00:54:36 +02:00
|
|
|
if (_disposed || IsSnapshotRequesting(camera.Id)) return;
|
|
|
|
|
|
|
|
|
|
_snapshotRequesting[camera.Id] = true;
|
|
|
|
|
var completedWithoutImage = false;
|
2026-08-10 22:53:21 +02:00
|
|
|
try
|
|
|
|
|
{
|
2026-10-25 00:54:36 +02:00
|
|
|
var request = await Api.RequestCameraSnapshotAsync(camera.Id);
|
|
|
|
|
if (!request.Succeeded || request.Data == Guid.Empty)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(request.ErrorMessage ?? Text["CamerasPage_OperationFailed"], Severity.Error);
|
2026-10-25 00:54:36 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-25 01:00:32 +02:00
|
|
|
_pendingSnapshotRequests[camera.Id] = request.Data;
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Language.Culture, Text["CamerasPage_CaptureRequested"], camera.Name), Severity.Info);
|
2026-10-25 00:54:36 +02:00
|
|
|
for (var attempt = 0; attempt < 35 && !_disposed; attempt++)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
|
|
|
|
var status = await Api.GetCameraSnapshotStatusAsync(camera.Id, request.Data);
|
|
|
|
|
if (status?.Status is "Failed" or "TimedOut")
|
|
|
|
|
{
|
2026-10-25 01:00:32 +02:00
|
|
|
if (status.Status == "Failed")
|
|
|
|
|
{
|
|
|
|
|
_pendingSnapshotRequests.Remove(camera.Id);
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(status.Reason ?? Text["CamerasPage_CaptureFailed"], Severity.Error);
|
2026-10-25 01:00:32 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2026-10-25 00:54:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status?.Status != "Completed") continue;
|
|
|
|
|
|
|
|
|
|
completedWithoutImage = true;
|
|
|
|
|
var snapshot = await Api.GetEventAsync(request.Data);
|
|
|
|
|
if (snapshot is null || string.IsNullOrEmpty(snapshot.SnapshotUrl)) continue;
|
|
|
|
|
|
|
|
|
|
_snapshots[camera.Id] = snapshot.SnapshotThumbUrl ?? snapshot.SnapshotUrl;
|
2026-10-25 01:00:32 +02:00
|
|
|
_pendingSnapshotRequests.Remove(camera.Id);
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_SnapshotAvailable"], Severity.Success);
|
2026-10-25 00:54:36 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-25 01:00:32 +02:00
|
|
|
if (_disposed) return;
|
2026-10-25 00:54:36 +02:00
|
|
|
Snackbar.Add(completedWithoutImage
|
2026-10-25 05:59:18 +01:00
|
|
|
? Text["CamerasPage_CaptureComplete"]
|
|
|
|
|
: Text["CamerasPage_CaptureSlow"],
|
2026-10-25 01:00:32 +02:00
|
|
|
Severity.Info);
|
2026-08-10 22:53:21 +02:00
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch {
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_OperationFailed"], Severity.Error);
|
2026-07-18 18:58:20 +00:00
|
|
|
}
|
2026-10-25 00:54:36 +02:00
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_snapshotRequesting[camera.Id] = false;
|
|
|
|
|
if (!_disposed) await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
2026-07-17 06:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-19 22:38:34 +02:00
|
|
|
private async Task ToggleCamera(CameraItem camera)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.ToggleCameraStatusAsync(camera.Id);
|
|
|
|
|
if (result.Succeeded && result.Data is not null)
|
|
|
|
|
{
|
|
|
|
|
camera.Status = result.Data.Status;
|
|
|
|
|
Snackbar.Add(
|
2026-11-12 02:06:10 +01:00
|
|
|
result.Data.Status != "Disabled" ? string.Format(Language.Culture, Text["CamerasPage_CameraEnabled"], camera.Name) : string.Format(Language.Culture, Text["CamerasPage_CameraDisabled"], camera.Name),
|
2026-08-19 22:38:34 +02:00
|
|
|
Severity.Success);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(result.ErrorMessage ?? Text["CamerasPage_OperationFailed"], Severity.Error);
|
2026-08-19 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_OperationFailed"], Severity.Error);
|
2026-08-19 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 18:58:20 +00:00
|
|
|
private bool _confirmDeleteShow;
|
|
|
|
|
private Guid _confirmDeleteId;
|
|
|
|
|
private string _confirmDeleteName = "";
|
|
|
|
|
|
|
|
|
|
private void ConfirmDeleteCamera(Guid id, string name)
|
|
|
|
|
{
|
|
|
|
|
_confirmDeleteId = id;
|
|
|
|
|
_confirmDeleteName = name;
|
|
|
|
|
_confirmDeleteShow = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ExecuteDeleteCamera()
|
|
|
|
|
{
|
|
|
|
|
_confirmDeleteShow = false;
|
|
|
|
|
await DeleteCamera(_confirmDeleteId, _confirmDeleteName);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 06:30:09 +00:00
|
|
|
private async Task CreateCamera()
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
if (string.IsNullOrWhiteSpace(_newName)) { _dialogError = Text["CamerasPage_NameRequiredError"]; return; }
|
2026-07-17 06:30:09 +00:00
|
|
|
_saving = true;
|
2026-07-18 18:58:20 +00:00
|
|
|
_dialogError = "";
|
2026-07-17 06:30:09 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.CreateCameraAsync(SiteId, _newName, _newRtspUrl, _newManufacturer, _newModel);
|
2026-08-14 21:07:28 +02:00
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
_dialogError = string.IsNullOrWhiteSpace(result.ErrorMessage)
|
2026-10-25 05:59:18 +01:00
|
|
|
? Text["CamerasPage_CreateError"]
|
2026-08-14 21:07:28 +02:00
|
|
|
: result.ErrorMessage;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-07-17 06:30:09 +00:00
|
|
|
_showCreate = false;
|
|
|
|
|
ResetForm();
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_CameraAdded"], Severity.Success);
|
2026-07-17 06:30:09 +00:00
|
|
|
await LoadCameras();
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { _dialogError = Text["CamerasPage_OperationFailed"]; }
|
2026-07-17 06:30:09 +00:00
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DeleteCamera(Guid id, string name)
|
|
|
|
|
{
|
|
|
|
|
if (await Api.DeleteCameraAsync(id))
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Language.Culture, Text["CamerasPage_CameraDeleted"], name), Severity.Success);
|
2026-07-17 06:30:09 +00:00
|
|
|
await LoadCameras();
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
else Snackbar.Add(Text["CamerasPage_Error"], Severity.Error);
|
2026-07-17 06:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetForm()
|
|
|
|
|
{
|
|
|
|
|
_newName = "";
|
|
|
|
|
_newManufacturer = null;
|
|
|
|
|
_newModel = null;
|
|
|
|
|
_newRtspUrl = null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-26 17:24:15 +02:00
|
|
|
// ─── Découverte ─────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private async Task LoadDiscoveries()
|
|
|
|
|
{
|
|
|
|
|
_loadingDiscoveries = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_discoveries = await Api.GetPendingDiscoveriesAsync(SiteId);
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { Snackbar.Add(Text["CamerasPage_OperationFailed"], Severity.Error); }
|
2026-08-26 17:24:15 +02:00
|
|
|
finally { _loadingDiscoveries = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadSiteAgent()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var agents = await Api.GetAgentsBySiteAsync(SiteId, 1, 50);
|
|
|
|
|
_siteAgentId = agents?.Items.FirstOrDefault()?.Id;
|
|
|
|
|
}
|
|
|
|
|
catch { /* best effort — la caméra sera créée sans agent assigné */ }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ScanNow()
|
|
|
|
|
{
|
|
|
|
|
_scanning = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.ScanNowAsync(SiteId);
|
|
|
|
|
Snackbar.Add(
|
|
|
|
|
result is { AgentsNotified: > 0 }
|
2026-10-25 05:59:18 +01:00
|
|
|
? string.Format(Language.Culture, Text["CamerasPage_ScanRequested"], result.AgentsNotified)
|
|
|
|
|
: Text["CamerasPage_ScanNoAgents"],
|
2026-08-26 17:24:15 +02:00
|
|
|
result is { AgentsNotified: > 0 } ? Severity.Success : Severity.Warning);
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(8));
|
|
|
|
|
await LoadDiscoveries();
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { Snackbar.Add(Text["CamerasPage_OperationFailed"], Severity.Error); }
|
2026-08-26 17:24:15 +02:00
|
|
|
finally { _scanning = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenConfirm(PendingDiscoveryItem item)
|
|
|
|
|
{
|
|
|
|
|
_confirm = item;
|
|
|
|
|
_confirmName = DefaultName(item);
|
|
|
|
|
_selectedStreamUrl = item.StreamUrls.FirstOrDefault() ?? "";
|
|
|
|
|
_confirmError = "";
|
|
|
|
|
_confirmShow = true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
private string DefaultName(PendingDiscoveryItem item)
|
2026-08-26 17:24:15 +02:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
var vendor = item.Vendor ?? item.OnvifHardware ?? Text["CamerasPage_Camera"];
|
|
|
|
|
return string.Format(Language.Culture, Text["CamerasPage_DefaultCameraName"], vendor, item.IpAddress);
|
2026-08-26 17:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ConfirmCamera()
|
|
|
|
|
{
|
|
|
|
|
if (_confirm is null || string.IsNullOrEmpty(_selectedStreamUrl)) return;
|
|
|
|
|
_confirming = true;
|
|
|
|
|
_confirmError = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var (user, pass) = ExtractCredentials(_selectedStreamUrl);
|
|
|
|
|
var result = await Api.ConfirmDiscoveryAsync(
|
|
|
|
|
SiteId, _confirm.Id, _confirmName.Trim(), _selectedStreamUrl,
|
|
|
|
|
user, pass, _siteAgentId);
|
|
|
|
|
if (!result.Succeeded || result.Data is null)
|
|
|
|
|
{
|
|
|
|
|
_confirmError = string.IsNullOrWhiteSpace(result.ErrorMessage)
|
2026-10-25 05:59:18 +01:00
|
|
|
? Text["CamerasPage_ConfirmError"]
|
2026-08-26 17:24:15 +02:00
|
|
|
: result.ErrorMessage;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var camera = result.Data;
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Language.Culture, Text["CamerasPage_CameraAddedNamed"], camera.Name), Severity.Success);
|
2026-08-26 17:24:15 +02:00
|
|
|
_confirmShow = false;
|
|
|
|
|
await LoadDiscoveries();
|
|
|
|
|
await LoadCameras();
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { _confirmError = Text["CamerasPage_OperationFailed"]; }
|
2026-08-26 17:24:15 +02:00
|
|
|
finally { _confirming = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task Reject(PendingDiscoveryItem item)
|
|
|
|
|
{
|
|
|
|
|
if (await Api.RejectDiscoveryAsync(item.Id))
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Language.Culture, Text["CamerasPage_DiscoveryIgnored"], item.IpAddress), Severity.Info);
|
2026-08-26 17:24:15 +02:00
|
|
|
await LoadDiscoveries();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_IgnoreError"], Severity.Error);
|
2026-08-26 17:24:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static (string? User, string? Pass) ExtractCredentials(string url)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var uri = new Uri(url);
|
|
|
|
|
if (!string.IsNullOrEmpty(uri.UserInfo))
|
|
|
|
|
{
|
|
|
|
|
var parts = uri.UserInfo.Split(':', 2);
|
|
|
|
|
return (Uri.UnescapeDataString(parts[0]),
|
|
|
|
|
parts.Length > 1 ? Uri.UnescapeDataString(parts[1]) : "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { /* URL invalide — pas de credentials */ }
|
|
|
|
|
return (null, null);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
private string FormatType(string detectedType) => detectedType switch
|
2026-08-26 17:24:15 +02:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
"Standard" => Text["CamerasPage_Camera"],
|
2026-08-26 17:24:15 +02:00
|
|
|
"Nvr" => "NVR",
|
|
|
|
|
"HomeKit" => "HomeKit",
|
2026-10-25 05:59:18 +01:00
|
|
|
"Doorbell" => Text["CamerasPage_Doorbell"],
|
|
|
|
|
_ => Text["CamerasPage_Unknown"]
|
2026-08-26 17:24:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static Color TypeColor(string detectedType) => detectedType switch
|
|
|
|
|
{
|
|
|
|
|
"Standard" or "Nvr" => Color.Success,
|
|
|
|
|
"HomeKit" => Color.Info,
|
|
|
|
|
_ => Color.Default
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ─── Identifiants ───────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
private async Task LoadCredentials()
|
|
|
|
|
{
|
|
|
|
|
_credentialsLoading = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_credentials = await Api.GetSiteCredentialsAsync(SiteId);
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { Snackbar.Add(Text["CamerasPage_OperationFailed"], Severity.Error); }
|
2026-08-26 17:24:15 +02:00
|
|
|
finally { _credentialsLoading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task AddCredential()
|
|
|
|
|
{
|
|
|
|
|
_savingCredential = true;
|
|
|
|
|
_credentialError = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await Api.AddSiteCredentialAsync(SiteId, _newCredLabel, _newCredUsername, _newCredPassword);
|
|
|
|
|
if (result is null)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
_credentialError = Text["CamerasPage_CredentialAddError"];
|
2026-08-26 17:24:15 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_CredentialAdded"], Severity.Success);
|
2026-08-26 17:24:15 +02:00
|
|
|
_showCredentialDialog = false;
|
|
|
|
|
_newCredLabel = "";
|
|
|
|
|
_newCredUsername = "";
|
|
|
|
|
_newCredPassword = "";
|
|
|
|
|
await LoadCredentials();
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { _credentialError = Text["CamerasPage_OperationFailed"]; }
|
2026-08-26 17:24:15 +02:00
|
|
|
finally { _savingCredential = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DeleteCredential(SiteCredentialItem credential)
|
|
|
|
|
{
|
|
|
|
|
if (await Api.DeleteSiteCredentialAsync(SiteId, credential.Id))
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Language.Culture, Text["CamerasPage_CredentialDeleted"], credential.Label), Severity.Success);
|
2026-08-26 17:24:15 +02:00
|
|
|
await LoadCredentials();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CamerasPage_DeleteError"], Severity.Error);
|
2026-08-26 17:24:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Lifecycle ──────────────────────────────────────────────────
|
|
|
|
|
|
2026-08-10 22:53:21 +02:00
|
|
|
public void Dispose()
|
2026-07-17 06:30:09 +00:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Language.LanguageChanged -= OnLanguageChanged;
|
2026-08-10 22:53:21 +02:00
|
|
|
_disposed = true;
|
|
|
|
|
_refreshCts?.Cancel();
|
|
|
|
|
_refreshCts?.Dispose();
|
|
|
|
|
}
|
2026-07-17 06:30:09 +00:00
|
|
|
}
|