diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Uns/GlobalUns.razor b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Uns/GlobalUns.razor new file mode 100644 index 00000000..3410789a --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Uns/GlobalUns.razor @@ -0,0 +1,129 @@ +@page "/uns" +@attribute [Microsoft.AspNetCore.Authorization.Authorize] +@rendermode RenderMode.InteractiveServer +@using ZB.MOM.WW.OtOpcUa.AdminUI.Uns +@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Uns +@inject IUnsTreeService Svc + +
+

UNS

+ Changes apply on the next deployment. +
+ +
+
+ Unified namespace +
+ + + + +
+
+ + @if (_loading) + { +
+ Loading… +
+ } + else if (_roots.Count == 0) + { +
No clusters yet.
+ } + else + { +
+ +
+ } +
+ +@code { + private IReadOnlyList _roots = Array.Empty(); + private string? _filter; + private bool _loading = true; + + protected override async Task OnInitializedAsync() + { + _roots = await Svc.LoadStructureAsync(); + _loading = false; + } + + /// + /// Toggles a node's expansion. For equipment nodes whose children have not yet + /// been loaded, lazily fetches the tag/virtual-tag leaves on first expand. + /// + private async Task ToggleAsync(UnsNode node) + { + node.Expanded = !node.Expanded; + + if (node.Kind == UnsNodeKind.Equipment && node.Expanded && !node.Loaded) + { + node.Loading = true; + StateHasChanged(); + try + { + var kids = await Svc.LoadEquipmentChildrenAsync(node.EntityId!); + node.Children.Clear(); + node.Children.AddRange(kids); + node.Loaded = true; + } + catch (Exception ex) + { + node.Error = ex.Message; + } + finally + { + node.Loading = false; + StateHasChanged(); + } + } + } + + /// + /// Expands every structural node (Enterprise/Cluster/Area/Line). Equipment nodes + /// are intentionally left collapsed because expanding them would trigger lazy loads. + /// + private void ExpandAll() + { + foreach (var root in _roots) + { + ExpandStructural(root); + } + } + + private static void ExpandStructural(UnsNode node) + { + if (node.Kind is UnsNodeKind.Enterprise or UnsNodeKind.Cluster + or UnsNodeKind.Area or UnsNodeKind.Line) + { + node.Expanded = true; + } + + foreach (var child in node.Children) + { + ExpandStructural(child); + } + } + + /// Collapses every node in the tree. + private void CollapseAll() + { + foreach (var root in _roots) + { + CollapseNode(root); + } + } + + private static void CollapseNode(UnsNode node) + { + node.Expanded = false; + foreach (var child in node.Children) + { + CollapseNode(child); + } + } +}