Skip to content

Commit

Permalink
Override renderring attribute (#319)
Browse files Browse the repository at this point in the history
* just build

* BaseAttribute in progress

* Added test for presentationBase atribute

* Rename PresentationBaseAttribute to RenderTemplateOverrideAttribute

* Repair override attribute.

* Tests

* Repair

---------

Co-authored-by: blazej.kuhajda <blazej.kuhajda@mts.sk>
  • Loading branch information
Brano5 and blazej.kuhajda authored Jun 13, 2024
1 parent 0ed2b81 commit 3152490
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,6 @@
if (element == null)
return;

var overrideAttribute = AttributesHandler.GetRenderTemplateOverrideAttribute(element);

if (overrideAttribute != null)
{

if (!string.IsNullOrWhiteSpace(overrideAttribute.TemplateOverrideName))
{
var presentation = GetDisplayPresentationIfEmpty();
var pipeline = presentation.Split('-');

foreach (var item in pipeline) // apply pipeline
{
string fullPresentationType = overrideAttribute.TemplateOverrideName + GetDisplayPresentationIfEmpty() + "View";
var tcomponent = ComponentService.GetComponent(fullPresentationType);

if (tcomponent != null)
{
if (element is ITwinPrimitive)
{
@CreatePrimitiveComponent((ITwinPrimitive)element, tcomponent)
;
return;
}
if (element is ITwinObject)
{
@CreateComplexComponent((ITwinObject)element, tcomponent)
;
return;
}

}
}

}

}


// if it is primitive type, just generate
if (element is ITwinPrimitive)
{
Expand Down Expand Up @@ -161,7 +123,6 @@

private RenderFragment Generator(ITwinElement kid, Type layout) => __builder =>
{

if (IsEnumerator(kid))
{
var enumDiscriminatorAttribute = AttributesHandler.GetEnumeratorDiscriminatorAttribute(kid);
Expand All @@ -177,7 +138,6 @@
ITwinObject complexKid = (ITwinObject)kid;
@GenerateComplex(complexKid, layout)
}

};

private RenderFragment GenerateComplex(ITwinObject twin, Type layout) => __builder =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ private void UnSubscribeFromPolling()

internal IRenderableComponent ViewLocatorBuilder(Type twinType, ITwinElement twin, string presentationType, string presentationTemplate = null)
{

if (!string.IsNullOrWhiteSpace(presentationTemplate))
{
return ComponentService.GetComponent(presentationTemplate);
Expand All @@ -236,12 +235,27 @@ internal IRenderableComponent ViewLocatorBuilder(Type twinType, ITwinElement twi
{
var presentationName = item;
if (presentationName.ToLower() == "base") presentationName = "";
// try to find component view
var component = GetComponent(twinType, twin, presentationName, namespc);
if (component == null)

IRenderableComponent component = null;

var overrideAttribute = AttributesHandler.GetRenderTemplateOverrideAttribute(twin);

if (overrideAttribute != null && !string.IsNullOrWhiteSpace(overrideAttribute.TemplateOverrideName))
{
//if not found, look at predecessor
component = ViewLocatorBuilder(twinType.BaseType, twin, presentationName, PresentationTemplate);
// try to find override template component view
var buildedComponentName = $"{overrideAttribute.TemplateOverrideName}{presentationName}View";
component = ComponentService.GetComponent(buildedComponentName);
SubscribeForPolling(component, twin);
}
if(component == null) // if not set and foun override template
{
// try to find component view
component = GetComponent(twinType, twin, presentationName, namespc);
if (component == null)
{
//if not found, look at predecessor
component = ViewLocatorBuilder(twinType.BaseType, twin, presentationName, PresentationTemplate);
}
}

if (component != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div name="testingProgram-testRenderInnerOverridedStruct" b-gswuladdww>
<div name="testingProgram-testRenderInnerOverridedStruct-testInteger" class="w-100 form-group mb-2">
<label for:ignore="testingProgram.testRenderInnerOverridedStruct.testInteger_3b4ebb5d-d903-4f6e-9c71-b76767c52365">Test Integer</label>
<input id:ignore="testingProgram.testRenderInnerOverridedStruct.testInteger_3b4ebb5d-d903-4f6e-9c71-b76767c52365" readonly="readonly" class="w-100 form-control " style="background-color:transparent" type="text" step="any" value="0" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="testingProgram.testRenderInnerOverridedStruct.Test Integer" />

<div class="invalid-feedback"></div>
</div><div name="testingProgram-testRenderInnerOverridedStruct-testString" class="w-100 form-group mb-2">
<label for:ignore="testingProgram.testRenderInnerOverridedStruct.testString_85ba0aca-0826-42fe-9359-ed4f0e630899">Test String</label>
<input id:ignore="testingProgram.testRenderInnerOverridedStruct.testString_85ba0aca-0826-42fe-9359-ed4f0e630899" readonly="readonly" class="w-100 form-control " style="background-color:transparent" type="text" step="any" value="" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="testingProgram.testRenderInnerOverridedStruct.Test String" />

<div class="invalid-feedback"></div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div name="testingProgram-testRenderOverridedSimpleStruct" b-gswuladdww>
<div name="testingProgram-testRenderOverridedSimpleStruct-testInteger" class="w-100 form-group mb-2">
<label for:ignore="testingProgram.testRenderOverridedSimpleStruct.testInteger_01362a1b-a1c8-4457-9034-8c13c14efef7">Test Integer</label>
<input id:ignore="testingProgram.testRenderOverridedSimpleStruct.testInteger_01362a1b-a1c8-4457-9034-8c13c14efef7" readonly="readonly" class="w-100 form-control " style="background-color:transparent" type="text" step="any" value="0" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="testingProgram.testRenderOverridedSimpleStruct.Test Integer" />

<div class="invalid-feedback"></div>
</div><div name="testingProgram-testRenderOverridedSimpleStruct-testString" class="w-100 form-group mb-2">
<label for:ignore="testingProgram.testRenderOverridedSimpleStruct.testString_53ce35dc-d0f3-41e1-9038-7f8000f58d6a">Test String</label>
<input id:ignore="testingProgram.testRenderOverridedSimpleStruct.testString_53ce35dc-d0f3-41e1-9038-7f8000f58d6a" readonly="readonly" class="w-100 form-control " style="background-color:transparent" type="text" step="any" value="" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="testingProgram.testRenderOverridedSimpleStruct.Test String" />

<div class="invalid-feedback"></div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div name="testingProgram-testRenderOverridedTag" b-gswuladdww>
<div name="testingProgram-testRenderOverridedTag" class="w-100 form-group mb-2">
<label for:ignore="testingProgram.testRenderOverridedTag_97c217f7-ac06-4d99-83b6-e7fede582d01">testRenderOverridedTag</label>
<input id:ignore="testingProgram.testRenderOverridedTag_97c217f7-ac06-4d99-83b6-e7fede582d01" readonly="readonly" class="w-100 form-control " style="background-color:transparent" type="text" step="any" value="0" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="testingProgram.testRenderOverridedTag" />

<div class="invalid-feedback"></div>
</div>
</div>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,21 @@ public void Render_stTestLayouts_Border_UniformGrid_Successfull()
//}

[Fact]
public void Render_stTestRenderTemplateOverrideAttributeStruct_Success()
public void Render_stTestRenderOverridedSimpleStruct_Success()
{
Compare("stTestRenderTemplateOverrideStruct.html", _fixture.Connector.testingProgram.testRenderTemplateOverrideStruct, "Display");
Compare("stTestRenderOverridedSimpleStruct.html", _fixture.Connector.testingProgram.testRenderOverridedSimpleStruct, "Display");
}

[Fact]
public void Render_stTestRenderTemplateOverrideAttributeTag_Success()
public void Render_stTestRenderInnerOverridedStruct_Success()
{
Compare("stTestRenderTemplateOverrideTag.html", _fixture.Connector.testingProgram.testRenderTemplateOverrideTag, "Display");
Compare("stTestRenderInnerOverridedStruct.html", _fixture.Connector.testingProgram.testRenderInnerOverridedStruct, "Display");
}

[Fact]
public void Render_stTestRenderOverridedTag_Success()
{
Compare("stTestRenderOverridedTag.html", _fixture.Connector.testingProgram.testRenderOverridedTag, "Display");
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
@using AXSharp.Connector.ValueTypes;

<div class="w-100 form-group">
<div>
<h1>My Simpl ePrimitive Struct Display View</h1>
</div>
<h1>Overrided My Simple Primitive Struct Display View</h1>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
@using AXSharp.Connector.ValueTypes;

<div class="w-100 form-group">
<div>
<h1>tested primitive tag</h1>
</div>
<h1>Overrided My Simple Primitive Tag Display View</h1>
</div>

@code{
@code {

[Parameter]
public ITwinPrimitive Onliner { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@
<div>
<p>------- "TAG Display"--------------</p>
</div>
<RenderableContentControl Presentation="Display" Context="@Entry.Plc.MAINC.OverridedSimpleTag">
</RenderableContentControl>
<RenderableContentControl Presentation="Display" Context="@Entry.Plc.MAINC.OverridedTag" />

<div>
<p>------- "TAG Control"--------------</p>
</div>
<RenderableContentControl Presentation="Control" Context="@Entry.Plc.MAINC.OverridedSimpleTag">
</RenderableContentControl>
<RenderableContentControl Presentation="Control" Context="@Entry.Plc.MAINC.OverridedTag" />

<div>
<p>------- "STRUCT Display"--------------</p>
</div>
<RenderableContentControl Presentation="Display" Context="@Entry.Plc.MAINC.OverridedSimpleStruct">
</RenderableContentControl>
<RenderableContentControl Presentation="Display" Context="@Entry.Plc.MAINC.OverridedSimpleStruct" />

<div>
<p>------- "STRUCT Control"--------------</p>
</div>
<RenderableContentControl Presentation="Control" Context="@Entry.Plc.MAINC.OverridedSimpleStruct">
</RenderableContentControl>
<RenderableContentControl Presentation="Control" Context="@Entry.Plc.MAINC.OverridedSimpleStruct" />

<div>
<p>------- "INNER STRUCT Display"--------------</p>
</div>
<RenderableContentControl Presentation="Display" Context="@Entry.Plc.MAINC.InnerOverridedStruct" />

<div>
<p>------- "INNER STRUCT Control"--------------</p>
</div>
<RenderableContentControl Presentation="Control" Context="@Entry.Plc.MAINC.InnerOverridedStruct" />
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ CLASS MAIN
{#ix-attr:[RenderTemplateOverride("ixBlazor.App.Custom.MySimplePrimitiveStruct")]}
OverridedSimpleStruct : stSimplePrimitive;

InnerOverridedStruct : stRenderTemplateOverride;

{#ix-attr:[RenderTemplateOverride("ixBlazor.App.Custom.MySimplePrimitiveTag")]}
OverridedSimpleTag : WORD;
OverridedTag : WORD;

END_VAR

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{S7.extern=ReadWrite}
CLASS stRenderTemplateOverride
VAR PUBLIC
{#ix-set:AttributeName = "<#Test Integer#>"}
testInteger : INT;
{#ix-attr:[RenderTemplateOverrideAttribute("ixBlazor.App.Custom.MySimplePrimitiveTag")]}
{#ix-set:AttributeName = "<#Test String#>"}
testString : STRING;
END_VAR
END_CLASS
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ CLASS testingProgram
testLayouts : stTestLayouts;

{#ix-attr:[RenderTemplateOverride("ixBlazor.App.Custom.MySimplePrimitiveStruct")]}
testRenderTemplateOverrideStruct : stSimplePrimitive;
testRenderOverridedSimpleStruct : stSimplePrimitive;

testRenderInnerOverridedStruct : stRenderTemplateOverride;

{#ix-attr:[RenderTemplateOverride("ixBlazor.App.Custom.MySimplePrimitiveTag")]}
testRenderTemplateOverrideTag : WORD;
testRenderOverridedTag : WORD;
END_VAR

END_CLASS

0 comments on commit 3152490

Please sign in to comment.