feat(client-ui): ConfirmAlarmWindow dialog (comment)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="ZB.MOM.WW.OtOpcUa.Client.UI.Views.ConfirmAlarmWindow"
|
||||
Title="Confirm Alarm"
|
||||
Width="420"
|
||||
SizeToContent="Height"
|
||||
MinHeight="240"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
CanResize="False">
|
||||
<StackPanel Margin="16" Spacing="12">
|
||||
<TextBlock Text="Confirm Alarm" FontWeight="Bold" FontSize="16" />
|
||||
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="Source:" FontSize="12" Foreground="Gray" />
|
||||
<TextBlock Name="SourceText" FontWeight="SemiBold" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="Condition:" FontSize="12" Foreground="Gray" />
|
||||
<TextBlock Name="ConditionText" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="Comment:" FontSize="12" Foreground="Gray" />
|
||||
<TextBox Name="CommentInput"
|
||||
Watermark="Enter confirmation comment"
|
||||
AcceptsReturn="True"
|
||||
Height="60"
|
||||
TextWrapping="Wrap" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Name="ResultText" Foreground="Gray" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right">
|
||||
<Button Name="ConfirmButton" Content="Confirm" />
|
||||
<Button Name="CancelButton" Content="Cancel" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
@@ -0,0 +1,71 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using ZB.MOM.WW.OtOpcUa.Client.UI.ViewModels;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Client.UI.Views;
|
||||
|
||||
public partial class ConfirmAlarmWindow : Window
|
||||
{
|
||||
private readonly AlarmsViewModel _alarmsVm;
|
||||
private readonly AlarmEventViewModel _alarm;
|
||||
|
||||
/// <summary>Initializes a new instance of the ConfirmAlarmWindow class for XAML designer support.</summary>
|
||||
public ConfirmAlarmWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
_alarmsVm = null!;
|
||||
_alarm = null!;
|
||||
}
|
||||
|
||||
/// <summary>Initializes a new instance of the ConfirmAlarmWindow class with alarm context.</summary>
|
||||
/// <param name="alarmsVm">The alarms view model.</param>
|
||||
/// <param name="alarm">The alarm event to confirm.</param>
|
||||
public ConfirmAlarmWindow(AlarmsViewModel alarmsVm, AlarmEventViewModel alarm)
|
||||
{
|
||||
InitializeComponent();
|
||||
_alarmsVm = alarmsVm;
|
||||
_alarm = alarm;
|
||||
|
||||
var sourceText = this.FindControl<TextBlock>("SourceText");
|
||||
if (sourceText != null) sourceText.Text = alarm.SourceName;
|
||||
|
||||
var conditionText = this.FindControl<TextBlock>("ConditionText");
|
||||
if (conditionText != null) conditionText.Text = $"{alarm.ConditionName} (Severity: {alarm.Severity})";
|
||||
|
||||
var confirmButton = this.FindControl<Button>("ConfirmButton");
|
||||
if (confirmButton != null) confirmButton.Click += OnConfirmClicked;
|
||||
|
||||
var cancelButton = this.FindControl<Button>("CancelButton");
|
||||
if (cancelButton != null) cancelButton.Click += OnCancelClicked;
|
||||
}
|
||||
|
||||
private async void OnConfirmClicked(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var commentInput = this.FindControl<TextBox>("CommentInput");
|
||||
var resultText = this.FindControl<TextBlock>("ResultText");
|
||||
if (commentInput == null || resultText == null) return;
|
||||
|
||||
var comment = commentInput.Text ?? string.Empty;
|
||||
|
||||
resultText.Foreground = Brushes.Gray;
|
||||
resultText.Text = "Confirming...";
|
||||
|
||||
var (success, message) = await _alarmsVm.ConfirmAlarmAsync(_alarm, comment);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
resultText.Foreground = Brushes.Red;
|
||||
resultText.Text = message;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCancelClicked(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user