2026-07-17 19:08:17 +00:00
|
|
|
@page "/cameras/{Id:guid}"
|
|
|
|
|
@attribute [Authorize]
|
|
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
@inject NavigationManager Nav
|
2026-10-25 05:59:18 +01:00
|
|
|
@inject UiText Text
|
2026-11-06 11:14:49 +01:00
|
|
|
@using Microsoft.AspNetCore.Components.Forms
|
2026-10-25 05:59:18 +01:00
|
|
|
@inject UiLanguageService Language
|
2026-11-06 11:14:49 +01:00
|
|
|
@inject IJSRuntime JS
|
|
|
|
|
@implements IAsyncDisposable
|
2026-07-17 19:08:17 +00:00
|
|
|
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudText Typo="Typo.h1" Class="mb-2">
|
2026-07-27 20:11:31 +00:00
|
|
|
<i class="fas fa-camera mr-2"></i>
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CameraDetail_TitlePrefix"] @_camera?.Name
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudText>
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
|
|
|
|
@if (_camera is not null)
|
|
|
|
|
{
|
|
|
|
|
<MudBadge Color="@GetStatusColor(_camera.Status)" Variant="Variant.Filled">
|
|
|
|
|
@GetStatusIcon(_camera.Status) @FormatStatus(_camera.Status)
|
|
|
|
|
</MudBadge>
|
2026-10-25 05:59:18 +01:00
|
|
|
<span class="ml-2">@Text["CameraDetail_CreatedAt"] @_camera.CreatedAt.ToString("g", Language.Culture)</span>
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
|
|
|
|
</MudText>
|
2026-07-17 19:08:17 +00:00
|
|
|
|
|
|
|
|
@if (_loading)
|
|
|
|
|
{
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudPaper Elevation="0" Style="border-radius: var(--hmd-radius-lg);">
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="360px" />
|
|
|
|
|
</MudPaper>
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
else if (_camera is null)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudAlert Severity="Severity.Warning">@Text["CameraDetail_NotFound"]</MudAlert>
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-23 07:20:47 +02:00
|
|
|
@* ─── Dernière image événementielle, rafraîchie périodiquement ─── *@
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudPaper Elevation="2" Class="pa-0 mb-6" Style="border-radius: var(--hmd-radius-lg); overflow: hidden;">
|
|
|
|
|
<div style="position: relative; aspect-ratio: 16/9; background: var(--mud-palette-dark);">
|
|
|
|
|
@if (_snapshotLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="100%" />
|
|
|
|
|
}
|
|
|
|
|
else if (!string.IsNullOrEmpty(_latestSnapshotUrl))
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<img src="@_latestSnapshotUrl" alt="@string.Format(Language.Culture, Text["CameraDetail_LatestImageAlt"], _camera.Name)"
|
2026-08-10 23:07:43 +02:00
|
|
|
style="width:100%; height:100%; object-fit:contain;" />
|
2026-10-23 07:20:47 +02:00
|
|
|
@if (_latestSnapshotAt is DateTime capturedAt)
|
2026-08-10 23:07:43 +02:00
|
|
|
{
|
2026-10-23 07:20:47 +02:00
|
|
|
<span style="position:absolute; top:12px; left:12px; padding:4px 8px; border-radius:4px; background:rgba(0,0,0,0.65); color:white;">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CameraDetail_LatestImage"] @capturedAt.ToLocalTime().ToString("g", Language.Culture)
|
2026-10-23 07:20:47 +02:00
|
|
|
</span>
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<div class="d-flex align-center justify-center flex-column" style="height:100%; min-height:240px;">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Videocam" Size="Size.Large" Color="Color.Secondary" />
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2">
|
2026-10-25 05:59:18 +01:00
|
|
|
@Text["CameraDetail_NoStream"]
|
2026-08-10 23:07:43 +02:00
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@* Overlay actions live *@
|
|
|
|
|
<div style="position:absolute; bottom:12px; right:12px;" class="d-flex gap-2">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTooltip Text="@Text["CameraDetail_TakeSnapshot"]">
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.PhotoCamera" Color="Color.Inherit" Style="background: rgba(0,0,0,0.45);"
|
2026-10-25 05:59:18 +01:00
|
|
|
aria-label="@Text["CameraDetail_TakeSnapshot"]" Disabled="@(_camera.Status != "Online" || _snapshotLoading)"
|
2026-10-23 07:20:47 +02:00
|
|
|
OnClick="@TakeSnapshot" />
|
2026-08-10 23:07:43 +02:00
|
|
|
</MudTooltip>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTooltip Text="@Text["CameraDetail_RefreshStream"]">
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Color="Color.Inherit" Style="background: rgba(0,0,0,0.45);"
|
2026-10-25 05:59:18 +01:00
|
|
|
aria-label="@Text["CameraDetail_RefreshStream"]" OnClick="@RefreshSnapshot" />
|
2026-08-10 23:07:43 +02:00
|
|
|
</MudTooltip>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
|
2026-11-06 11:14:49 +01:00
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-6">
|
|
|
|
|
<div class="d-flex align-center justify-space-between mb-2">
|
|
|
|
|
<MudText Typo="Typo.h6">@Text["CameraDetail_Live"]</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Primary" Disabled="@(_camera.Status != "Online" || _liveStarting)" OnClick="ToggleLive">
|
|
|
|
|
@(_liveEnabled ? Text["CameraDetail_StopLive"] : Text["CameraDetail_WatchLive"])
|
|
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
|
|
|
|
<video @ref="_liveVideo" data-live-camera="@_camera.Id" autoplay playsinline controls style="width:100%; max-height:480px; background:#111"></video>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
|
2026-08-10 23:07:43 +02:00
|
|
|
@* ─── Informations & actions ─── *@
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-5 mb-6" Style="border-radius: var(--hmd-radius-md);">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.h6" Class="mb-4">@Text["CameraDetail_Information"]</MudText>
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" sm="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField @bind-Value="_editName" Label="@Text["CameraDetail_Name"]" Variant="Variant.Outlined" Class="mb-4" Immediate="true" />
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTextField @bind-Value="_editRtspUrl" Label="@Text["CameraDetail_RtspUrl"]" Variant="Variant.Outlined" Class="mb-4" Immediate="true"
|
2026-08-10 23:07:43 +02:00
|
|
|
InputType="@(_showRtsp ? InputType.Text : InputType.Password)"
|
|
|
|
|
Adornment="Adornment.End"
|
|
|
|
|
AdornmentIcon="@(_showRtsp ? Icons.Material.Filled.VisibilityOff : Icons.Material.Filled.Visibility)"
|
|
|
|
|
OnAdornmentClick="@(() => _showRtsp = !_showRtsp)" />
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["CameraDetail_Manufacturer"]</MudText>
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudText Typo="Typo.body1">@(_camera.Manufacturer ?? "-")</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" sm="6">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["CameraDetail_Model"]</MudText>
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudText Typo="Typo.body1">@(_camera.Model ?? "-")</MudText>
|
|
|
|
|
</MudItem>
|
2026-11-06 11:14:49 +01:00
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudSwitch T="bool" @bind-Value="_recordingEnabled" Color="Color.Primary" Disabled="@_saving"
|
|
|
|
|
Label="@Text["CameraDetail_RecordingEnabled"]" />
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@Text["CameraDetail_RecordingHelp"]</MudText>
|
|
|
|
|
<MudSwitch T="bool" @bind-Value="_eventRecordingEnabled" Color="Color.Primary" Disabled="@_saving"
|
|
|
|
|
Label="@Text["CameraDetail_EventRecordingEnabled"]" />
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@Text["CameraDetail_EventRecordingHelp"]</MudText>
|
|
|
|
|
</MudItem>
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudGrid>
|
2026-08-10 23:07:43 +02:00
|
|
|
|
|
|
|
|
@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>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<div class="d-flex flex-wrap gap-2 mt-2">
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@SaveCamera" Disabled="@_saving">
|
|
|
|
|
@if (_saving) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Save" Class="mr-1" /> @Text["CameraDetail_Save"]
|
2026-08-10 23:07:43 +02:00
|
|
|
</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="@(_camera.Status == "Disabled" ? Color.Success : Color.Default)"
|
2026-10-25 02:30:17 +02:00
|
|
|
OnClick="@ToggleCameraStatus" Disabled="@(_saving || _togglingStatus)">
|
|
|
|
|
@if (_togglingStatus) { <MudProgressCircular Size="Size.Small" Class="mr-1" /> }
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudIcon Icon="@(_camera.Status == "Disabled" ? Icons.Material.Filled.PlayArrow : Icons.Material.Filled.Stop)"
|
|
|
|
|
Class="mr-1" />
|
2026-10-25 05:59:18 +01:00
|
|
|
@(_camera.Status == "Disabled" ? Text["CameraDetail_Enable"] : Text["CameraDetail_Disable"])
|
2026-08-10 23:07:43 +02:00
|
|
|
</MudButton>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="@(() => _confirmDeleteShow = true)" aria-label="@Text["CameraDetail_DeleteCamera"]">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Delete" Class="mr-1" /> @Text["CameraDetail_Delete"]
|
2026-08-10 23:07:43 +02:00
|
|
|
</MudButton>
|
|
|
|
|
<MudSpacer />
|
|
|
|
|
<MudButton Variant="Variant.Text" Color="Color.Default" OnClick="@(() => Nav.NavigateTo($"/sites/{_camera.SiteId}/cameras"))">
|
|
|
|
|
← Retour aux caméras
|
|
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudPaper>
|
|
|
|
|
|
2026-11-06 11:14:49 +01:00
|
|
|
@* ─── Enregistrements: les URL same-origin héritent de l'authentification du navigateur et supportent Range. ─── *@
|
|
|
|
|
<MudText Typo="Typo.h6" Class="mb-3">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.VideoLibrary" Class="mr-1" /> @Text["CameraDetail_Recordings"]
|
|
|
|
|
</MudText>
|
|
|
|
|
@if (_recordingsLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudPaper Elevation="0" Class="mb-6" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="96px" />
|
|
|
|
|
</MudPaper>
|
|
|
|
|
}
|
|
|
|
|
else if (_recordings.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
@if (_selectedRecording is not null)
|
|
|
|
|
{
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
<video controls preload="metadata" src="@RecordingContentUrl(_selectedRecording.Id)"
|
|
|
|
|
style="display:block;width:100%;max-height:480px;background:#111;" />
|
|
|
|
|
<div class="d-flex flex-wrap align-center gap-3 mt-3">
|
|
|
|
|
<MudText Typo="Typo.body2">@_selectedRecording.Timestamp.ToLocalTime().ToString("g", Language.Culture)</MudText>
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@FormatRecordingDuration(_selectedRecording.DurationSeconds)</MudText>
|
|
|
|
|
<a href="@RecordingContentUrl(_selectedRecording.Id)"
|
|
|
|
|
download="@RecordingDownloadName(_selectedRecording.Id)">
|
|
|
|
|
@Text["CameraDetail_ExportRecording"]
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</MudPaper>
|
|
|
|
|
}
|
|
|
|
|
<MudTable Items="@_recordings" Hover="true" Elevation="1" Dense="true" Class="mb-6">
|
|
|
|
|
<HeaderContent>
|
|
|
|
|
<MudTh>@Text["CameraDetail_Timestamp"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CameraDetail_Duration"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CameraDetail_Size"]</MudTh>
|
|
|
|
|
<MudTh></MudTh>
|
|
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
|
|
|
|
<MudTd DataLabel="@Text["CameraDetail_Timestamp"]">@context.Timestamp.ToLocalTime().ToString("g", Language.Culture)</MudTd>
|
|
|
|
|
<MudTd DataLabel="@Text["CameraDetail_Duration"]">@FormatRecordingDuration(context.DurationSeconds)</MudTd>
|
|
|
|
|
<MudTd DataLabel="@Text["CameraDetail_Size"]">@FormatRecordingSize(context.SizeBytes)</MudTd>
|
|
|
|
|
<MudTd DataLabel="">
|
|
|
|
|
<MudButton Size="Size.Small" Variant="Variant.Text" OnClick="@(() => SelectRecording(context))">
|
|
|
|
|
@Text["CameraDetail_PlayRecording"]
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudText Class="mb-6" Typo="Typo.body2" Color="Color.Secondary">@Text["CameraDetail_NoRecordings"]</MudText>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<MudPaper Elevation="1" Class="pa-5 mb-6" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
<MudText Typo="Typo.h6" Class="mb-2">@Text["CameraDetail_PlateOcrTitle"]</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">@Text["CameraDetail_PlateOcrPrivacy"]</MudText>
|
|
|
|
|
<InputFile OnChange="RecognizePlateCropAsync" accept="image/jpeg,image/png" disabled="@_recognizingPlate" />
|
|
|
|
|
@if (_recognizingPlate)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" Size="Size.Small" Class="ml-2" />
|
|
|
|
|
}
|
|
|
|
|
@if (!string.IsNullOrEmpty(_plateOcrMessage))
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="@(_plateOcrSuccess ? Severity.Success : Severity.Error)" Class="mt-3">@_plateOcrMessage</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
@if (_plateOcrResult is not null)
|
|
|
|
|
{
|
|
|
|
|
@if (_plateVehicleCandidates.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
<MudText Typo="Typo.body2" Class="mt-3">@Text["CameraDetail_PlateOcrReview"]</MudText>
|
|
|
|
|
<MudSelect T="Guid?" @bind-Value="_selectedPlateVehicleId" Label="@(Text["CameraDetail_PlateOcrSelectVehicle"])"
|
|
|
|
|
Disabled="@(_confirmingPlate || _plateAssociationConfirmed)" Class="mt-2">
|
|
|
|
|
@foreach (var vehicle in _plateVehicleCandidates)
|
|
|
|
|
{
|
|
|
|
|
<MudSelectItem T="Guid?" Value="@((Guid?)vehicle.Id)">
|
|
|
|
|
@FormatPlateVehicle(vehicle)
|
|
|
|
|
</MudSelectItem>
|
|
|
|
|
}
|
|
|
|
|
</MudSelect>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="mt-3"
|
|
|
|
|
Disabled="@(_selectedPlateVehicleId is null || _confirmingPlate || _plateAssociationConfirmed)"
|
|
|
|
|
OnClick="ConfirmPlateAssociationAsync">
|
|
|
|
|
@Text["CameraDetail_PlateOcrConfirm"]
|
|
|
|
|
</MudButton>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Warning" Class="mt-3">@Text["CameraDetail_PlateOcrNoVehicle"]</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</MudPaper>
|
|
|
|
|
|
2026-08-10 23:07:43 +02:00
|
|
|
@* ─── Mini-timeline : événements récents ─── *@
|
|
|
|
|
<MudText Typo="Typo.h6" Class="mb-4">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Notifications" Class="mr-1" /> @Text["CameraDetail_RecentEvents"]
|
2026-07-19 13:21:25 +00:00
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
@if (_eventsLoading)
|
|
|
|
|
{
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudPaper Elevation="0" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="120px" />
|
|
|
|
|
</MudPaper>
|
2026-07-19 13:21:25 +00:00
|
|
|
}
|
|
|
|
|
else if (_events is { Count: > 0 })
|
|
|
|
|
{
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudTable Items="@_events" Hover="true" Elevation="1" Dense="true">
|
2026-07-19 13:21:25 +00:00
|
|
|
<HeaderContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTh>@Text["CameraDetail_Timestamp"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CameraDetail_Type"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CameraDetail_Confidence"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CameraDetail_Label"]</MudTh>
|
2026-07-19 13:21:25 +00:00
|
|
|
<MudTh></MudTh>
|
|
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CameraDetail_Timestamp"]">@context.OccurredAt.ToLocalTime().ToString("g", Language.Culture)</MudTd>
|
|
|
|
|
<MudTd DataLabel="@Text["CameraDetail_Type"]">
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudChip T="string" Size="Size.Small" Color="@GetEventColor(context.Type)" Variant="Variant.Outlined">
|
|
|
|
|
@FormatEventType(context.Type)
|
|
|
|
|
</MudChip>
|
|
|
|
|
</MudTd>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTd DataLabel="@Text["CameraDetail_Confidence"]">@((context.Confidence * 100).ToString("0", Language.Culture) + "%")</MudTd>
|
|
|
|
|
<MudTd DataLabel="@Text["CameraDetail_Label"]">@context.Label</MudTd>
|
2026-07-19 13:21:25 +00:00
|
|
|
<MudTd DataLabel="">
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Image" Size="Size.Small" aria-label="@Text["CameraDetail_ViewSnapshot"]"
|
2026-07-19 13:21:25 +00:00
|
|
|
Disabled="@(context.SnapshotUrl is null)"
|
2026-08-10 23:07:43 +02:00
|
|
|
OnClick="@(() => { _showSnapshotUrl = context.SnapshotUrl; _showSnapshotDialog = true; })" />
|
2026-07-19 13:21:25 +00:00
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
2026-08-10 23:07:43 +02:00
|
|
|
<MudLink Href="@($"/events?q={Uri.EscapeDataString(_camera.Name)}")" Class="mt-2 d-block">
|
2026-07-19 13:21:25 +00:00
|
|
|
Voir tous les événements →
|
|
|
|
|
</MudLink>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText Class="mt-2" Typo="Typo.body2" Color="Color.Default">@Text["CameraDetail_NoRecentEvents"]</MudText>
|
2026-07-19 13:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 23:07:43 +02:00
|
|
|
@* ─── Dialogs (toujours rendus, visibilité via @bind-Visible) ─── *@
|
|
|
|
|
<MudOverlay Visible="@_confirmDeleteShow" OnClick="@(() => _confirmDeleteShow = false)" />
|
|
|
|
|
<MudDialog @bind-Visible="_confirmDeleteShow">
|
2026-10-25 05:59:18 +01:00
|
|
|
<TitleContent><MudText Typo="Typo.h6">@Text["CameraDetail_ConfirmDeleteTitle"]</MudText></TitleContent>
|
2026-08-10 23:07:43 +02:00
|
|
|
<DialogContent>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudText>@string.Format(Language.Culture, Text["CameraDetail_ConfirmDeleteBody"], _camera.Name)</MudText>
|
2026-08-10 23:07:43 +02:00
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteShow = false)">@Text["CameraDetail_Cancel"]</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Error" OnClick="@DeleteCamera">@Text["CameraDetail_Delete"]</MudButton>
|
2026-08-10 23:07:43 +02:00
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
|
|
|
|
<MudDialog @bind-Visible="_showSnapshotDialog" Options="_snapshotOptions">
|
|
|
|
|
<DialogContent>
|
|
|
|
|
@if (_showSnapshotUrl is not null)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
<img src="@_showSnapshotUrl" alt="@Text["CameraDetail_SnapshotAlt"]" style="width:100%;height:auto;" class="rounded-lg" />
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudButton OnClick="@(() => _showSnapshotDialog = false)">@Text["CameraDetail_Close"]</MudButton>
|
2026-08-10 23:07:43 +02:00
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
[Parameter] public Guid Id { get; set; }
|
|
|
|
|
|
|
|
|
|
private CameraItem? _camera;
|
|
|
|
|
private string _editName = "";
|
|
|
|
|
private string? _editRtspUrl;
|
2026-11-06 11:14:49 +01:00
|
|
|
private bool _recordingEnabled;
|
|
|
|
|
private bool _eventRecordingEnabled;
|
2026-07-17 19:08:17 +00:00
|
|
|
private string _editError = "";
|
|
|
|
|
private string _editSuccess = "";
|
2026-07-19 13:21:25 +00:00
|
|
|
private bool _loading = true;
|
|
|
|
|
private bool _saving;
|
2026-10-25 02:30:17 +02:00
|
|
|
private bool _togglingStatus;
|
2026-08-10 23:07:43 +02:00
|
|
|
private bool _showRtsp;
|
|
|
|
|
private bool _confirmDeleteShow;
|
2026-11-06 11:14:49 +01:00
|
|
|
private bool _recognizingPlate;
|
|
|
|
|
private bool _plateOcrSuccess;
|
|
|
|
|
private string? _plateOcrMessage;
|
|
|
|
|
private Heimdall.Application.Services.LicensePlateRecognitionResponse? _plateOcrResult;
|
|
|
|
|
private List<VehicleClientItem> _plateVehicleCandidates = [];
|
|
|
|
|
private Guid? _selectedPlateVehicleId;
|
|
|
|
|
private bool _confirmingPlate;
|
|
|
|
|
private bool _plateAssociationConfirmed;
|
2026-07-19 13:21:25 +00:00
|
|
|
|
|
|
|
|
private List<EventItem>? _events;
|
2026-11-06 11:14:49 +01:00
|
|
|
private List<RecordingItem> _recordings = [];
|
|
|
|
|
private RecordingItem? _selectedRecording;
|
|
|
|
|
private bool _recordingsLoading;
|
2026-07-19 13:21:25 +00:00
|
|
|
private bool _eventsLoading;
|
|
|
|
|
private string? _showSnapshotUrl;
|
|
|
|
|
private bool _showSnapshotDialog;
|
|
|
|
|
private readonly DialogOptions _snapshotOptions = new()
|
|
|
|
|
{
|
|
|
|
|
FullWidth = true,
|
|
|
|
|
MaxWidth = MaxWidth.Large,
|
|
|
|
|
CloseButton = true
|
|
|
|
|
};
|
2026-07-17 19:08:17 +00:00
|
|
|
|
2026-08-10 23:07:43 +02:00
|
|
|
private string? _latestSnapshotUrl;
|
2026-10-23 07:20:47 +02:00
|
|
|
private DateTime? _latestSnapshotAt;
|
2026-08-10 23:07:43 +02:00
|
|
|
private bool _snapshotLoading;
|
|
|
|
|
private CancellationTokenSource? _refreshCts;
|
|
|
|
|
private bool _disposed;
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Language.LanguageChanged += OnLanguageChanged;
|
2026-07-17 19:08:17 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_camera = await Api.GetCameraAsync(Id);
|
|
|
|
|
if (_camera is not null)
|
|
|
|
|
{
|
|
|
|
|
_editName = _camera.Name;
|
|
|
|
|
_editRtspUrl = _camera.RtspUrl;
|
2026-11-06 11:14:49 +01:00
|
|
|
_recordingEnabled = _camera.RecordingEnabled;
|
|
|
|
|
_eventRecordingEnabled = _camera.EventRecordingEnabled;
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-11-08 13:02:38 +01:00
|
|
|
catch (HttpRequestException ex) when (IsMissingOrHiddenResource(ex))
|
|
|
|
|
{
|
|
|
|
|
// Le filtre d'accès renvoie 403 pour masquer une caméra absente ou non accessible.
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { Snackbar.Add(Text["CameraDetail_OperationFailed"], Severity.Error); }
|
2026-07-17 19:08:17 +00:00
|
|
|
finally { _loading = false; }
|
2026-07-19 13:21:25 +00:00
|
|
|
|
2026-11-08 13:02:38 +01:00
|
|
|
if (_camera is not null)
|
|
|
|
|
{
|
|
|
|
|
await LoadEventsAsync();
|
|
|
|
|
await LoadRecordingsAsync();
|
|
|
|
|
await LoadLatestSnapshotAsync();
|
|
|
|
|
}
|
2026-08-11 11:59:18 +02:00
|
|
|
}
|
|
|
|
|
|
2026-11-08 13:02:38 +01:00
|
|
|
private static bool IsMissingOrHiddenResource(HttpRequestException exception) =>
|
|
|
|
|
exception.StatusCode is System.Net.HttpStatusCode.NotFound or System.Net.HttpStatusCode.Forbidden;
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
private void OnLanguageChanged() => _ = InvokeAsync(StateHasChanged);
|
|
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
// L'auto-refresh démarre après le premier rendu : une boucle infinie
|
|
|
|
|
// awaitée dans OnInitializedAsync bloque le rendu initial (SSR/prerender
|
|
|
|
|
// attend la fin du cycle de vie) → page lente.
|
|
|
|
|
private bool _autoRefreshStarted;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
2026-11-08 13:02:38 +01:00
|
|
|
if (firstRender && !_autoRefreshStarted && _camera is not null)
|
2026-08-11 11:59:18 +02:00
|
|
|
{
|
|
|
|
|
_autoRefreshStarted = true;
|
|
|
|
|
await StartAutoRefresh();
|
|
|
|
|
}
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadEventsAsync()
|
|
|
|
|
{
|
2026-07-19 13:21:25 +00:00
|
|
|
try { _eventsLoading = true; _events = await Api.GetRecentEventsAsync(Id, 10); }
|
|
|
|
|
catch { }
|
|
|
|
|
finally { _eventsLoading = false; }
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
2026-11-06 11:14:49 +01:00
|
|
|
private async Task RecognizePlateCropAsync(InputFileChangeEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var file = args.File;
|
|
|
|
|
if (file.Size is < 16 or > 512 * 1024 || file.ContentType is not ("image/jpeg" or "image/png"))
|
|
|
|
|
{
|
|
|
|
|
_plateOcrSuccess = false;
|
|
|
|
|
_plateOcrMessage = Text["CameraDetail_PlateOcrInvalid"];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_recognizingPlate = true;
|
|
|
|
|
_plateOcrMessage = null;
|
|
|
|
|
_plateOcrResult = null;
|
|
|
|
|
_plateVehicleCandidates = [];
|
|
|
|
|
_selectedPlateVehicleId = null;
|
|
|
|
|
_plateAssociationConfirmed = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await using var stream = file.OpenReadStream(512 * 1024);
|
|
|
|
|
var response = await Api.RecognizePlateCropAsync(Id, stream, file.ContentType, file.Name);
|
|
|
|
|
_plateOcrSuccess = response.Succeeded;
|
|
|
|
|
if (!response.Succeeded || response.Data is null)
|
|
|
|
|
{
|
|
|
|
|
_plateOcrMessage = response.ErrorMessage ?? Text["CameraDetail_OperationFailed"];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_plateOcrResult = response.Data;
|
|
|
|
|
_plateOcrMessage = string.Format(Language.Culture, Text["CameraDetail_PlateOcrResult"], response.Data.PlateText,
|
|
|
|
|
(response.Data.Confidence * 100).ToString("0", Language.Culture));
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var candidates = await Api.GetVehiclesAsync(search: response.Data.PlateText, pageSize: 100) ?? [];
|
|
|
|
|
_plateVehicleCandidates = candidates
|
|
|
|
|
.Where(vehicle => NormalizePlateText(vehicle.LicensePlate) == NormalizePlateText(response.Data.PlateText))
|
|
|
|
|
.ToList();
|
|
|
|
|
if (response.Data.SuggestedVehicleId is Guid suggestedId &&
|
|
|
|
|
_plateVehicleCandidates.Any(vehicle => vehicle.Id == suggestedId))
|
|
|
|
|
_selectedPlateVehicleId = suggestedId;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_plateVehicleCandidates = [];
|
|
|
|
|
}
|
|
|
|
|
await LoadEventsAsync();
|
|
|
|
|
}
|
|
|
|
|
catch { _plateOcrSuccess = false; _plateOcrMessage = Text["CameraDetail_OperationFailed"]; }
|
|
|
|
|
finally { _recognizingPlate = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ConfirmPlateAssociationAsync()
|
|
|
|
|
{
|
|
|
|
|
if (_plateOcrResult is null || _selectedPlateVehicleId is not Guid vehicleId || _plateAssociationConfirmed || _confirmingPlate)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_confirmingPlate = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await Api.ConfirmPlateAssociationAsync(
|
|
|
|
|
Id, _plateOcrResult.PlateId, _plateOcrResult.EventId, vehicleId);
|
|
|
|
|
if (response.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
_plateAssociationConfirmed = true;
|
|
|
|
|
_plateOcrMessage = Text["CameraDetail_PlateOcrLinked"];
|
|
|
|
|
await LoadEventsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_plateOcrSuccess = false;
|
|
|
|
|
_plateOcrMessage = response.ErrorMessage ?? Text["CameraDetail_OperationFailed"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_plateOcrSuccess = false;
|
|
|
|
|
_plateOcrMessage = Text["CameraDetail_OperationFailed"];
|
|
|
|
|
}
|
|
|
|
|
finally { _confirmingPlate = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string NormalizePlateText(string? value) => value is null
|
|
|
|
|
? string.Empty
|
|
|
|
|
: new string(value.Where(char.IsAsciiLetterOrDigit).Select(char.ToUpperInvariant).ToArray());
|
|
|
|
|
|
|
|
|
|
private static string FormatPlateVehicle(VehicleClientItem vehicle)
|
|
|
|
|
{
|
|
|
|
|
var identity = string.Join(" ", new[] { vehicle.Make, vehicle.Model, vehicle.Color }.Where(value => !string.IsNullOrWhiteSpace(value)));
|
|
|
|
|
return string.IsNullOrWhiteSpace(identity) ? vehicle.LicensePlate ?? vehicle.Id.ToString("D") : $"{vehicle.LicensePlate} — {identity}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task LoadRecordingsAsync()
|
|
|
|
|
{
|
|
|
|
|
_recordingsLoading = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var page = await Api.GetCameraRecordingsAsync(Id);
|
|
|
|
|
_recordings = page?.Items.ToList() ?? [];
|
|
|
|
|
_selectedRecording = _recordings.FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
catch { _recordings = []; _selectedRecording = null; }
|
|
|
|
|
finally { _recordingsLoading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectRecording(RecordingItem recording) => _selectedRecording = recording;
|
|
|
|
|
private static string RecordingContentUrl(Guid recordingId) => $"/api/recordings/{recordingId:D}/content";
|
|
|
|
|
private static string RecordingDownloadName(Guid recordingId) => $"heimdall-recording-{recordingId:N}.mp4";
|
|
|
|
|
private static string FormatRecordingDuration(double seconds) => TimeSpan.FromSeconds(seconds).ToString("hh\\:mm\\:ss");
|
|
|
|
|
private static string FormatRecordingSize(long bytes) => bytes >= 1024 * 1024
|
|
|
|
|
? $"{bytes / 1024d / 1024d:0.0} MB"
|
|
|
|
|
: $"{bytes / 1024d:0} KB";
|
|
|
|
|
|
2026-08-10 23:07:43 +02:00
|
|
|
private async Task LoadLatestSnapshotAsync()
|
|
|
|
|
{
|
|
|
|
|
_snapshotLoading = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-10-23 07:20:47 +02:00
|
|
|
var events = await Api.GetRecentEventsAsync(Id, 20);
|
|
|
|
|
var latest = events?.FirstOrDefault(e => !string.IsNullOrEmpty(e.SnapshotThumbUrl ?? e.SnapshotUrl));
|
|
|
|
|
_latestSnapshotUrl = latest?.SnapshotThumbUrl ?? latest?.SnapshotUrl;
|
|
|
|
|
_latestSnapshotAt = latest?.OccurredAt;
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
|
|
|
|
catch { /* flux indisponible */ }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_snapshotLoading = false;
|
|
|
|
|
if (!_disposed) await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task StartAutoRefresh()
|
|
|
|
|
{
|
|
|
|
|
_refreshCts = new CancellationTokenSource();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
while (!_refreshCts.Token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(10), _refreshCts.Token);
|
|
|
|
|
if (!_disposed) await LoadLatestSnapshotAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (OperationCanceledException) { /* arrêt volontaire */ }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task RefreshSnapshot() => await LoadLatestSnapshotAsync();
|
|
|
|
|
|
2026-10-23 07:20:47 +02:00
|
|
|
private async Task TakeSnapshot()
|
|
|
|
|
{
|
|
|
|
|
_snapshotLoading = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var request = await Api.RequestCameraSnapshotAsync(Id);
|
|
|
|
|
if (!request.Succeeded || request.Data == Guid.Empty)
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(request.ErrorMessage ?? Text["CameraDetail_OperationFailed"], Severity.Error);
|
2026-10-23 07:20:47 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CameraDetail_CaptureRequested"], Severity.Info);
|
2026-10-23 07:30:58 +02:00
|
|
|
for (var attempt = 0; attempt < 35 && !_disposed; attempt++)
|
2026-10-23 07:20:47 +02:00
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
2026-10-23 07:30:58 +02:00
|
|
|
var status = await Api.GetCameraSnapshotStatusAsync(Id, request.Data);
|
|
|
|
|
if (status?.Status is "Failed" or "TimedOut")
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(status.Reason ?? Text["CameraDetail_CaptureFailed"], Severity.Error);
|
2026-10-23 07:30:58 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (status?.Status != "Completed") continue;
|
|
|
|
|
var snapshot = await Api.GetEventAsync(request.Data);
|
|
|
|
|
if (snapshot is null || string.IsNullOrEmpty(snapshot.SnapshotUrl)) continue;
|
2026-10-23 07:20:47 +02:00
|
|
|
_latestSnapshotUrl = snapshot.SnapshotThumbUrl ?? snapshot.SnapshotUrl;
|
|
|
|
|
_latestSnapshotAt = snapshot.OccurredAt;
|
|
|
|
|
await LoadEventsAsync();
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CameraDetail_SnapshotAvailable"], Severity.Success);
|
2026-10-23 07:20:47 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(Text["CameraDetail_CapturePending"], Severity.Info);
|
2026-10-23 07:20:47 +02:00
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { Snackbar.Add(Text["CameraDetail_OperationFailed"], Severity.Error); }
|
2026-10-23 07:20:47 +02:00
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_snapshotLoading = false;
|
|
|
|
|
if (!_disposed) await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
private async Task SaveCamera()
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
if (string.IsNullOrWhiteSpace(_editName)) { _editError = Text["CameraDetail_NameRequired"]; return; }
|
2026-07-17 19:08:17 +00:00
|
|
|
_saving = true;
|
|
|
|
|
_editError = "";
|
|
|
|
|
_editSuccess = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-11-06 11:14:49 +01:00
|
|
|
if (await Api.UpdateCameraAsync(Id, _editName, _editRtspUrl, null,
|
|
|
|
|
recordingEnabled: _recordingEnabled, eventRecordingEnabled: _eventRecordingEnabled))
|
2026-07-17 19:08:17 +00:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
_editSuccess = Text["CameraDetail_Updated"];
|
2026-07-17 19:08:17 +00:00
|
|
|
if (_camera is not null) _camera.Name = _editName;
|
2026-11-06 11:14:49 +01:00
|
|
|
if (_camera is not null) _camera.RecordingEnabled = _recordingEnabled;
|
|
|
|
|
if (_camera is not null) _camera.EventRecordingEnabled = _eventRecordingEnabled;
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
else _editError = Text["CameraDetail_UpdateError"];
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { _editError = Text["CameraDetail_OperationFailed"]; }
|
2026-07-17 19:08:17 +00:00
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 23:07:43 +02:00
|
|
|
private async Task ToggleCameraStatus()
|
|
|
|
|
{
|
2026-10-25 02:30:17 +02:00
|
|
|
if (_camera is null || _saving || _togglingStatus) return;
|
2026-08-10 23:07:43 +02:00
|
|
|
_saving = true;
|
2026-10-25 02:30:17 +02:00
|
|
|
_togglingStatus = true;
|
2026-08-10 23:07:43 +02:00
|
|
|
_editError = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
2026-08-19 22:38:34 +02:00
|
|
|
var result = await Api.ToggleCameraStatusAsync(Id);
|
|
|
|
|
if (result.Succeeded && result.Data is not null)
|
2026-08-10 23:07:43 +02:00
|
|
|
{
|
2026-08-19 22:38:34 +02:00
|
|
|
_camera.Status = result.Data.Status;
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(result.Data.Status == "Online" ? Text["CameraDetail_Enabled"] : Text["CameraDetail_Disabled"], Severity.Success);
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
else _editError = result.ErrorMessage ?? Text["CameraDetail_StatusError"];
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
catch { _editError = Text["CameraDetail_OperationFailed"]; }
|
2026-10-25 02:30:17 +02:00
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_saving = false;
|
|
|
|
|
_togglingStatus = false;
|
|
|
|
|
}
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DeleteCamera()
|
|
|
|
|
{
|
|
|
|
|
if (_camera is null) return;
|
|
|
|
|
if (await Api.DeleteCameraAsync(Id))
|
|
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Snackbar.Add(string.Format(Language.Culture, Text["CameraDetail_Deleted"], _camera.Name), Severity.Success);
|
2026-08-10 23:07:43 +02:00
|
|
|
Nav.NavigateTo($"/sites/{_camera.SiteId}/cameras");
|
|
|
|
|
}
|
2026-10-25 05:59:18 +01:00
|
|
|
else Snackbar.Add(Text["CameraDetail_DeleteError"], Severity.Error);
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
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" => "○",
|
|
|
|
|
_ => "?"
|
|
|
|
|
};
|
2026-08-10 23:07:43 +02:00
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
private string FormatStatus(string status) => status switch
|
2026-08-10 23:07:43 +02:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
"Online" => Text["CameraDetail_StatusOnline"],
|
|
|
|
|
"Offline" => Text["CameraDetail_StatusOffline"],
|
|
|
|
|
"Disabled" => Text["CameraDetail_StatusDisabled"],
|
2026-08-10 23:07:43 +02:00
|
|
|
_ => status
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
private string FormatEventType(string type) => type switch
|
2026-08-10 23:07:43 +02:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
"ManualSnapshot" => Text["CameraDetail_EventManualSnapshot"],
|
|
|
|
|
"MotionDetected" => Text["CameraDetail_EventMotion"],
|
|
|
|
|
"PersonDetected" => Text["CameraDetail_EventPerson"],
|
|
|
|
|
"VehicleDetected" => Text["CameraDetail_EventVehicle"],
|
|
|
|
|
"FaceRecognized" => Text["CameraDetail_EventFace"],
|
2026-11-06 11:14:49 +01:00
|
|
|
"LicensePlateDetected" => Text["LicensePlateDetected"],
|
2026-10-25 05:59:18 +01:00
|
|
|
"CameraOffline" => Text["CameraDetail_StatusOffline"],
|
2026-08-10 23:07:43 +02:00
|
|
|
_ => type
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static Color GetEventColor(string type) => type switch
|
|
|
|
|
{
|
|
|
|
|
"MotionDetected" => Color.Warning,
|
|
|
|
|
"PersonDetected" => Color.Error,
|
|
|
|
|
"VehicleDetected" => Color.Info,
|
|
|
|
|
"FaceRecognized" => Color.Success,
|
2026-11-06 11:14:49 +01:00
|
|
|
"LicensePlateDetected" => Color.Info,
|
2026-08-10 23:07:43 +02:00
|
|
|
_ => Color.Default
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-06 11:14:49 +01:00
|
|
|
private ElementReference _liveVideo;
|
|
|
|
|
private IJSObjectReference? _liveModule;
|
|
|
|
|
private bool _liveEnabled;
|
|
|
|
|
private bool _liveStarting;
|
|
|
|
|
|
|
|
|
|
private async Task ToggleLive()
|
|
|
|
|
{
|
|
|
|
|
if (_camera is null || _liveStarting) return;
|
|
|
|
|
_liveStarting = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_liveModule ??= await JS.InvokeAsync<IJSObjectReference>("import", "./js/live-view.js");
|
|
|
|
|
if (_liveEnabled)
|
|
|
|
|
{
|
|
|
|
|
await _liveModule.InvokeVoidAsync("stop", _camera.Id);
|
|
|
|
|
_liveEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _liveModule.InvokeVoidAsync("start", _camera.Id, _liveVideo);
|
|
|
|
|
_liveEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { Snackbar.Add(Text["CameraDetail_LiveUnavailable"], Severity.Warning); }
|
|
|
|
|
finally { _liveStarting = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ValueTask DisposeAsync()
|
2026-08-10 23:07:43 +02:00
|
|
|
{
|
2026-10-25 05:59:18 +01:00
|
|
|
Language.LanguageChanged -= OnLanguageChanged;
|
2026-08-10 23:07:43 +02:00
|
|
|
_disposed = true;
|
|
|
|
|
_refreshCts?.Cancel();
|
|
|
|
|
_refreshCts?.Dispose();
|
2026-11-06 11:14:49 +01:00
|
|
|
if (_liveModule is not null)
|
|
|
|
|
{
|
|
|
|
|
try { if (_camera is not null) await _liveModule.InvokeVoidAsync("stop", _camera.Id); await _liveModule.DisposeAsync(); }
|
|
|
|
|
catch (JSDisconnectedException) { }
|
|
|
|
|
}
|
2026-08-10 23:07:43 +02:00
|
|
|
}
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|