dashboard(alarms): provider-status badge (alarmmgr vs degraded subtag)
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
@page "/alarms"
|
||||
@implements IAsyncDisposable
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@using ZB.MOM.WW.MxGateway.Server.Dashboard.Hubs
|
||||
@inject IDashboardLiveDataService LiveData
|
||||
@inject IOptions<GatewayOptions> GatewayOptions
|
||||
@inject DashboardHubConnectionFactory HubFactory
|
||||
|
||||
<PageTitle>Dashboard Alarms</PageTitle>
|
||||
|
||||
@@ -10,6 +13,12 @@
|
||||
<h1>Alarms</h1>
|
||||
<div class="text-secondary">@HeaderLine()</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge @_providerStatus.BadgeCssClass"
|
||||
title="@ProviderStatusTitle()">
|
||||
@_providerStatus.Label
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!GatewayOptions.Value.Alarms.Enabled)
|
||||
@@ -163,10 +172,44 @@
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
private Task? _pollTask;
|
||||
|
||||
private DashboardAlarmProviderStatus _providerStatus = DashboardAlarmProviderStatus.Healthy;
|
||||
private HubConnection? _alarmsHub;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_pollTask = PollLoopAsync();
|
||||
_ = AttachAlarmsHubAsync();
|
||||
}
|
||||
|
||||
private string? ProviderStatusTitle()
|
||||
{
|
||||
return _providerStatus.IsDegraded && !string.IsNullOrWhiteSpace(_providerStatus.Reason)
|
||||
? _providerStatus.Reason
|
||||
: null;
|
||||
}
|
||||
|
||||
private async Task AttachAlarmsHubAsync()
|
||||
{
|
||||
_alarmsHub = HubFactory.Create("/hubs/alarms");
|
||||
_alarmsHub.On<AlarmFeedMessage>(AlarmsHub.AlarmMessage, async message =>
|
||||
{
|
||||
if (message.PayloadCase == AlarmFeedMessage.PayloadOneofCase.ProviderStatus)
|
||||
{
|
||||
_providerStatus = DashboardAlarmProviderStatus.FromFeed(message);
|
||||
await InvokeAsync(StateHasChanged).ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
await _alarmsHub.StartAsync(_cts.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The badge is best-effort; it stays at the healthy default until
|
||||
// the hub reconnects and delivers a fresh provider-status message.
|
||||
}
|
||||
}
|
||||
|
||||
private string HeaderLine()
|
||||
@@ -268,6 +311,19 @@
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await _cts.CancelAsync();
|
||||
|
||||
if (_alarmsHub is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _alarmsHub.DisposeAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Disposal-time errors are best-effort.
|
||||
}
|
||||
}
|
||||
|
||||
if (_pollTask is not null)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user