Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Design/ExternalSystemForm.razor
T
Joseph Doherty 7b0b9c7365 refactor: rename ScadaLink → ZB.MOM.WW.ScadaBridge (code + projects + namespaces)
Solution + 23 src projects + 26 test projects renamed; folders, csproj,
namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated.
ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated.
SQL roles/logins, LDAP domains, CLI command name, and CLI config dir
(~/.scadalink → ~/.scadabridge) also renamed.

Build green; 5 Host.Tests fail awaiting SQL login rename in next commit.
Pre-existing StaleTagMonitor timing flakes unchanged.

Rename script committed at tools/rename-to-scadabridge.sh.
2026-05-28 09:37:45 -04:00

161 lines
6.1 KiB
Plaintext

@page "/design/external-systems/create"
@page "/design/external-systems/{Id:int}/edit"
@using ZB.MOM.WW.ScadaBridge.Security
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.ExternalSystems
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories
@attribute [Authorize(Policy = AuthorizationPolicies.RequireDesign)]
@inject IExternalSystemRepository ExternalSystemRepository
@inject NavigationManager NavigationManager
<div class="container-fluid mt-3">
<button class="btn btn-link text-decoration-none ps-0 mb-2" @onclick="GoBack">&larr; Back</button>
<div class="d-flex justify-content-between align-items-center mb-3">
<h4 class="mb-0">@(Id.HasValue ? "Edit External System" : "Add External System")</h4>
@* Bundle D (#23 M7-T12) drill-in: deep-link into the central Audit Log
pre-filtered to this external system's outbound API events. Audit rows
record the target by external-system name, so we filter on Target. *@
@if (Id.HasValue && !string.IsNullOrWhiteSpace(_name))
{
<a class="btn btn-outline-secondary btn-sm"
href="/audit/log?target=@Uri.EscapeDataString(_name)"
data-test="audit-link">
Recent audit activity
</a>
}
</div>
@if (_loading)
{
<LoadingSpinner IsLoading="true" />
}
else
{
<div class="card">
<div class="card-body">
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" class="form-control" @bind="_name" />
</div>
<div class="mb-3">
<label class="form-label">Endpoint URL</label>
<input type="text" class="form-control" @bind="_endpointUrl" />
</div>
<div class="mb-3">
<label class="form-label">Auth Type</label>
<select class="form-select" @bind="_authType">
<option>ApiKey</option>
<option>BasicAuth</option>
<option>None</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Auth Config (JSON)</label>
<input type="text" class="form-control" @bind="_authConfig"
placeholder="@_authConfigPlaceholder" />
</div>
<div class="mb-3">
<label class="form-label">Max Retries</label>
<input type="number" class="form-control" @bind="_maxRetries" min="0" />
</div>
<div class="mb-3">
<label class="form-label">Retry Delay (seconds)</label>
<input type="number" class="form-control" @bind="_retryDelaySeconds" min="0" />
</div>
@if (_formError != null)
{
<div class="text-danger small mb-2">@_formError</div>
}
<div class="d-flex gap-2">
<button class="btn btn-success" @onclick="Save">Save</button>
<button class="btn btn-outline-secondary" @onclick="GoBack">Cancel</button>
</div>
</div>
</div>
}
</div>
@code {
[Parameter] public int? Id { get; set; }
private bool _loading = true;
private string _name = "", _endpointUrl = "", _authType = "ApiKey";
private string? _authConfig;
private int _maxRetries = 3;
private int _retryDelaySeconds = 5;
private string? _formError;
private ExternalSystemDefinition? _existing;
// Per-AuthType placeholder that hints at the expected JSON shape for AuthConfig.
private string _authConfigPlaceholder => _authType switch
{
"ApiKey" => "{\"key\":\"xyz\"}",
"BasicAuth" => "{\"username\":\"u\",\"password\":\"p\"}",
_ => "{}"
};
protected override async Task OnInitializedAsync()
{
if (Id.HasValue)
{
try
{
_existing = await ExternalSystemRepository.GetExternalSystemByIdAsync(Id.Value);
if (_existing != null)
{
_name = _existing.Name;
_endpointUrl = _existing.EndpointUrl;
_authType = _existing.AuthType;
_authConfig = _existing.AuthConfiguration;
_maxRetries = _existing.MaxRetries;
_retryDelaySeconds = (int)_existing.RetryDelay.TotalSeconds;
}
}
catch (Exception ex) { _formError = ex.Message; }
}
_loading = false;
}
private async Task Save()
{
_formError = null;
if (string.IsNullOrWhiteSpace(_name) || string.IsNullOrWhiteSpace(_endpointUrl))
{
_formError = "Name and URL required.";
return;
}
try
{
if (_existing != null)
{
_existing.Name = _name.Trim();
_existing.EndpointUrl = _endpointUrl.Trim();
_existing.AuthType = _authType;
_existing.AuthConfiguration = _authConfig?.Trim();
_existing.MaxRetries = _maxRetries;
_existing.RetryDelay = TimeSpan.FromSeconds(_retryDelaySeconds);
await ExternalSystemRepository.UpdateExternalSystemAsync(_existing);
}
else
{
var es = new ExternalSystemDefinition(_name.Trim(), _endpointUrl.Trim(), _authType)
{
AuthConfiguration = _authConfig?.Trim(),
MaxRetries = _maxRetries,
RetryDelay = TimeSpan.FromSeconds(_retryDelaySeconds)
};
await ExternalSystemRepository.AddExternalSystemAsync(es);
}
await ExternalSystemRepository.SaveChangesAsync();
NavigationManager.NavigateTo("/design/external-systems");
}
catch (Exception ex) { _formError = ex.Message; }
}
private void GoBack() => NavigationManager.NavigateTo("/design/external-systems");
}