fix(adminui): converter UI — try/catch + confirm + FleetAdmin gate on per-equipment convert (review)
This commit is contained in:
@@ -145,7 +145,11 @@ else
|
||||
}
|
||||
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="OpenAddAlias" disabled="@(_gateways.Count == 0)">Add alias (browse Galaxy)</button>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="OpenAddTag">Add tag</button>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="PreviewConvertRelaysAsync" disabled="@(_gateways.Count == 0 || _convertBusy)">Convert relay virtual-tags…</button>
|
||||
<AuthorizeView Policy="FleetAdmin">
|
||||
<Authorized>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="PreviewConvertRelaysAsync" disabled="@(_gateways.Count == 0 || _convertBusy)">Convert relay virtual-tags…</button>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
@if (!string.IsNullOrWhiteSpace(_tagError))
|
||||
{
|
||||
@@ -202,70 +206,93 @@ else
|
||||
<div class="text-success small mb-2">@_convertMessage</div>
|
||||
}
|
||||
|
||||
@if (_convertPreview is not null)
|
||||
{
|
||||
<section class="panel rise mt-2">
|
||||
<div class="panel-head d-flex justify-content-between align-items-center">
|
||||
<span>Convert relay virtual-tags to aliases</span>
|
||||
<button type="button" class="btn btn-sm btn-link" @onclick="@(() => { _convertPreview = null; })">Close</button>
|
||||
</div>
|
||||
<div style="padding:1rem">
|
||||
<h6 class="text-muted">Will convert (@_convertPreview.Converted.Count)</h6>
|
||||
@if (_convertPreview.Converted.Count == 0)
|
||||
{
|
||||
<p class="text-muted small mb-3">No relay virtual-tags to convert.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-sm mb-3">
|
||||
<thead><tr><th>Virtual tag</th><th>Full name</th><th>Data type</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var c in _convertPreview.Converted)
|
||||
{
|
||||
<tr>
|
||||
<td>@c.VirtualTagName</td>
|
||||
<td class="mono">@c.FullName</td>
|
||||
<td>@c.DataType</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
<AuthorizeView Policy="FleetAdmin">
|
||||
<Authorized>
|
||||
@if (!string.IsNullOrWhiteSpace(_convertError))
|
||||
{
|
||||
<div class="text-danger small mb-2">@_convertError</div>
|
||||
}
|
||||
|
||||
<h6 class="text-muted">Skipped (@_convertPreview.Skipped.Count)</h6>
|
||||
@if (_convertPreview.Skipped.Count == 0)
|
||||
{
|
||||
<p class="text-muted small mb-0">Nothing skipped.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-sm mb-0">
|
||||
<thead><tr><th>Virtual tag</th><th>Reason</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var s in _convertPreview.Skipped)
|
||||
{
|
||||
<tr>
|
||||
<td>@s.VirtualTagName</td>
|
||||
<td>@s.Reason</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
@if (_convertPreview is not null)
|
||||
{
|
||||
<section class="panel rise mt-2">
|
||||
<div class="panel-head d-flex justify-content-between align-items-center">
|
||||
<span>Convert relay virtual-tags to aliases</span>
|
||||
<button type="button" class="btn btn-sm btn-link" @onclick="@(() => { _convertPreview = null; _convertConfirming = false; })">Close</button>
|
||||
</div>
|
||||
<div style="padding:1rem">
|
||||
<h6 class="text-muted">Will convert (@_convertPreview.Converted.Count)</h6>
|
||||
@if (_convertPreview.Converted.Count == 0)
|
||||
{
|
||||
<p class="text-muted small mb-3">No relay virtual-tags to convert.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-sm mb-3">
|
||||
<thead><tr><th>Virtual tag</th><th>Full name</th><th>Data type</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var c in _convertPreview.Converted)
|
||||
{
|
||||
<tr @key="c.FullName">
|
||||
<td>@c.VirtualTagName</td>
|
||||
<td class="mono">@c.FullName</td>
|
||||
<td>@c.DataType</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
@if (_convertPreview.Converted.Count > 0)
|
||||
{
|
||||
<button type="button" class="btn btn-primary btn-sm" @onclick="ApplyConvertRelaysAsync" disabled="@_convertBusy">
|
||||
@if (_convertBusy) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||
Apply
|
||||
</button>
|
||||
}
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="@(() => { _convertPreview = null; })" disabled="@_convertBusy">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
<h6 class="text-muted">Skipped (@_convertPreview.Skipped.Count)</h6>
|
||||
@if (_convertPreview.Skipped.Count == 0)
|
||||
{
|
||||
<p class="text-muted small mb-0">Nothing skipped.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-sm mb-0">
|
||||
<thead><tr><th>Virtual tag</th><th>Reason</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var s in _convertPreview.Skipped)
|
||||
{
|
||||
<tr @key="s.VirtualTagName">
|
||||
<td>@s.VirtualTagName</td>
|
||||
<td>@s.Reason</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
<div class="mt-3 d-flex gap-2 align-items-center">
|
||||
@if (_convertPreview.Converted.Count > 0)
|
||||
{
|
||||
@if (!_convertConfirming)
|
||||
{
|
||||
<button type="button" class="btn btn-primary btn-sm" @onclick="() => _convertConfirming = true" disabled="@_convertBusy">
|
||||
Apply…
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="small">Convert @_convertPreview.Converted.Count relay virtual-tag(s)?</span>
|
||||
<button type="button" class="btn btn-danger btn-sm" @onclick="ApplyConvertRelaysAsync" disabled="@_convertBusy">
|
||||
@if (_convertBusy) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||
Yes, apply
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="() => _convertConfirming = false" disabled="@_convertBusy">Cancel</button>
|
||||
}
|
||||
}
|
||||
@if (!_convertConfirming)
|
||||
{
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="@(() => { _convertPreview = null; _convertConfirming = false; })" disabled="@_convertBusy">Close</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
|
||||
<TagModal Visible="_tagModalVisible" IsNew="_tagModalIsNew" EquipmentId="@EquipmentId"
|
||||
Existing="_tagModalExisting" Drivers="_tagDriverOptions"
|
||||
@@ -403,10 +430,14 @@ else
|
||||
private AliasTagEditDto? _aliasModalExisting;
|
||||
|
||||
// --- Relay→alias converter (per-equipment). _convertPreview holds the dry-run result while the
|
||||
// inline preview panel is open; null = panel closed. _convertMessage is a brief post-apply summary. ---
|
||||
// inline preview panel is open; null = panel closed. _convertMessage is a brief post-apply summary.
|
||||
// _convertError surfaces exceptions so a service failure doesn't crash the circuit. _convertConfirming
|
||||
// guards the Apply button (two-step confirm, mirrors the fleet page). ---
|
||||
private RelayConversionResult? _convertPreview;
|
||||
private bool _convertBusy;
|
||||
private bool _convertConfirming;
|
||||
private string? _convertMessage;
|
||||
private string? _convertError;
|
||||
|
||||
// --- Virtual Tags tab state. _vtags is null until the tab is first activated. ---
|
||||
private IReadOnlyList<EquipmentVirtualTagRow>? _vtags;
|
||||
@@ -524,26 +555,32 @@ else
|
||||
private async Task PreviewConvertRelaysAsync()
|
||||
{
|
||||
_convertMessage = null;
|
||||
_convertError = null;
|
||||
_convertConfirming = false;
|
||||
_convertBusy = true;
|
||||
try
|
||||
{
|
||||
_convertPreview = await Svc.ConvertRelayVirtualTagsToAliasesAsync(EquipmentId!, dryRun: true);
|
||||
}
|
||||
catch (Exception ex) { _convertPreview = null; _convertError = ex.Message; }
|
||||
finally { _convertBusy = false; }
|
||||
}
|
||||
|
||||
private async Task ApplyConvertRelaysAsync()
|
||||
{
|
||||
_convertBusy = true;
|
||||
_convertError = null;
|
||||
try
|
||||
{
|
||||
var r = await Svc.ConvertRelayVirtualTagsToAliasesAsync(EquipmentId!, dryRun: false);
|
||||
_convertPreview = null;
|
||||
_convertConfirming = false;
|
||||
_convertMessage = $"Converted {r.Converted.Count}, skipped {r.Skipped.Count}.";
|
||||
// The converted virtual tags become aliases, so both lists change.
|
||||
await ReloadTagsAsync();
|
||||
await ReloadVirtualTagsAsync();
|
||||
}
|
||||
catch (Exception ex) { _convertError = ex.Message; _convertConfirming = false; }
|
||||
finally { _convertBusy = false; }
|
||||
}
|
||||
|
||||
@@ -649,9 +686,11 @@ else
|
||||
_tags = null;
|
||||
_vtags = null;
|
||||
_alarms = null;
|
||||
// Drop any open relay-conversion preview/summary so it can't leak across equipment changes.
|
||||
// Drop any open relay-conversion preview/summary/confirm so it can't leak across equipment changes.
|
||||
_convertPreview = null;
|
||||
_convertMessage = null;
|
||||
_convertError = null;
|
||||
_convertConfirming = false;
|
||||
if (!IsNew)
|
||||
{
|
||||
_equipment = await Svc.LoadEquipmentAsync(EquipmentId!);
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
<tbody>
|
||||
@foreach (var c in _preview.Converted)
|
||||
{
|
||||
<tr>
|
||||
<tr @key="(c.EquipmentId, c.FullName)">
|
||||
<td class="mono">@c.EquipmentId</td>
|
||||
<td>@c.VirtualTagName</td>
|
||||
<td class="mono">@c.FullName</td>
|
||||
@@ -79,7 +79,7 @@
|
||||
<tbody>
|
||||
@foreach (var s in _preview.Skipped)
|
||||
{
|
||||
<tr>
|
||||
<tr @key="(s.EquipmentId, s.VirtualTagName)">
|
||||
<td class="mono">@s.EquipmentId</td>
|
||||
<td>@s.VirtualTagName</td>
|
||||
<td>@s.Reason</td>
|
||||
|
||||
Reference in New Issue
Block a user