187 lines
7.9 KiB
Plaintext
187 lines
7.9 KiB
Plaintext
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
|
|
@using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management
|
|
@inject IServiceProvider MutationServices
|
|
@page "/admin/sites/create"
|
|
@page "/admin/sites/{Id:int}/edit"
|
|
@using ZB.MOM.WW.ScadaBridge.Security
|
|
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites
|
|
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories
|
|
@using ZB.MOM.WW.ScadaBridge.Communication
|
|
@attribute [Authorize(Policy = AuthorizationPolicies.RequireAdmin)]
|
|
@inject ISiteRepository SiteRepository
|
|
@inject CommunicationService CommunicationService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<div class="container-fluid mt-3">
|
|
<div class="mb-3">
|
|
<button class="btn btn-outline-secondary btn-sm" @onclick="GoBack">
|
|
← Back
|
|
</button>
|
|
</div>
|
|
|
|
<ToastNotification @ref="_toast" />
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span class="fw-semibold">@(IsEditMode ? "Edit Site" : "Add Site")</span>
|
|
@* Drill-in: deep-link into the central Audit
|
|
Log pre-filtered to this site's events. AuditEvent.SourceSiteId
|
|
stores the SiteIdentifier (string), so we pass that through. *@
|
|
@if (IsEditMode && !string.IsNullOrWhiteSpace(_formIdentifier))
|
|
{
|
|
<a class="btn btn-outline-secondary btn-sm"
|
|
href="/audit/log?site=@Uri.EscapeDataString(_formIdentifier)"
|
|
data-test="audit-link">
|
|
Recent audit activity
|
|
</a>
|
|
}
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="mb-2">
|
|
<label class="form-label small" for="@($"{_fieldScope}-field-1")">Identifier</label>
|
|
<input id="@($"{_fieldScope}-field-1")" type="text" class="form-control form-control-sm" @bind="_formIdentifier"
|
|
disabled="@IsEditMode" />
|
|
</div>
|
|
<div class="mb-2">
|
|
<label class="form-label small" for="@($"{_fieldScope}-field-2")">Name</label>
|
|
<input id="@($"{_fieldScope}-field-2")" type="text" class="form-control form-control-sm" @bind="_formName" />
|
|
</div>
|
|
<div class="mb-0">
|
|
<label class="form-label small" for="@($"{_fieldScope}-field-3")">Description</label>
|
|
<input id="@($"{_fieldScope}-field-3")" type="text" class="form-control form-control-sm" @bind="_formDescription" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<span class="fw-semibold">Node A</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="mb-2">
|
|
<label class="form-label small" for="@($"{_fieldScope}-field-4")">Akka Address (legacy — unused)</label>
|
|
<input aria-describedby="@($"{_helpScope}-0")" id="@($"{_fieldScope}-field-4")" type="text" class="form-control form-control-sm" @bind="_formNodeAAddress"
|
|
placeholder="akka.tcp://scadabridge@host:port/user/site-communication" />
|
|
<div class="form-text" id="@($"{_helpScope}-0")">
|
|
Retained for historical configuration only — nothing reads it at runtime.
|
|
Central dials the gRPC address below.
|
|
</div>
|
|
</div>
|
|
<div class="mb-0">
|
|
<label class="form-label small" for="@($"{_fieldScope}-field-5")">gRPC Address</label>
|
|
<input id="@($"{_fieldScope}-field-5")" type="text" class="form-control form-control-sm" @bind="_formGrpcNodeAAddress"
|
|
placeholder="http://host:8083" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-header">
|
|
<span class="fw-semibold">Node B</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="mb-2">
|
|
<label class="form-label small" for="@($"{_fieldScope}-field-6")">Akka Address (legacy — unused)</label>
|
|
<input aria-describedby="@($"{_helpScope}-1")" id="@($"{_fieldScope}-field-6")" type="text" class="form-control form-control-sm" @bind="_formNodeBAddress"
|
|
placeholder="akka.tcp://scadabridge@host:port/user/site-communication" />
|
|
<div class="form-text" id="@($"{_helpScope}-1")">
|
|
Retained for historical configuration only — nothing reads it at runtime.
|
|
Central dials the gRPC address below.
|
|
</div>
|
|
</div>
|
|
<div class="mb-0">
|
|
<label class="form-label small" for="@($"{_fieldScope}-field-7")">gRPC Address</label>
|
|
<input id="@($"{_fieldScope}-field-7")" type="text" class="form-control form-control-sm" @bind="_formGrpcNodeBAddress"
|
|
placeholder="http://host:8083" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@if (_formError != null)
|
|
{
|
|
<div class="text-danger small mt-2">@_formError</div>
|
|
}
|
|
<div class="mb-3">
|
|
<div class="btn-group btn-group-sm" role="group">
|
|
<button class="btn btn-success" @onclick="SaveSite">Save</button>
|
|
<button class="btn btn-outline-secondary" @onclick="GoBack">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public int? Id { get; set; }
|
|
|
|
private bool IsEditMode => Id.HasValue;
|
|
|
|
private Site? _editingSite;
|
|
private string _formName = string.Empty;
|
|
private string _formIdentifier = string.Empty;
|
|
private string? _formDescription;
|
|
private string? _formNodeAAddress;
|
|
private string? _formNodeBAddress;
|
|
private string? _formGrpcNodeAAddress;
|
|
private string? _formGrpcNodeBAddress;
|
|
private string? _formError;
|
|
|
|
private ToastNotification _toast = default!;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (Id.HasValue)
|
|
{
|
|
_editingSite = await SiteRepository.GetSiteByIdAsync(Id.Value);
|
|
if (_editingSite != null)
|
|
{
|
|
_formName = _editingSite.Name;
|
|
_formIdentifier = _editingSite.SiteIdentifier;
|
|
_formDescription = _editingSite.Description;
|
|
_formNodeAAddress = _editingSite.NodeAAddress;
|
|
_formNodeBAddress = _editingSite.NodeBAddress;
|
|
_formGrpcNodeAAddress = _editingSite.GrpcNodeAAddress;
|
|
_formGrpcNodeBAddress = _editingSite.GrpcNodeBAddress;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GoBack()
|
|
{
|
|
NavigationManager.NavigateTo("/admin/sites");
|
|
}
|
|
|
|
private async Task SaveSite()
|
|
{
|
|
_formError = null;
|
|
|
|
if (string.IsNullOrWhiteSpace(_formName))
|
|
{
|
|
_formError = "Name is required.";
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (_editingSite is null && string.IsNullOrWhiteSpace(_formIdentifier))
|
|
{
|
|
_formError = "Identifier is required.";
|
|
return;
|
|
}
|
|
await MutationServices.ExecuteConfigurationAsync(_editingSite is not null
|
|
? new UpdateSiteCommand(_editingSite.Id, _formName.Trim(), _formDescription?.Trim(),
|
|
_formNodeAAddress?.Trim(), _formNodeBAddress?.Trim(), _formGrpcNodeAAddress?.Trim(), _formGrpcNodeBAddress?.Trim())
|
|
: new CreateSiteCommand(_formName.Trim(), _formIdentifier.Trim(), _formDescription?.Trim(),
|
|
_formNodeAAddress?.Trim(), _formNodeBAddress?.Trim(), _formGrpcNodeAAddress?.Trim(), _formGrpcNodeBAddress?.Trim()));
|
|
CommunicationService.RefreshSiteAddresses();
|
|
NavigationManager.NavigateTo("/admin/sites");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_formError = $"Save failed: {ex.Message}";
|
|
}
|
|
}
|
|
}
|
|
|
|
@code { private readonly string _fieldScope = "field-" + Guid.NewGuid().ToString("N"); }
|
|
|
|
@code { private readonly string _helpScope = "help-" + Guid.NewGuid().ToString("N"); }
|