@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites
@*
M10 residual: body component for the template "Add / Edit Native Alarm Source"
dialog hosted by IDialogService.ShowAsync. Renders ONLY the form fields +
action buttons inside the host's .modal-body; the host owns the backdrop,
header, focus trap, Escape, and focus restoration.
Native alarm sources are a READ-ONLY mirror of OPC UA A&C / MxAccess Gateway
alarms, so the connection picker is restricted to alarm-capable protocols —
the page filters that list via AlarmCapableProtocols.IsAlarmCapable and hands
it in. OnSaveAsync returns null on success (dialog closes with true) or the
error to render inline (dialog stays open).
*@
@code {
/// Host-supplied context: Close(true) on a successful save, Cancel on dismiss.
[Parameter, EditorRequired] public DialogContext Context { get; set; } = default!;
/// True when editing an existing source (the name becomes read-only).
[Parameter] public bool Editing { get; set; }
[Parameter] public string InitialName { get; set; } = string.Empty;
[Parameter] public string InitialConnection { get; set; } = string.Empty;
[Parameter] public string InitialSourceRef { get; set; } = string.Empty;
[Parameter] public string? InitialFilter { get; set; }
[Parameter] public string? InitialDescription { get; set; }
[Parameter] public bool InitialIsLocked { get; set; }
/// Connections whose protocol can surface native alarms (OPC UA / MxGateway).
[Parameter] public IReadOnlyList AlarmCapableConnections { get; set; }
= Array.Empty();
///
/// Persists the draft. Returns null on success (the dialog closes with
/// true) or the message to render inline, leaving the dialog open.
///
[Parameter, EditorRequired] public Func> OnSaveAsync { get; set; } = default!;
private string _nasName = string.Empty;
private string _nasConnection = string.Empty;
private string _nasSourceRef = string.Empty;
private string? _nasFilter;
private string? _nasDescription;
private bool _nasIsLocked;
private string? _error;
private bool _busy;
protected override void OnInitialized()
{
_nasName = InitialName;
_nasConnection = InitialConnection;
_nasSourceRef = InitialSourceRef;
_nasFilter = InitialFilter;
_nasDescription = InitialDescription;
_nasIsLocked = InitialIsLocked;
}
private async Task Submit()
{
if (_busy) return;
_error = null;
_busy = true;
try
{
var draft = new NativeSourceDraft(
_nasName,
_nasConnection,
_nasSourceRef,
_nasFilter,
_nasDescription,
_nasIsLocked);
var error = await OnSaveAsync(draft);
if (error == null)
{
Context.Close(true);
}
else
{
_error = error;
}
}
finally
{
_busy = false;
}
}
/// The authored native alarm source as submitted; the page performs the add/update.
/// Source name (ignored on edit — the stored name is fixed).
/// Alarm-capable data connection to mirror from.
/// OPC UA SourceNode nodeId, or MxAccess object/area.
/// Optional condition filter; blank mirrors every condition.
/// Optional free-text description.
/// Whether instances may override the binding.
public sealed record NativeSourceDraft(
string Name,
string ConnectionName,
string SourceReference,
string? ConditionFilter,
string? Description,
bool IsLocked);
}