diff --git a/src/ScadaLink.CentralUI/Components/Pages/Design/TemplateEdit.razor b/src/ScadaLink.CentralUI/Components/Pages/Design/TemplateEdit.razor index dc54627..d661774 100644 --- a/src/ScadaLink.CentralUI/Components/Pages/Design/TemplateEdit.razor +++ b/src/ScadaLink.CentralUI/Components/Pages/Design/TemplateEdit.razor @@ -103,20 +103,15 @@ = Array.Empty(); /// - /// One entry per template that composes this one (in the design-time - /// graph). Populated by ; the user - /// picks one via when multiple exist. + /// Editor's Parent.* context. Empty for base templates (no owner exists); + /// exactly one entry for derived templates — the slot-owner resolved from + /// the template's OwnerCompositionId. /// private List _editorParents = new(); - /// Index into ; -1 when none. - private int _selectedParentIndex = -1; - private ScadaLink.CentralUI.ScriptAnalysis.CompositionContext? ActiveEditorParent => - _selectedParentIndex >= 0 && _selectedParentIndex < _editorParents.Count - ? _editorParents[_selectedParentIndex] - : null; + _editorParents.FirstOrDefault(); private bool _showCompForm; private int _compComposedTemplateId; @@ -190,7 +185,6 @@ // editor. _editorChildren = await BuildChildContextsAsync(_compositions); _editorParents = await BuildParentContextsAsync(Id); - _selectedParentIndex = _editorParents.Count > 0 ? 0 : -1; _validationResult = null; } @@ -865,21 +859,6 @@
- @if (_editorParents.Count > 1) - { -
- Parent context for editor: - - (this template is composed by @_editorParents.Count parents; pick one for Parent.* assistance) -
- } > BuildParentContextsAsync(int templateId) { - var parents = await TemplateEngineRepository.GetTemplatesComposingAsync(templateId); - return parents - .Select(p => BuildCompositionContext(p.Name, p)) - .ToList(); + // Post derive-on-compose: only derived templates have a parent context, + // and exactly one — the template that owns their composition slot. + // Base templates suppress Parent.* assistance. + if (_selectedTemplate?.IsDerived != true || _ownerTemplate == null) + return new List(); + + // Resolve the owner with eager-loaded members so the context has shapes. + var owner = await TemplateEngineRepository.GetTemplateByIdAsync(_ownerTemplate.Id); + if (owner == null) + return new List(); + + return new List + { + BuildCompositionContext(owner.Name, owner) + }; } private static ScadaLink.CentralUI.ScriptAnalysis.CompositionContext BuildCompositionContext( @@ -1331,12 +1321,6 @@ return new ScadaLink.CentralUI.ScriptAnalysis.CompositionContext(label, attrs, scripts); } - private void OnParentContextChanged(ChangeEventArgs e) - { - if (int.TryParse(e.Value?.ToString(), out var idx) && idx >= 0 && idx < _editorParents.Count) - _selectedParentIndex = idx; - } - private static string MapDataType(ScadaLink.Commons.Types.Enums.DataType dt) => dt switch { ScadaLink.Commons.Types.Enums.DataType.Boolean => "Boolean",