2026-07-16 21:19:16 +00:00
|
|
|
@page "/"
|
|
|
|
|
@page "/dashboard"
|
|
|
|
|
@attribute [Authorize]
|
|
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject AuthState Auth
|
|
|
|
|
@inject ISnackbar Snackbar
|
2026-10-25 04:19:19 +01:00
|
|
|
@inject UiLanguageService Language
|
|
|
|
|
@inject UiText Text
|
2026-10-25 05:59:18 +01:00
|
|
|
@implements IDisposable
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-08-10 22:41:49 +02:00
|
|
|
<MudText Typo="Typo.h1" Class="mb-1">
|
2026-10-25 04:19:19 +01:00
|
|
|
@Text["Dashboard"]
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudText>
|
2026-07-19 07:12:40 +00:00
|
|
|
<MudText Typo="Typo.body1" Class="mb-2">
|
2026-10-25 04:19:19 +01:00
|
|
|
@Text["WelcomeUser"], <strong>@Auth.User?.DisplayName</strong>
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudText>
|
2026-07-19 07:12:40 +00:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Update" Size="Size.Small" Class="mr-1" />
|
2026-10-25 04:19:19 +01:00
|
|
|
@Text["LastUpdated"] @_lastRefresh.ToString("T", Language.Culture)
|
2026-07-19 07:12:40 +00:00
|
|
|
</MudText>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
@* Stats Cards Row — tuiles uniformes (StatTile, hauteur 100%) *@
|
2026-07-16 21:19:16 +00:00
|
|
|
<MudGrid>
|
2026-08-11 11:59:18 +02:00
|
|
|
<MudItem xs="12" sm="6" lg="3" Class="d-flex">
|
2026-10-25 04:19:19 +01:00
|
|
|
<StatTile Label="@Text["CameraCount"]"
|
2026-08-11 11:59:18 +02:00
|
|
|
Value="@(_stats?.TotalCameras.ToString() ?? "—")"
|
|
|
|
|
Icon="@Icons.Material.Filled.Videocam"
|
|
|
|
|
IconColor="Color.Primary"
|
|
|
|
|
Loading="@_loading">
|
|
|
|
|
<Footer>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.caption" Color="Color.Success">@(_stats?.CamerasOnline ?? 0) @Text["Online"]</MudText>
|
|
|
|
|
<MudText Typo="Typo.caption" Color="Color.Error">@(_stats?.CamerasOffline ?? 0) @Text["Offline"]</MudText>
|
2026-08-11 11:59:18 +02:00
|
|
|
</Footer>
|
|
|
|
|
</StatTile>
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudItem>
|
2026-08-11 11:59:18 +02:00
|
|
|
<MudItem xs="12" sm="6" lg="3" Class="d-flex">
|
2026-10-25 04:19:19 +01:00
|
|
|
<StatTile Label="@Text["OnlineAgents"]"
|
2026-08-11 11:59:18 +02:00
|
|
|
Value="@(_stats?.OnlineAgents.ToString() ?? "—")"
|
|
|
|
|
Icon="@Icons.Material.Filled.Memory"
|
|
|
|
|
IconColor="Color.Success"
|
|
|
|
|
Loading="@_loading">
|
|
|
|
|
<Footer>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.caption" Color="Color.Secondary">@(_stats?.TotalAgents ?? 0) @Text["Total"]</MudText>
|
2026-08-11 11:59:18 +02:00
|
|
|
</Footer>
|
|
|
|
|
</StatTile>
|
2026-07-17 15:10:14 +00:00
|
|
|
</MudItem>
|
2026-08-11 11:59:18 +02:00
|
|
|
<MudItem xs="12" sm="6" lg="3" Class="d-flex">
|
2026-10-25 04:19:19 +01:00
|
|
|
<StatTile Label="@Text["Events24h"]"
|
2026-08-11 11:59:18 +02:00
|
|
|
Value="@(_eventCount24h.ToString())"
|
|
|
|
|
Icon="@Icons.Material.Filled.Notifications"
|
|
|
|
|
IconColor="Color.Warning"
|
|
|
|
|
Loading="@_loading">
|
|
|
|
|
<Footer>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudLink Href="/events" Typo="Typo.caption">@Text["ViewAll"] →</MudLink>
|
2026-08-11 11:59:18 +02:00
|
|
|
</Footer>
|
|
|
|
|
</StatTile>
|
2026-07-19 13:30:03 +00:00
|
|
|
</MudItem>
|
2026-08-11 11:59:18 +02:00
|
|
|
<MudItem xs="12" sm="6" lg="3" Class="d-flex">
|
2026-10-25 05:59:18 +01:00
|
|
|
<StatTile Label="@Text["Sites"]"
|
2026-08-11 11:59:18 +02:00
|
|
|
Value="@(_stats?.TotalSites.ToString() ?? "—")"
|
|
|
|
|
Icon="@Icons.Material.Filled.Assignment"
|
|
|
|
|
IconColor="Color.Info"
|
|
|
|
|
Loading="@_loading">
|
|
|
|
|
<Footer>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudLink Href="/sites" Typo="Typo.caption">@Text["Manage"] →</MudLink>
|
2026-08-11 11:59:18 +02:00
|
|
|
</Footer>
|
|
|
|
|
</StatTile>
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
2026-07-19 13:30:03 +00:00
|
|
|
@* Camera Status + Recent Events Row *@
|
|
|
|
|
<MudGrid Class="mt-4">
|
|
|
|
|
@* Camera Status Breakdown *@
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 04:19:19 +01:00
|
|
|
<SectionCard Title="@Text["CameraStatusSection"]" Icon="@Icons.Material.Filled.Videocam">
|
2026-07-19 13:30:03 +00:00
|
|
|
@if (_cameraStatusData is not null)
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_cameraStatusData" Hover="false" Elevation="0">
|
|
|
|
|
<HeaderContent>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudTh>@Text["Status"]</MudTh>
|
|
|
|
|
<MudTh>@Text["Count"]</MudTh>
|
2026-07-19 13:30:03 +00:00
|
|
|
<MudTh></MudTh>
|
|
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
|
|
|
|
<MudTd>
|
|
|
|
|
<MudText Color="@context.Color">@context.Label</MudText>
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd>
|
|
|
|
|
<MudText Typo="Typo.h6">@context.Count</MudText>
|
|
|
|
|
</MudTd>
|
|
|
|
|
<MudTd>
|
|
|
|
|
<MudProgressLinear Value="@context.Percent" Color="@context.Color" style="width:100px" />
|
|
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
else { <MudSkeleton Width="100%" Height="100px" /> }
|
2026-08-11 11:59:18 +02:00
|
|
|
</SectionCard>
|
2026-07-19 13:30:03 +00:00
|
|
|
</MudItem>
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-07-19 13:30:03 +00:00
|
|
|
@* Recent Events *@
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 04:19:19 +01:00
|
|
|
<SectionCard Title="@Text["RecentEvents"]" Icon="@Icons.Material.Filled.Notifications">
|
2026-08-11 11:59:18 +02:00
|
|
|
<ChildContent>
|
|
|
|
|
@if (_recentEventsLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudSkeleton Width="100%" Height="40px" />
|
|
|
|
|
<MudSkeleton Width="100%" Height="40px" Class="mt-1" />
|
|
|
|
|
}
|
|
|
|
|
else if (_recentEvents is { Count: > 0 })
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_recentEvents" Hover="true" Elevation="0">
|
|
|
|
|
<HeaderContent>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudTh>@Text["Time"]</MudTh>
|
|
|
|
|
<MudTh>@Text["Type"]</MudTh>
|
|
|
|
|
<MudTh>@Text["Confidence"]</MudTh>
|
2026-08-11 11:59:18 +02:00
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudTd><MudText Typo="Typo.body2">@context.OccurredAt.ToLocalTime().ToString("t", Language.Culture)</MudText></MudTd>
|
2026-08-11 11:59:18 +02:00
|
|
|
<MudTd><MudText Color="@GetEventColor(context.Type)">@FormatEventType(context.Type)</MudText></MudTd>
|
|
|
|
|
<MudTd><MudText>@($"{context.Confidence:P0}")</MudText></MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["NoRecentEvents"]</MudText>
|
2026-08-11 11:59:18 +02:00
|
|
|
}
|
|
|
|
|
</ChildContent>
|
|
|
|
|
<Actions>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudLink Href="/events" Typo="Typo.caption">@Text["ViewAll"] →</MudLink>
|
2026-08-11 11:59:18 +02:00
|
|
|
</Actions>
|
|
|
|
|
</SectionCard>
|
2026-07-19 13:30:03 +00:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
|
|
|
|
@* Agent Workload + Quick Actions *@
|
|
|
|
|
<MudGrid Class="mt-4">
|
|
|
|
|
@* Agent Workload *@
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 04:19:19 +01:00
|
|
|
<SectionCard Title="@Text["AgentLoad"]" Icon="@Icons.Material.Filled.Memory">
|
2026-07-19 13:30:03 +00:00
|
|
|
@if (_agentsLoading)
|
|
|
|
|
{
|
2026-08-10 23:26:32 +02:00
|
|
|
<MudGrid>
|
|
|
|
|
@for (var i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
<MudItem xs="12" sm="6">
|
|
|
|
|
<MudPaper Elevation="0" Style="border-radius: var(--hmd-radius-md);">
|
|
|
|
|
<MudSkeleton Variant="SkeletonVariant.Rectangular" Height="140px" />
|
|
|
|
|
</MudPaper>
|
|
|
|
|
</MudItem>
|
|
|
|
|
}
|
|
|
|
|
</MudGrid>
|
2026-07-19 13:30:03 +00:00
|
|
|
}
|
|
|
|
|
else if (_agents is { Count: > 0 })
|
|
|
|
|
{
|
2026-08-10 23:26:32 +02:00
|
|
|
<MudGrid>
|
|
|
|
|
@foreach (var agent in _agents)
|
|
|
|
|
{
|
|
|
|
|
<MudItem xs="12" sm="6" @key="agent.Id">
|
|
|
|
|
<AgentCard Agent="@agent" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
}
|
|
|
|
|
</MudGrid>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudLink Href="/admin/agents" Typo="Typo.caption" Class="mt-2 d-block">@Text["AllAgents"] →</MudLink>
|
2026-07-19 13:30:03 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@Text["NoAgentsRegistered"]</MudText>
|
2026-07-19 13:30:03 +00:00
|
|
|
}
|
2026-08-11 11:59:18 +02:00
|
|
|
</SectionCard>
|
2026-07-19 13:30:03 +00:00
|
|
|
</MudItem>
|
|
|
|
|
|
|
|
|
|
@* Quick Actions *@
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-10-25 04:19:19 +01:00
|
|
|
<SectionCard Title="@Text["QuickActions"]" Icon="@Icons.Material.Filled.FlashOn">
|
2026-07-19 13:30:03 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Primary" Href="/events" Class="mb-4" Style="height:80px;">
|
|
|
|
|
<div class="d-flex flex-column align-center">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Notifications" />
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.body2">@Text["Events"]</MudText>
|
2026-07-19 13:30:03 +00:00
|
|
|
</div>
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Secondary" Href="/sites" Class="mb-4" Style="height:80px;">
|
|
|
|
|
<div class="d-flex flex-column align-center">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" />
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.body2">@Text["NewSite"]</MudText>
|
2026-07-19 13:30:03 +00:00
|
|
|
</div>
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Warning" Href="/admin/agents" Class="mb-4" Style="height:80px;">
|
|
|
|
|
<div class="d-flex flex-column align-center">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Memory" />
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.body2">@Text["Agents"]</MudText>
|
2026-07-19 13:30:03 +00:00
|
|
|
</div>
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudButton FullWidth="true" Variant="Variant.Outlined" Color="Color.Info" Href="/audit-logs" Class="mb-4" Style="height:80px;">
|
|
|
|
|
<div class="d-flex flex-column align-center">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.History" />
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.body2">@Text["Audit"]</MudText>
|
2026-07-19 13:30:03 +00:00
|
|
|
</div>
|
|
|
|
|
</MudButton>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
2026-08-11 11:59:18 +02:00
|
|
|
</SectionCard>
|
2026-07-19 13:30:03 +00:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
|
|
|
|
@* Sites Table *@
|
|
|
|
|
<MudGrid Class="mt-4">
|
|
|
|
|
<MudItem xs="12">
|
2026-10-25 04:19:19 +01:00
|
|
|
<SectionCard Title="@Text["Sites"]" Icon="@Icons.Material.Filled.Business">
|
2026-08-11 11:59:18 +02:00
|
|
|
<ChildContent>
|
|
|
|
|
@if (_loading) { for (int i = 0; i < 3; i++) { <MudSkeleton Width="100%" Height="40px" Class="mt-1" /> } }
|
|
|
|
|
else if (_sites?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_sites" Hover="true" Striped="true" Elevation="0">
|
|
|
|
|
<HeaderContent>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudTh>@Text["Name"]</MudTh>
|
|
|
|
|
<MudTh>@Text["Address"]</MudTh>
|
|
|
|
|
<MudTh>@Text["Status"]</MudTh>
|
|
|
|
|
<MudTh>@Text["CreatedAt"]</MudTh>
|
2026-08-11 11:59:18 +02:00
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
|
|
|
|
<MudTd><MudLink Href="@($"/sites/{context.Id}")">@context.Name</MudLink></MudTd>
|
|
|
|
|
<MudTd>@(context.Address ?? "—")</MudTd>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudTd><MudText Color="@(context.Enabled ? Color.Success : Color.Default)">@(context.Enabled ? Text["Active"] : Text["Inactive"])</MudText></MudTd>
|
|
|
|
|
<MudTd>@context.CreatedAt.ToString("g", Language.Culture)</MudTd>
|
2026-08-11 11:59:18 +02:00
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<div class="pa-8 text-center">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Business" Size="Size.Large" Color="Color.Secondary" />
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudText Typo="Typo.h6" Color="Color.Secondary" Class="mt-4">@Text["NoSiteConfigured"]</MudText>
|
2026-08-11 11:59:18 +02:00
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-4">
|
2026-10-25 04:19:19 +01:00
|
|
|
@Text["CreateSitePrompt"]
|
2026-08-11 11:59:18 +02:00
|
|
|
</MudText>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Href="/sites">
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" /> @Text["CreateSite"]
|
2026-08-11 11:59:18 +02:00
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</ChildContent>
|
|
|
|
|
<Actions>
|
2026-10-25 04:19:19 +01:00
|
|
|
<MudTooltip Text="@Text["Refresh"]">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Size="Size.Small" OnClick="@(async () => await LoadData())" aria-label="@Text["RefreshDashboard"]" />
|
2026-07-19 13:30:03 +00:00
|
|
|
</MudTooltip>
|
2026-08-11 11:59:18 +02:00
|
|
|
</Actions>
|
|
|
|
|
</SectionCard>
|
2026-07-16 21:19:16 +00:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
|
|
|
|
@code {
|
2026-07-19 13:30:03 +00:00
|
|
|
private StatsResult? _stats;
|
2026-07-16 21:19:16 +00:00
|
|
|
private IReadOnlyList<SiteItem>? _sites;
|
|
|
|
|
private bool _loading = true;
|
2026-07-19 07:12:40 +00:00
|
|
|
private DateTime _lastRefresh;
|
2026-07-19 13:30:03 +00:00
|
|
|
private bool _recentEventsLoading;
|
|
|
|
|
private bool _agentsLoading;
|
|
|
|
|
private List<EventItem>? _recentEvents;
|
|
|
|
|
private int _eventCount24h;
|
|
|
|
|
private List<AgentItem>? _agents;
|
|
|
|
|
private List<CameraStatusEntry>? _cameraStatusData;
|
2026-07-16 21:19:16 +00:00
|
|
|
|
2026-08-10 23:26:32 +02:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2026-10-25 04:19:19 +01:00
|
|
|
Language.LanguageChanged += OnLanguageChanged;
|
2026-08-10 23:26:32 +02:00
|
|
|
await LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Auto-refresh 15s (métriques agents) ─────────────────────────
|
2026-08-11 11:59:18 +02:00
|
|
|
// Démarre APRÈS le premier rendu (OnAfterRenderAsync) : une boucle
|
|
|
|
|
// infinie awaitée dans OnInitializedAsync bloque le rendu initial
|
|
|
|
|
// (SSR/prerender attend la fin du cycle de vie) → page lente.
|
2026-08-10 23:26:32 +02:00
|
|
|
private CancellationTokenSource? _refreshCts;
|
|
|
|
|
private bool _disposed;
|
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 23:26:32 +02:00
|
|
|
|
|
|
|
|
private async Task StartAutoRefresh()
|
|
|
|
|
{
|
|
|
|
|
_refreshCts = new CancellationTokenSource();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
while (!_refreshCts.Token.IsCancellationRequested)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(15), _refreshCts.Token);
|
|
|
|
|
if (_disposed) return;
|
|
|
|
|
// Rafraîchit uniquement la section agents (léger) : les stats
|
|
|
|
|
// globales restent au refresh manuel pour éviter le flash.
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_agentsLoading = true;
|
|
|
|
|
var agentsPage = await Api.GetAllAgentsAsync(1, 5);
|
|
|
|
|
_agents = agentsPage?.Items?.ToList();
|
|
|
|
|
}
|
|
|
|
|
catch { /* keep last state */ }
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_agentsLoading = false;
|
|
|
|
|
if (!_disposed) await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (OperationCanceledException) { /* arrêt volontaire */ }
|
|
|
|
|
}
|
2026-07-19 07:12:40 +00:00
|
|
|
|
2026-07-19 13:30:03 +00:00
|
|
|
private async Task LoadData()
|
2026-07-19 07:12:40 +00:00
|
|
|
{
|
2026-07-19 13:30:03 +00:00
|
|
|
_loading = true;
|
2026-07-19 07:12:40 +00:00
|
|
|
try
|
|
|
|
|
{
|
2026-07-19 13:30:03 +00:00
|
|
|
// Stats
|
|
|
|
|
_stats = await Api.GetStatsAsync();
|
|
|
|
|
if (_stats is not null)
|
2026-10-25 04:19:19 +01:00
|
|
|
UpdateCameraStatusData();
|
2026-07-17 17:22:33 +00:00
|
|
|
|
2026-07-19 13:30:03 +00:00
|
|
|
// Sites
|
|
|
|
|
var sitesResult = await Api.GetSitesAsync(1, 5);
|
|
|
|
|
_sites = sitesResult?.Items;
|
|
|
|
|
|
|
|
|
|
// Agents
|
|
|
|
|
try { _agentsLoading = true; var agentsPage = await Api.GetAllAgentsAsync(1, 5); _agents = agentsPage?.Items?.ToList(); }
|
|
|
|
|
catch { }
|
|
|
|
|
finally { _agentsLoading = false; }
|
|
|
|
|
|
|
|
|
|
// Recent events
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_recentEventsLoading = true;
|
|
|
|
|
var eventsResult = await Api.GetEventsAsync(null, null, 1, 10);
|
|
|
|
|
_recentEvents = eventsResult?.Items ?? [];
|
|
|
|
|
_eventCount24h = eventsResult?.TotalCount ?? 0;
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
finally { _recentEventsLoading = false; }
|
|
|
|
|
|
2026-07-19 07:12:40 +00:00
|
|
|
_lastRefresh = DateTime.Now;
|
2026-07-16 21:19:16 +00:00
|
|
|
}
|
2026-08-10 23:33:06 +02:00
|
|
|
catch { Snackbar.Add(UiErrors.OperationFailed(), Severity.Error); }
|
2026-07-16 21:19:16 +00:00
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
2026-07-19 07:12:40 +00:00
|
|
|
|
2026-10-25 04:19:19 +01:00
|
|
|
private string FormatEventType(string type) => type switch
|
2026-07-19 07:12:40 +00:00
|
|
|
{
|
2026-10-25 04:19:19 +01:00
|
|
|
"MotionDetected" => Text["MotionDetected"],
|
|
|
|
|
"PersonDetected" => Text["PersonDetected"],
|
|
|
|
|
"VehicleDetected" => Text["VehicleDetected"],
|
|
|
|
|
"FaceRecognized" => Text["FaceRecognized"],
|
|
|
|
|
"CameraOffline" => Text["CameraOffline"],
|
2026-07-19 13:30:03 +00:00
|
|
|
_ => type
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static Color GetEventColor(string type) => type switch
|
|
|
|
|
{
|
|
|
|
|
"MotionDetected" => Color.Warning,
|
|
|
|
|
"PersonDetected" => Color.Error,
|
|
|
|
|
"VehicleDetected" => Color.Info,
|
|
|
|
|
"FaceRecognized" => Color.Success,
|
|
|
|
|
_ => Color.Default
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private record CameraStatusEntry(string Label, int Count, Color Color, int Percent);
|
2026-08-10 23:26:32 +02:00
|
|
|
|
2026-10-25 04:19:19 +01:00
|
|
|
private void UpdateCameraStatusData()
|
|
|
|
|
{
|
|
|
|
|
if (_stats is null) return;
|
|
|
|
|
|
|
|
|
|
var other = _stats.TotalCameras - _stats.CamerasOnline - _stats.CamerasOffline;
|
|
|
|
|
var total = Math.Max(_stats.TotalCameras, 1);
|
|
|
|
|
_cameraStatusData =
|
|
|
|
|
[
|
|
|
|
|
new(Text["Online"], _stats.CamerasOnline, Color.Success, (int)(_stats.CamerasOnline * 100.0 / total)),
|
|
|
|
|
new(Text["Offline"], _stats.CamerasOffline, Color.Error, (int)(_stats.CamerasOffline * 100.0 / total)),
|
|
|
|
|
new(Text["Other"], other, Color.Default, (int)(other * 100.0 / total)),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLanguageChanged()
|
|
|
|
|
{
|
|
|
|
|
UpdateCameraStatusData();
|
|
|
|
|
_ = InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 23:26:32 +02:00
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_disposed = true;
|
2026-10-25 04:19:19 +01:00
|
|
|
Language.LanguageChanged -= OnLanguageChanged;
|
2026-08-10 23:26:32 +02:00
|
|
|
_refreshCts?.Cancel();
|
|
|
|
|
_refreshCts?.Dispose();
|
|
|
|
|
}
|
2026-07-16 21:19:16 +00:00
|
|
|
}
|