Files
lmxopcua/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/Views/AlarmsView.axaml.cs
T
Joseph Doherty 64e3fbe035
v2-ci / build (push) Failing after 1m43s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
docs: backfill XML documentation across 756 files
Adds <summary>, <param>, <typeparam>, and <inheritdoc/> tags to public
members surfaced by commentchecker — resolves 5,847 of 5,869 issues
(99.6%) across three /fixdocs passes.
2026-05-28 08:10:17 -04:00

82 lines
2.9 KiB
C#

using System.ComponentModel;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.VisualTree;
using ZB.MOM.WW.OtOpcUa.Client.UI.ViewModels;
namespace ZB.MOM.WW.OtOpcUa.Client.UI.Views;
public partial class AlarmsView : UserControl
{
// Severity color bands (OPC UA severity 0-1000)
private static readonly IBrush InactiveBrush = new SolidColorBrush(Color.Parse("#F0F0F0")); // light grey
private static readonly IBrush LowBrush = new SolidColorBrush(Color.Parse("#DBEAFE")); // light blue (1-332)
private static readonly IBrush MediumBrush = new SolidColorBrush(Color.Parse("#FEF3C7")); // light yellow (333-665)
private static readonly IBrush HighBrush = new SolidColorBrush(Color.Parse("#FEE2E2")); // light red (666-899)
private static readonly IBrush CriticalBrush = new SolidColorBrush(Color.Parse("#FECACA")); // red (900-1000)
/// <summary>Initializes a new instance of the <see cref="AlarmsView"/> class.</summary>
public AlarmsView()
{
InitializeComponent();
}
/// <inheritdoc />
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
var grid = this.FindControl<DataGrid>("AlarmsGrid");
if (grid == null) return;
var contextMenu = new ContextMenu();
var ackItem = new MenuItem { Header = "Acknowledge..." };
ackItem.Click += OnAcknowledgeClicked;
contextMenu.Items.Add(ackItem);
contextMenu.Opening += OnContextMenuOpening;
grid.ContextMenu = contextMenu;
}
private void OnDataGridLoadingRow(object? sender, DataGridRowEventArgs e)
{
if (e.Row.DataContext is AlarmEventViewModel alarm)
e.Row.Background = GetSeverityBrush(alarm);
}
private static IBrush GetSeverityBrush(AlarmEventViewModel alarm)
{
if (!alarm.ActiveState)
return InactiveBrush;
return alarm.Severity switch
{
>= 900 => CriticalBrush,
>= 666 => HighBrush,
>= 333 => MediumBrush,
_ => LowBrush
};
}
private void OnContextMenuOpening(object? sender, CancelEventArgs e)
{
var grid = this.FindControl<DataGrid>("AlarmsGrid");
if (grid?.SelectedItem is not AlarmEventViewModel alarm || !alarm.CanAcknowledge)
e.Cancel = true;
}
private void OnAcknowledgeClicked(object? sender, RoutedEventArgs e)
{
if (DataContext is not AlarmsViewModel vm) return;
var grid = this.FindControl<DataGrid>("AlarmsGrid");
if (grid?.SelectedItem is not AlarmEventViewModel alarm || !alarm.CanAcknowledge) return;
var parentWindow = this.FindAncestorOfType<Window>();
if (parentWindow == null) return;
var ackWindow = new AckAlarmWindow(vm, alarm);
ackWindow.ShowDialog(parentWindow);
}
}