Adds the draft-editor tab + page surface for authoring Phase 7 virtual tags and scripted alarms, plus the /alarms/historian operator diagnostics page. Monaco loads from CDN via a progressive-enhancement JS shim — the textarea works immediately so the page is functional even if the CDN is unreachable. ## New services (Admin) - ScriptService — CRUD for Script entity. SHA-256 SourceHash recomputed on save so Core.Scripting's CompiledScriptCache hits on re-publish of unchanged source + misses when the source actually changes. - VirtualTagService — CRUD for VirtualTag, with Enabled toggle. - ScriptedAlarmService — CRUD for ScriptedAlarm + lookup of persistent ScriptedAlarmState (logical-id-keyed per plan decision #14). - ScriptTestHarnessService — pre-publish dry-run. Enforces plan decision #22: only inputs the DependencyExtractor identifies can be supplied. Missing / extra synthetic inputs surface as dedicated outcomes. Captures SetVirtualTag writes + Serilog events from the script so the operator can see both the output + the log output before publishing. - HistorianDiagnosticsService — surfaces the local-process IAlarmHistorianSink state on /alarms/historian. Null sink reports Disabled + swallows retry. Live SqliteStoreAndForwardSink reports real queue depth + last-error + drain state and routes the Retry-dead-lettered button through. ## New UI - ScriptsTab.razor (inside DraftEditor tabs) — list + create/edit/delete scripts with Monaco editor + dependency preview + test-harness run panel showing output + writes + log emissions. - ScriptEditor.razor — reusable Monaco-backed textarea. Loads editor from CDN via wwwroot/js/monaco-loader.js. Textarea stays authoritative for Blazor binding; Monaco mirrors into it on every keystroke. - AlarmsHistorian.razor (/alarms/historian) — queue depth + dead-letter depth + drain state badge + last-error banner + Retry-dead-lettered button. - DraftEditor.razor — new "Scripts" tab. ## DI wiring All five services registered in Program.cs. Null historian sink bound at Admin composition time (real SqliteStoreAndForwardSink lives in the Server process). ## Tests — 13/13 Phase7ServicesTests covers: - ScriptService: Add generates logical id + hash, Update recomputes hash on source change, Update same-source keeps hash (cache-hit preservation), Delete is idempotent - VirtualTagService: round-trips trigger flags, Enabled toggle works - ScriptedAlarmService: HistorizeToAveva defaults true per plan decision #15 - ScriptTestHarness: successful run captures output + writes, rejects missing / extra inputs, rejects non-literal paths, compile errors surface as Threw - HistorianDiagnosticsService: null sink reports Disabled + retry returns 0
106 lines
4.8 KiB
Plaintext
106 lines
4.8 KiB
Plaintext
@page "/clusters/{ClusterId}/draft/{GenerationId:long}"
|
|
@using ZB.MOM.WW.OtOpcUa.Admin.Services
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Validation
|
|
@inject GenerationService GenerationSvc
|
|
@inject DraftValidationService ValidationSvc
|
|
@inject NavigationManager Nav
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<div>
|
|
<h1 class="mb-0">Draft editor</h1>
|
|
<small class="text-muted">Cluster <code>@ClusterId</code> · generation @GenerationId</small>
|
|
</div>
|
|
<div>
|
|
<a class="btn btn-outline-secondary" href="/clusters/@ClusterId">Back to cluster</a>
|
|
<a class="btn btn-outline-primary ms-2" href="/clusters/@ClusterId/draft/@GenerationId/diff">View diff</a>
|
|
<button class="btn btn-primary ms-2" disabled="@(_errors.Count != 0 || _busy)" @onclick="PublishAsync">Publish</button>
|
|
</div>
|
|
</div>
|
|
|
|
<ul class="nav nav-tabs mb-3">
|
|
<li class="nav-item"><button class="nav-link @Active("equipment")" @onclick='() => _tab = "equipment"'>Equipment</button></li>
|
|
<li class="nav-item"><button class="nav-link @Active("uns")" @onclick='() => _tab = "uns"'>UNS</button></li>
|
|
<li class="nav-item"><button class="nav-link @Active("namespaces")" @onclick='() => _tab = "namespaces"'>Namespaces</button></li>
|
|
<li class="nav-item"><button class="nav-link @Active("drivers")" @onclick='() => _tab = "drivers"'>Drivers</button></li>
|
|
<li class="nav-item"><button class="nav-link @Active("acls")" @onclick='() => _tab = "acls"'>ACLs</button></li>
|
|
<li class="nav-item"><button class="nav-link @Active("scripts")" @onclick='() => _tab = "scripts"'>Scripts</button></li>
|
|
</ul>
|
|
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
@if (_tab == "equipment") { <EquipmentTab GenerationId="@GenerationId" ClusterId="@ClusterId"/> }
|
|
else if (_tab == "uns") { <UnsTab GenerationId="@GenerationId" ClusterId="@ClusterId"/> }
|
|
else if (_tab == "namespaces") { <NamespacesTab GenerationId="@GenerationId" ClusterId="@ClusterId"/> }
|
|
else if (_tab == "drivers") { <DriversTab GenerationId="@GenerationId" ClusterId="@ClusterId"/> }
|
|
else if (_tab == "acls") { <AclsTab GenerationId="@GenerationId" ClusterId="@ClusterId"/> }
|
|
else if (_tab == "scripts") { <ScriptsTab GenerationId="@GenerationId" ClusterId="@ClusterId"/> }
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card sticky-top">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<strong>Validation</strong>
|
|
<button class="btn btn-sm btn-outline-secondary" @onclick="RevalidateAsync">Re-run</button>
|
|
</div>
|
|
<div class="card-body">
|
|
@if (_validating) { <p class="text-muted">Checking…</p> }
|
|
else if (_errors.Count == 0) { <div class="alert alert-success mb-0">No validation errors — safe to publish.</div> }
|
|
else
|
|
{
|
|
<div class="alert alert-danger mb-2">@_errors.Count error@(_errors.Count == 1 ? "" : "s")</div>
|
|
<ul class="list-unstyled">
|
|
@foreach (var e in _errors)
|
|
{
|
|
<li class="mb-2">
|
|
<span class="badge bg-danger me-1">@e.Code</span>
|
|
<small>@e.Message</small>
|
|
@if (!string.IsNullOrEmpty(e.Context)) { <div class="text-muted"><code>@e.Context</code></div> }
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
@if (_publishError is not null) { <div class="alert alert-danger mt-3">@_publishError</div> }
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public string ClusterId { get; set; } = string.Empty;
|
|
[Parameter] public long GenerationId { get; set; }
|
|
|
|
private string _tab = "equipment";
|
|
private List<ValidationError> _errors = [];
|
|
private bool _validating;
|
|
private bool _busy;
|
|
private string? _publishError;
|
|
|
|
private string Active(string k) => _tab == k ? "active" : string.Empty;
|
|
|
|
protected override async Task OnParametersSetAsync() => await RevalidateAsync();
|
|
|
|
private async Task RevalidateAsync()
|
|
{
|
|
_validating = true;
|
|
try
|
|
{
|
|
var errors = await ValidationSvc.ValidateAsync(GenerationId, CancellationToken.None);
|
|
_errors = errors.ToList();
|
|
}
|
|
finally { _validating = false; }
|
|
}
|
|
|
|
private async Task PublishAsync()
|
|
{
|
|
_busy = true;
|
|
_publishError = null;
|
|
try
|
|
{
|
|
await GenerationSvc.PublishAsync(ClusterId, GenerationId, notes: "Published via Admin UI", CancellationToken.None);
|
|
Nav.NavigateTo($"/clusters/{ClusterId}");
|
|
}
|
|
catch (Exception ex) { _publishError = ex.Message; }
|
|
finally { _busy = false; }
|
|
}
|
|
}
|