feat(m9/T26b): TemplateEdit full multi-level inherited set + read-only staleness banner

This commit is contained in:
Joseph Doherty
2026-06-18 13:01:38 -04:00
parent ca6e5da34b
commit 6bc2bb5430
5 changed files with 579 additions and 0 deletions
@@ -14,6 +14,7 @@
@inject ICentralUiRepository CentralUiRepository
@inject TemplateService TemplateService
@inject ZB.MOM.WW.ScadaBridge.CentralUI.ScriptAnalysis.ScriptAnalysisService AnalysisService
@inject ZB.MOM.WW.ScadaBridge.CentralUI.Services.ITemplateInheritanceQueryService InheritanceQuery
@inject AuthenticationStateProvider AuthStateProvider
@inject NavigationManager NavigationManager
@inject IDialogService Dialog
@@ -62,6 +63,12 @@
private Template? _ownerTemplate;
private TemplateComposition? _ownerComposition;
// M9-T26b: the FULL transitively-resolved inherited member set (multi-level
// chain + post-creation base additions) + staleness, fetched read-only via
// GetResolvedTemplateMembersCommand. Populated only for derived templates;
// null when the read failed (editor falls back to the stored-row view).
private Commons.Messages.Management.ResolvedTemplateMembers? _resolved;
private bool _loading = true;
private string? _loadError;
private string _activeTab = "attributes";
@@ -195,6 +202,7 @@
_baseTemplate = null;
_ownerTemplate = null;
_ownerComposition = null;
_resolved = null;
if (_selectedTemplate.IsDerived && _selectedTemplate.ParentTemplateId.HasValue)
{
_baseTemplate = await TemplateEngineRepository.GetTemplateByIdAsync(_selectedTemplate.ParentTemplateId.Value);
@@ -218,6 +226,14 @@
}
}
}
// M9-T26b: resolve the FULL inherited member set (whole chain +
// post-creation base additions) read-only. The stored-row tables
// above only carry the IMMEDIATE base; this surfaces the rest with
// origin annotation + a base-changed staleness banner. Read-only:
// a failed read leaves _resolved null and the editor degrades to
// the stored-row view.
_resolved = await InheritanceQuery.ResolveAsync(Id);
}
// Editor metadata: child compositions + every parent that
@@ -270,6 +286,32 @@
</div>
</div>
}
@* M9-T26b: read-only base-changed banner. Informational only — surfaced
when the freshly-resolved inherited set differs from this template's
stored copy (a multi-level inherited member, or a base member added
after this template was created). No action button: a deploy already
resolves fresh, so this is purely an authoring heads-up. *@
@if (_resolved?.Staleness.IsStale == true)
{
<div class="alert alert-info py-2 mb-3" role="status">
<i class="bi bi-info-circle me-1"></i>
<strong>Base template changed</strong> —
@_resolved.Staleness.DifferingMemberCount inherited member(s) differ from this template's stored copy.
The effective set below reflects the live base; a deploy resolves fresh.
</div>
}
@* M9-T26b: the FULL transitively-resolved inherited member set — the whole
chain (grandparent + further ancestors) plus base members added after
this template was created, which the immediate-base tables below cannot
show. Read-only preview; each row carries its origin template + lock
state, and alarms surface the merged effective trigger configuration. *@
@if (_resolved != null)
{
@RenderInheritedSet()
}
<div class="d-flex justify-content-between align-items-center mb-3">
<div>
<h4 class="d-inline mb-0">@_selectedTemplate.Name</h4>
@@ -419,6 +461,115 @@
}
};
// ---- M9-T26b: full resolved inherited set (read-only preview) ----
/// <summary>
/// Renders the FULL transitively-resolved effective member set (attributes,
/// alarms, scripts, native alarm sources) for a derived template. Read-only:
/// no edit / override / deploy actions — purely an authoring view that shows
/// what the whole inheritance chain resolves to (multi-level + post-creation
/// base additions), which the immediate-base tables below cannot surface.
/// </summary>
private RenderFragment RenderInheritedSet() => __builder =>
{
var r = _resolved!;
<div class="card mb-3 border-info-subtle">
<div class="card-header bg-info-subtle d-flex align-items-center">
<i class="bi bi-diagram-3 me-2"></i>
<span class="fw-semibold">Effective inherited set</span>
<span class="text-muted small ms-2">
Resolved across the full inheritance chain (read-only). Edits stay on the per-tab tables below.
</span>
</div>
<div class="card-body">
@RenderInheritedMemberTable("Attributes", r.Attributes, showTrigger: false)
@RenderInheritedMemberTable("Alarms", r.Alarms, showTrigger: true)
@RenderInheritedMemberTable("Scripts", r.Scripts, showTrigger: false)
@RenderInheritedMemberTable("Native Alarm Sources", r.NativeAlarmSources, showTrigger: false)
@if (r.Attributes.Count == 0 && r.Alarms.Count == 0
&& r.Scripts.Count == 0 && r.NativeAlarmSources.Count == 0)
{
<p class="text-muted small mb-0">No resolved members.</p>
}
</div>
</div>
};
/// <summary>
/// Renders one section (attributes / alarms / scripts / native sources) of the
/// resolved inherited set. Each row shows the effective value (for alarms, the
/// merged <c>EffectiveTriggerConfiguration</c> when <paramref name="showTrigger"/>),
/// the origin template, and inherited / locked / base-locked annotations.
/// </summary>
private RenderFragment RenderInheritedMemberTable(
string title,
IReadOnlyList<Commons.Messages.Management.ResolvedTemplateMemberInfo> members,
bool showTrigger) => __builder =>
{
@if (members.Count > 0)
{
<h6 class="mt-2 mb-2">@title <span class="badge bg-secondary">@members.Count</span></h6>
<table class="table table-sm table-striped mb-3">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Effective value</th>
@if (showTrigger)
{
<th>Trigger config (effective)</th>
}
<th>Source</th>
<th>Lock</th>
</tr>
</thead>
<tbody>
@foreach (var m in members)
{
<tr>
<td>@m.Name</td>
<td class="small">@(m.EffectiveValue ?? "—")</td>
@if (showTrigger)
{
<td class="small text-muted font-monospace text-truncate"
style="max-width: 220px;" title="@m.EffectiveTriggerConfiguration">
@(string.IsNullOrEmpty(m.EffectiveTriggerConfiguration) ? "—" : m.EffectiveTriggerConfiguration)
</td>
}
<td>
@if (m.IsInherited)
{
<span class="badge bg-secondary"
title="@($"Inherited from {m.OriginTemplateName}")">
Inherited from @m.OriginTemplateName
</span>
}
else
{
<span class="badge bg-light text-dark">Local</span>
}
</td>
<td>
@if (m.IsBaseLocked)
{
<span class="badge bg-warning text-dark" title="A base template forbids overriding this member.">🔒 Base-locked</span>
}
else if (m.IsLocked)
{
<span class="badge bg-danger" aria-label="Locked">Locked</span>
}
else
{
<span class="badge bg-light text-dark" aria-label="Unlocked">Unlocked</span>
}
</td>
</tr>
}
</tbody>
</table>
}
};
private async Task DeleteTemplate()
{
if (_selectedTemplate == null) return;