Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d73869153 | ||
|
|
804125693c | ||
|
|
019a6df9eb | ||
|
|
e51ed2c858 | ||
|
|
0042bf6abc | ||
|
|
b9f356940c | ||
|
|
944429102c | ||
|
|
4dab9d35d4 |
No files matched your search
@@ -385,3 +385,7 @@ Ces liens correspondent aux fichiers inspectés ; les numéros désignent le dé
|
||||
| OPS-04 | [src/Heimdall.Infrastructure/BackgroundJobs/JobSetup.cs:64](../../src/Heimdall.Infrastructure/BackgroundJobs/JobSetup.cs#L64) |
|
||||
| OPS-05 | [src/Heimdall.Web/Controllers/UpdatesController.cs:59](../../src/Heimdall.Web/Controllers/UpdatesController.cs#L59) |
|
||||
| UI-01 | [src/Heimdall.Web/Components/Pages/SnapshotsPage.razor:44](../../src/Heimdall.Web/Components/Pages/SnapshotsPage.razor#L44) |
|
||||
|
||||
## Suivi de correction — lot 4 (20 octobre 2026)
|
||||
|
||||
La sécurité des chemins locaux (SEC-08) est déjà livrée dans la PR #2 fusionnée. Cette PR améliore la galerie : elle utilise les filtres snapshot, caméra/libellé et type côté API, avec pagination serveur, et conserve l’image originale en fallback si la miniature manque. Le build Web passe sans avertissement ni erreur et les tests ciblés du handler passent (4/4). La capture/lecture complète reste à réaliser ; son flux attend le contrôle d’accès livré dans la PR #2.
|
||||
@@ -53,10 +53,14 @@ public class GetEventsHandler : IRequestHandler<GetEventsQuery, ServiceResult<Pa
|
||||
if (request.MinConfidence.HasValue)
|
||||
query = query.Where(e => e.Confidence >= request.MinConfidence.Value);
|
||||
|
||||
if (request.HasSnapshot)
|
||||
query = query.Where(e => e.SnapshotUrl != null);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Search))
|
||||
{
|
||||
var search = request.Search.Trim();
|
||||
query = query.Where(e => (e.Label ?? "").Contains(search, StringComparison.OrdinalIgnoreCase));
|
||||
query = query.Where(e => (e.Label ?? "").Contains(search, StringComparison.OrdinalIgnoreCase)
|
||||
|| e.Camera.Name.Contains(search, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
var total = await query.CountAsync(ct).ConfigureAwait(false);
|
||||
|
||||
@@ -15,4 +15,5 @@ public record GetEventsQuery(
|
||||
int Page = 1,
|
||||
int PageSize = 50,
|
||||
string? Search = null,
|
||||
Guid? UserId = null) : IRequest<ServiceResult<PagedResult<CameraEventResponse>>>;
|
||||
Guid? UserId = null,
|
||||
bool HasSnapshot = false) : IRequest<ServiceResult<PagedResult<CameraEventResponse>>>;
|
||||
@@ -1,4 +1,5 @@
|
||||
@page "/snapshots"
|
||||
@using Heimdall.Domain.Enums
|
||||
@attribute [Authorize]
|
||||
@layout MainLayout
|
||||
@inject HeimdallApiClient Api
|
||||
@@ -12,9 +13,19 @@
|
||||
|
||||
<MudPaper Elevation="1" Class="pa-4 mb-4">
|
||||
<MudToolBar>
|
||||
<MudTextField @bind-Value="_search" Label="Rechercher (type, label, caméra)" Variant="Variant.Outlined"
|
||||
<MudTextField @bind-Value="_search" Label="Rechercher (label ou caméra)" Variant="Variant.Outlined"
|
||||
Class="mr-2" style="min-width:300px;" Placeholder="ex: Personne, Visage..." />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@LoadSnapshots">
|
||||
<MudSelect T="string" @bind-Value="_type" Label="Type" Variant="Variant.Outlined" Clearable="true" Class="mr-2" Style="min-width:180px;">
|
||||
<MudSelectItem Value="@nameof(EventType.MotionDetected)">Mouvement</MudSelectItem>
|
||||
<MudSelectItem Value="@nameof(EventType.PersonDetected)">Personne</MudSelectItem>
|
||||
<MudSelectItem Value="@nameof(EventType.VehicleDetected)">Véhicule</MudSelectItem>
|
||||
<MudSelectItem Value="@nameof(EventType.UnknownPerson)">Personne inconnue</MudSelectItem>
|
||||
<MudSelectItem Value="@nameof(EventType.FaceRecognized)">Visage reconnu</MudSelectItem>
|
||||
<MudSelectItem Value="@nameof(EventType.LicensePlateDetected)">Plaque détectée</MudSelectItem>
|
||||
<MudSelectItem Value="@nameof(EventType.CameraOffline)">Caméra hors ligne</MudSelectItem>
|
||||
<MudSelectItem Value="@nameof(EventType.CameraOnline)">Caméra en ligne</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@ApplyFilters">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Search" Class="mr-1" Size="Size.Small" /> Charger
|
||||
</MudButton>
|
||||
</MudToolBar>
|
||||
@@ -41,7 +52,7 @@ else
|
||||
@key="ev.Id">
|
||||
<div @onclick="() => OpenLightbox(ev)" role="button" tabindex="0"
|
||||
style="cursor: pointer;">
|
||||
<img src="@ev.SnapshotThumbUrl ?? ev.SnapshotUrl" alt="Snapshot"
|
||||
<img src="@(ev.SnapshotThumbUrl ?? ev.SnapshotUrl)" alt="Snapshot"
|
||||
style="width:100%;height:160px;object-fit:cover;border-radius:4px;" />
|
||||
<MudText Typo="Typo.caption" Class="mt-1" Color="Color.Secondary">
|
||||
@FormatEventType(ev.Type) · @ev.Confidence.ToString("P0")
|
||||
@@ -53,6 +64,11 @@ else
|
||||
</MudPaper>
|
||||
}
|
||||
</div>
|
||||
<div class="d-flex align-center justify-center mt-4" style="gap:16px;">
|
||||
<MudButton Disabled="@(_page <= 1)" OnClick="@(() => GoToPage(_page - 1))">Précédent</MudButton>
|
||||
<MudText Typo="Typo.body2">Page @_page / @_totalPages · @_total snapshot(s)</MudText>
|
||||
<MudButton Disabled="@(_page >= _totalPages)" OnClick="@(() => GoToPage(_page + 1))">Suivant</MudButton>
|
||||
</div>
|
||||
}
|
||||
|
||||
@* Lightbox toujours rendu : la visibilité est pilotée uniquement par @bind-Visible.
|
||||
@@ -86,7 +102,12 @@ else
|
||||
|
||||
@code {
|
||||
private string _search = "";
|
||||
private string? _type;
|
||||
private List<EventItem>? _snapshots;
|
||||
private int _page = 1;
|
||||
private int _totalPages = 1;
|
||||
private int _total;
|
||||
private const int PageSize = 48;
|
||||
private bool _loading;
|
||||
private bool _showLightbox;
|
||||
private EventItem? _lightboxEvent;
|
||||
@@ -107,17 +128,12 @@ else
|
||||
try
|
||||
{
|
||||
var ct = _cts.Token;
|
||||
var result = await Api.GetEventsAsync(null, null, 1, 100);
|
||||
var result = await Api.GetEventsAsync(null, null, _page, PageSize,
|
||||
string.IsNullOrWhiteSpace(_search) ? null : _search, _type, hasSnapshot: true);
|
||||
ct.ThrowIfCancellationRequested();
|
||||
var items = result?.Items ?? [];
|
||||
if (!string.IsNullOrWhiteSpace(_search))
|
||||
{
|
||||
var q = _search.ToLowerInvariant();
|
||||
items = items.Where(e =>
|
||||
(e.Label?.ToLowerInvariant().Contains(q) ?? false) ||
|
||||
e.Type.ToLowerInvariant().Contains(q)).ToList();
|
||||
}
|
||||
_snapshots = items.Where(e => e.SnapshotUrl is not null).ToList();
|
||||
_snapshots = result?.Items ?? [];
|
||||
_total = result?.TotalCount ?? 0;
|
||||
_totalPages = Math.Max(1, (int)Math.Ceiling(_total / (double)PageSize));
|
||||
}
|
||||
catch (OperationCanceledException) when (_cts.IsCancellationRequested) { }
|
||||
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
||||
@@ -126,6 +142,18 @@ else
|
||||
|
||||
public void Dispose() => _cts.Cancel();
|
||||
|
||||
private async Task GoToPage(int page)
|
||||
{
|
||||
_page = page;
|
||||
await LoadSnapshots();
|
||||
}
|
||||
|
||||
private async Task ApplyFilters()
|
||||
{
|
||||
_page = 1;
|
||||
await LoadSnapshots();
|
||||
}
|
||||
|
||||
private void OpenLightbox(EventItem ev)
|
||||
{
|
||||
_lightboxEvent = ev;
|
||||
|
||||
@@ -68,6 +68,7 @@ public class EventsController : ControllerBase
|
||||
[FromQuery] DateTime? from,
|
||||
[FromQuery] DateTime? to,
|
||||
[FromQuery] double? minConfidence,
|
||||
[FromQuery] bool hasSnapshot = false,
|
||||
[FromQuery] int page = 1,
|
||||
[FromQuery] int pageSize = 50,
|
||||
CancellationToken ct = default)
|
||||
@@ -77,7 +78,7 @@ public class EventsController : ControllerBase
|
||||
parsedType = t;
|
||||
|
||||
var userId = GetUserId();
|
||||
var result = await _mediator.Send(new GetEventsQuery(cameraId, siteId, parsedType, from, to, minConfidence, page, pageSize, q, userId), ct);
|
||||
var result = await _mediator.Send(new GetEventsQuery(cameraId, siteId, parsedType, from, to, minConfidence, page, pageSize, q, userId, hasSnapshot), ct);
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
|
||||
@@ -828,12 +828,13 @@ public class HeimdallApiClient
|
||||
// ─── Events ────────────────────────────────────────────────────────
|
||||
|
||||
public async Task<EventPageResult?> GetEventsAsync(Guid? cameraId, Guid? siteId, int page = 1, int pageSize = 50,
|
||||
string? q = null, string? type = null, DateTime? from = null, DateTime? to = null)
|
||||
string? q = null, string? type = null, DateTime? from = null, DateTime? to = null, bool hasSnapshot = false)
|
||||
{
|
||||
var client = CreateClient();
|
||||
var query = $"page={page}&pageSize={pageSize}";
|
||||
if (cameraId.HasValue) query += $"&cameraId={cameraId}";
|
||||
if (siteId.HasValue) query += $"&siteId={siteId}";
|
||||
if (hasSnapshot) query += "&hasSnapshot=true";
|
||||
if (!string.IsNullOrWhiteSpace(q)) query += $"&q={Uri.EscapeDataString(q)}";
|
||||
if (!string.IsNullOrWhiteSpace(type)) query += $"&type={Uri.EscapeDataString(type)}";
|
||||
if (from.HasValue) query += $"&from={Uri.EscapeDataString(from.Value.ToString("O", System.Globalization.CultureInfo.InvariantCulture))}";
|
||||
|
||||
@@ -93,4 +93,30 @@ public class GetEventsHandlerTests
|
||||
result.Data!.Items.Count.ShouldBe(1);
|
||||
result.Data.Items[0].Label.ShouldBe("Jean Dupont");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_events_should_search_camera_name_and_filter_to_snapshots_before_paging()
|
||||
{
|
||||
var site = new Site("Test", "Paris", "Europe/Paris");
|
||||
var camera = new Camera(site.Id, "North Gate");
|
||||
var withSnapshot = new CameraEvent(camera.Id, EventType.PersonDetected, 0.9, DateTime.UtcNow);
|
||||
withSnapshot.SetSnapshot("snapshot.jpg", "thumb.jpg");
|
||||
withSnapshot.SetCamera(camera);
|
||||
var withoutSnapshot = new CameraEvent(camera.Id, EventType.MotionDetected, 0.8, DateTime.UtcNow);
|
||||
withoutSnapshot.SetCamera(camera);
|
||||
|
||||
var context = Substitute.For<IApplicationDbContext>();
|
||||
context.CameraEvents.Returns(MockDbSetHelper.CreateFor<CameraEvent>([withSnapshot, withoutSnapshot]));
|
||||
var cameraAccess = Substitute.For<ICameraAccessService>();
|
||||
cameraAccess.GetUserAccessibleCameraIdsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns([camera.Id]);
|
||||
var handler = new GetEventsHandler(context, cameraAccess);
|
||||
|
||||
var result = await handler.Handle(new GetEventsQuery(null, null, null, null, null, null,
|
||||
Page: 1, PageSize: 50, Search: "NORTH GATE", HasSnapshot: true), CancellationToken.None);
|
||||
|
||||
result.IsSuccess.ShouldBeTrue();
|
||||
result.Data!.TotalCount.ShouldBe(1);
|
||||
result.Data.Items.ShouldHaveSingleItem().SnapshotUrl.ShouldBe("snapshot.jpg");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user