Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Uns/RelayAliasConvert.razor
T

155 lines
5.6 KiB
Plaintext

@page "/uns/convert-relays"
@* Fleet-wide relay→alias converter. Previews (dry-run) and applies the conversion of pure-relay
virtual tags into Galaxy alias tags across every equipment. Edits the draft config only; the
operator publishes normally afterward. FleetAdmin-gated (mirrors RoleGrants.razor). *@
@attribute [Microsoft.AspNetCore.Authorization.Authorize(Policy = "FleetAdmin")]
@rendermode RenderMode.InteractiveServer
@using ZB.MOM.WW.OtOpcUa.AdminUI.Uns
@inject IUnsTreeService Svc
<PageTitle>Convert relays</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-3">
<h4 class="mb-0">Convert relay virtual-tags to aliases</h4>
<a href="/uns" class="btn btn-outline-secondary btn-sm">Back to UNS</a>
</div>
<p class="text-muted">
Sweeps every equipment for pure-relay virtual tags (a script body that simply returns another
tag's value) and rewrites each one as a Galaxy alias tag. This edits the draft configuration
only — publish afterward to take effect. Run a preview first to review what will change.
</p>
<div class="d-flex gap-2 align-items-center mb-3">
<button type="button" class="btn btn-primary" @onclick="PreviewAsync" disabled="@_busy">
@if (_busy) { <span class="spinner-border spinner-border-sm me-1"></span> }
Preview
</button>
@if (_applied)
{
<span class="text-success small">Conversion applied. Publish to take effect.</span>
}
</div>
@if (!string.IsNullOrWhiteSpace(_error))
{
<div class="text-danger small mb-3">@_error</div>
}
@if (_preview is not null)
{
<section class="panel rise mt-2">
<div class="panel-head">Will convert (@_preview.Converted.Count)</div>
@if (_preview.Converted.Count == 0)
{
<div style="padding:1rem" class="text-muted">No relay virtual-tags to convert.</div>
}
else
{
<div class="table-wrap">
<table class="data-table">
<thead><tr><th>Equipment</th><th>Virtual tag</th><th>Full name</th><th>Data type</th></tr></thead>
<tbody>
@foreach (var c in _preview.Converted)
{
<tr @key="(c.EquipmentId, c.FullName)">
<td class="mono">@c.EquipmentId</td>
<td>@c.VirtualTagName</td>
<td class="mono">@c.FullName</td>
<td>@c.DataType</td>
</tr>
}
</tbody>
</table>
</div>
}
</section>
<section class="panel rise mt-3">
<div class="panel-head">Skipped (@_preview.Skipped.Count)</div>
@if (_preview.Skipped.Count == 0)
{
<div style="padding:1rem" class="text-muted">Nothing skipped.</div>
}
else
{
<div class="table-wrap">
<table class="data-table">
<thead><tr><th>Equipment</th><th>Virtual tag</th><th>Reason</th></tr></thead>
<tbody>
@foreach (var s in _preview.Skipped)
{
<tr @key="(s.EquipmentId, s.VirtualTagName)">
<td class="mono">@s.EquipmentId</td>
<td>@s.VirtualTagName</td>
<td>@s.Reason</td>
</tr>
}
</tbody>
</table>
</div>
}
</section>
@if (!_preview.Applied && _preview.Converted.Count > 0)
{
<div class="d-flex gap-2 align-items-center mt-3">
@if (!_confirming)
{
<button type="button" class="btn btn-warning" @onclick="() => _confirming = true" disabled="@_busy">
Apply conversion…
</button>
}
else
{
<span class="small">Convert @_preview.Converted.Count relay virtual-tag(s) to aliases in the draft?</span>
<button type="button" class="btn btn-danger btn-sm" @onclick="ApplyAsync" disabled="@_busy">
@if (_busy) { <span class="spinner-border spinner-border-sm me-1"></span> }
Yes, apply
</button>
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="() => _confirming = false" disabled="@_busy">
Cancel
</button>
}
</div>
}
}
@code {
private RelayConversionResult? _preview;
private bool _busy;
private bool _confirming;
private bool _applied;
private string? _error;
private async Task PreviewAsync()
{
_error = null;
_confirming = false;
_applied = false;
_busy = true;
try
{
_preview = await Svc.ConvertRelayVirtualTagsToAliasesAsync(null, dryRun: true);
}
catch (Exception ex) { _error = ex.Message; }
finally { _busy = false; }
}
private async Task ApplyAsync()
{
_error = null;
_busy = true;
try
{
await Svc.ConvertRelayVirtualTagsToAliasesAsync(null, dryRun: false);
_applied = true;
_confirming = false;
// Re-run the preview so the Converted set is now empty and only remaining skips show.
_preview = await Svc.ConvertRelayVirtualTagsToAliasesAsync(null, dryRun: true);
}
catch (Exception ex) { _error = ex.Message; }
finally { _busy = false; }
}
}