refactor(adminui): strip alias/relay machinery from UnsTreeService + EquipmentPage; Galaxy tags use standard TagModal
This commit is contained in:
@@ -139,17 +139,7 @@ else
|
||||
else if (_activeTab == "tags")
|
||||
{
|
||||
<div class="d-flex justify-content-end align-items-center gap-2 mb-2">
|
||||
@if (_gateways.Count == 0)
|
||||
{
|
||||
<span class="text-muted small">No Galaxy gateway in this cluster</span>
|
||||
}
|
||||
<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>
|
||||
<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))
|
||||
{
|
||||
@@ -167,7 +157,7 @@ else
|
||||
{
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr><th>Name</th><th>Driver</th><th>Data type</th><th>Access</th><th>Source</th><th class="text-end">Actions</th></tr>
|
||||
<tr><th>Name</th><th>Driver</th><th>Data type</th><th>Access</th><th class="text-end">Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var t in _tags)
|
||||
@@ -177,22 +167,8 @@ else
|
||||
<td class="mono">@t.DriverInstanceId</td>
|
||||
<td>@t.DataType</td>
|
||||
<td>@t.AccessLevel</td>
|
||||
<td>
|
||||
@if (t.IsAlias)
|
||||
{
|
||||
<span class="badge bg-info me-1">alias</span>
|
||||
<span class="mono small">@t.Source</span>
|
||||
}
|
||||
</td>
|
||||
<td class="text-end">
|
||||
@if (t.IsAlias)
|
||||
{
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm me-1" @onclick="() => OpenEditAlias(t.TagId)">Edit</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm me-1" @onclick="() => OpenEditTag(t.TagId)">Edit</button>
|
||||
}
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm me-1" @onclick="() => OpenEditTag(t.TagId)">Edit</button>
|
||||
<button type="button" class="btn btn-outline-danger btn-sm" @onclick="() => DeleteTag(t.TagId)">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -201,106 +177,9 @@ else
|
||||
</table>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(_convertMessage))
|
||||
{
|
||||
<div class="text-success small mb-2">@_convertMessage</div>
|
||||
}
|
||||
|
||||
<AuthorizeView Policy="FleetAdmin">
|
||||
<Authorized>
|
||||
@if (!string.IsNullOrWhiteSpace(_convertError))
|
||||
{
|
||||
<div class="text-danger small mb-2">@_convertError</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; _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>
|
||||
}
|
||||
|
||||
<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"
|
||||
OnSaved="OnTagSavedAsync" OnCancel="@(() => { _tagModalVisible = false; })" />
|
||||
|
||||
<AliasTagModal Visible="_aliasModalVisible" IsNew="_aliasModalIsNew" EquipmentId="@EquipmentId"
|
||||
Existing="_aliasModalExisting" Gateways="_gateways"
|
||||
OnSaved="OnAliasSavedAsync" OnCancel="@(() => { _aliasModalVisible = false; })" />
|
||||
}
|
||||
else if (_activeTab == "vtags")
|
||||
{
|
||||
@@ -421,24 +300,6 @@ else
|
||||
private TagEditDto? _tagModalExisting;
|
||||
private IReadOnlyList<(string Id, string Display, string DriverType)> _tagDriverOptions = Array.Empty<(string, string, string)>();
|
||||
|
||||
// --- Alias-tag modal state (Galaxy alias = an equipment Tag bound to a GalaxyMxGateway driver). The
|
||||
// gateways are reloaded alongside _tags so the Add-alias button can disable itself when none exist. ---
|
||||
private IReadOnlyList<(string DriverInstanceId, string Display, string DriverConfig)> _gateways
|
||||
= Array.Empty<(string, string, string)>();
|
||||
private bool _aliasModalVisible;
|
||||
private bool _aliasModalIsNew;
|
||||
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.
|
||||
// _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;
|
||||
private string? _vtagError;
|
||||
@@ -478,8 +339,6 @@ else
|
||||
private async Task ReloadTagsAsync()
|
||||
{
|
||||
_tags = await Svc.LoadTagsForEquipmentAsync(EquipmentId!);
|
||||
// Also refresh the candidate Galaxy gateways so the Add-alias affordance reflects the cluster.
|
||||
_gateways = await Svc.LoadGalaxyGatewaysForEquipmentAsync(EquipmentId!);
|
||||
}
|
||||
|
||||
private async Task OpenAddTag()
|
||||
@@ -520,70 +379,6 @@ else
|
||||
else { _tagError = r.Error; }
|
||||
}
|
||||
|
||||
// --- Alias-tag handlers (mirror the tag handlers; aliases live in the same _tags list + delete the
|
||||
// same way, so only the create/edit modal differs — it embeds the Galaxy live-browse picker). ---
|
||||
|
||||
private async Task OpenAddAlias()
|
||||
{
|
||||
_tagError = null;
|
||||
_gateways = await Svc.LoadGalaxyGatewaysForEquipmentAsync(EquipmentId!);
|
||||
_aliasModalIsNew = true;
|
||||
_aliasModalExisting = null;
|
||||
_aliasModalVisible = true;
|
||||
}
|
||||
|
||||
private async Task OpenEditAlias(string tagId)
|
||||
{
|
||||
_tagError = null;
|
||||
var dto = await Svc.LoadAliasTagAsync(tagId);
|
||||
if (dto is null) { _tagError = "That alias no longer exists; the list was refreshed."; await ReloadTagsAsync(); return; }
|
||||
_aliasModalIsNew = false;
|
||||
_aliasModalExisting = dto;
|
||||
_aliasModalVisible = true;
|
||||
}
|
||||
|
||||
private async Task OnAliasSavedAsync()
|
||||
{
|
||||
_aliasModalVisible = false;
|
||||
await ReloadTagsAsync();
|
||||
}
|
||||
|
||||
// --- Relay→alias converter handlers (per-equipment, scoped to EquipmentId). Dry-run first to fill
|
||||
// the inline preview panel; Apply mutates the draft then reloads the tags + virtual-tags lists so
|
||||
// the converted vtags vanish and the new aliases appear. ---
|
||||
|
||||
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; }
|
||||
}
|
||||
|
||||
// --- Virtual Tags tab handlers ---
|
||||
|
||||
private async Task ReloadVirtualTagsAsync()
|
||||
@@ -686,11 +481,6 @@ else
|
||||
_tags = null;
|
||||
_vtags = null;
|
||||
_alarms = null;
|
||||
// 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!);
|
||||
|
||||
Reference in New Issue
Block a user