feat(m9/T24b): move-data-connection UI dialog + action
This commit is contained in:
@@ -42,6 +42,12 @@
|
||||
|
||||
<ToastNotification @ref="_toast" />
|
||||
|
||||
<MoveDataConnectionDialog @bind-IsVisible="_showMoveDialog"
|
||||
ConnectionId="_moveConnectionId"
|
||||
ConnectionName="@_moveConnectionName"
|
||||
SiteOptions="MoveTargetSiteOptions()"
|
||||
OnMoved="OnConnectionMoved" />
|
||||
|
||||
@if (_loading)
|
||||
{
|
||||
<LoadingSpinner IsLoading="true" />
|
||||
@@ -124,6 +130,12 @@
|
||||
Edit
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button class="dropdown-item"
|
||||
@onclick="() => OpenMoveDialog(node.Connection!)">
|
||||
Move to Site…
|
||||
</button>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider" /></li>
|
||||
<li>
|
||||
<button class="dropdown-item text-danger"
|
||||
@@ -150,6 +162,10 @@
|
||||
@onclick='() => NavigationManager.NavigateTo($"/design/connections/{node.Connection!.Id}/edit")'>
|
||||
Edit
|
||||
</button>
|
||||
<button class="dropdown-item"
|
||||
@onclick="() => OpenMoveDialog(node.Connection!)">
|
||||
Move to Site…
|
||||
</button>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item text-danger"
|
||||
@onclick="() => DeleteConnection(node.Connection!)">
|
||||
@@ -409,6 +425,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ── M9-T24b: Move connection to another site ──
|
||||
// The dialog dispatches MoveDataConnectionCommand through the guard-running
|
||||
// ManagementActor path (IDataConnectionMoveService) — NOT a direct repository
|
||||
// write — so the server enforces the Designer gate and every move guard. The
|
||||
// page only opens the dialog, supplies the candidate target sites (the current
|
||||
// site excluded), and reloads the tree once the move succeeds.
|
||||
private bool _showMoveDialog;
|
||||
private int _moveConnectionId;
|
||||
private int _moveConnectionSiteId;
|
||||
private string _moveConnectionName = string.Empty;
|
||||
|
||||
private void OpenMoveDialog(DataConnection conn)
|
||||
{
|
||||
_moveConnectionId = conn.Id;
|
||||
_moveConnectionSiteId = conn.SiteId;
|
||||
_moveConnectionName = conn.Name;
|
||||
_showMoveDialog = true;
|
||||
}
|
||||
|
||||
// Candidate target sites for the move: every site EXCEPT the connection's
|
||||
// current one. Sourced from the already-loaded tree roots (each root is a site).
|
||||
private IEnumerable<(int Id, string Label)> MoveTargetSiteOptions() =>
|
||||
_treeRoots
|
||||
.Where(r => r.SiteId is int sid && sid != _moveConnectionSiteId)
|
||||
.Select(r => (r.SiteId!.Value, r.Label));
|
||||
|
||||
private async Task OnConnectionMoved()
|
||||
{
|
||||
_toast.ShowSuccess($"Connection '{_moveConnectionName}' moved.");
|
||||
await LoadDataAsync();
|
||||
}
|
||||
|
||||
// M9-T25: enum → Bootstrap badge class. Mirrors the Health dashboard's
|
||||
// GetConnectionHealthBadge (Components/Pages/Monitoring/Health.razor) so the
|
||||
// design page surfaces the same colour coding for the same status. Kept as a
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
|
||||
@inject IDataConnectionMoveService MoveService
|
||||
|
||||
@*
|
||||
M9-T24b: Move a data connection to another site. The picker lists the candidate
|
||||
target sites (the page excludes the connection's current site). On confirm the
|
||||
dialog dispatches MoveDataConnectionCommand through IDataConnectionMoveService —
|
||||
the guard-running ManagementActor path, NOT a direct repository write — so the
|
||||
server's Designer gate and every move guard (target exists, no name collision, no
|
||||
instance binding, no native-alarm-source name reference) run. A guard error is
|
||||
shown inline and the dialog stays open; success closes the dialog and raises
|
||||
OnMoved so the page reloads the tree. Mirrors the MoveFolderDialog idiom.
|
||||
*@
|
||||
@if (IsVisible)
|
||||
{
|
||||
<div class="modal show d-block" tabindex="-1" style="background: rgba(0,0,0,0.4);">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h6 class="modal-title">Move '@ConnectionName' to site…</h6>
|
||||
<button type="button" class="btn-close" @onclick="Close" disabled="@_busy"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@if (SiteOptions.Any())
|
||||
{
|
||||
<select class="form-select form-select-sm" @bind="_targetSiteId">
|
||||
@foreach (var opt in SiteOptions)
|
||||
{
|
||||
<option value="@opt.Id">@opt.Label</option>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="text-muted small">No other site is available to move this connection to.</div>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(_error))
|
||||
{
|
||||
<div class="text-danger small mt-2" data-test="move-connection-error">@_error</div>
|
||||
}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-outline-secondary btn-sm" @onclick="Close" disabled="@_busy">Cancel</button>
|
||||
<button class="btn btn-primary btn-sm" @onclick="Submit"
|
||||
disabled="@(_busy || !SiteOptions.Any())">Move</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public bool IsVisible { get; set; }
|
||||
[Parameter] public EventCallback<bool> IsVisibleChanged { get; set; }
|
||||
[Parameter] public int ConnectionId { get; set; }
|
||||
[Parameter] public string ConnectionName { get; set; } = string.Empty;
|
||||
[Parameter] public IEnumerable<(int Id, string Label)> SiteOptions { get; set; } = Array.Empty<(int, string)>();
|
||||
|
||||
/// <summary>Raised after a successful move so the page can reload the tree.</summary>
|
||||
[Parameter] public EventCallback OnMoved { get; set; }
|
||||
|
||||
private bool _wasVisible;
|
||||
private int? _targetSiteId;
|
||||
private string? _error;
|
||||
private bool _busy;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
// Reset internal state on transition from hidden -> visible: default the
|
||||
// picker to the first candidate site and clear any prior error.
|
||||
if (IsVisible && !_wasVisible)
|
||||
{
|
||||
_targetSiteId = SiteOptions.Select(o => (int?)o.Id).FirstOrDefault();
|
||||
_error = null;
|
||||
_busy = false;
|
||||
}
|
||||
_wasVisible = IsVisible;
|
||||
}
|
||||
|
||||
private async Task Close()
|
||||
{
|
||||
await IsVisibleChanged.InvokeAsync(false);
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
if (_targetSiteId is not int target || _busy) return;
|
||||
|
||||
_busy = true;
|
||||
_error = null;
|
||||
var result = await MoveService.MoveAsync(ConnectionId, target);
|
||||
_busy = false;
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
await IsVisibleChanged.InvokeAsync(false);
|
||||
await OnMoved.InvokeAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Surface the server guard error inline; keep the dialog open.
|
||||
_error = result.Error ?? "Move failed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user