feat(uns): GlobalUns page with browsable tree
This commit is contained in:
@@ -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
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h4 class="mb-0">UNS</h4>
|
||||
<span class="text-muted small">Changes apply on the next deployment.</span>
|
||||
</div>
|
||||
|
||||
<section class="panel rise" style="animation-delay:.02s">
|
||||
<div class="panel-head d-flex justify-content-between align-items-center flex-wrap gap-2">
|
||||
<span>Unified namespace</span>
|
||||
<div class="d-flex align-items-center gap-2 flex-wrap">
|
||||
<input type="text" class="form-control form-control-sm" style="max-width:240px"
|
||||
placeholder="Filter by name (substring)…"
|
||||
@bind="_filter" @bind:event="oninput" />
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="ExpandAll">Expand all</button>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="CollapseAll">Collapse all</button>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm" disabled>Import equipment CSV</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (_loading)
|
||||
{
|
||||
<div style="padding:1rem" class="text-muted">
|
||||
<span class="spinner-border spinner-border-sm me-1"></span>Loading…
|
||||
</div>
|
||||
}
|
||||
else if (_roots.Count == 0)
|
||||
{
|
||||
<div style="padding:1rem" class="text-muted">No clusters yet.</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div style="padding:.5rem 1rem">
|
||||
<UnsTree Roots="_roots" Filter="_filter" OnToggleExpand="ToggleAsync" />
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private IReadOnlyList<UnsNode> _roots = Array.Empty<UnsNode>();
|
||||
private string? _filter;
|
||||
private bool _loading = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_roots = await Svc.LoadStructureAsync();
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Expands every structural node (Enterprise/Cluster/Area/Line). Equipment nodes
|
||||
/// are intentionally left collapsed because expanding them would trigger lazy loads.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Collapses every node in the tree.</summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user