Skip to content

Commit

Permalink
add properties to access visual parents over rcc
Browse files Browse the repository at this point in the history
  • Loading branch information
PTKu committed Dec 21, 2023
1 parent 4da8d86 commit 735c354
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace AXSharp.Presentation.Blazor.Controls.RenderableContent
/// </summary>
public partial class RenderableComponentBase : ComponentBase, IRenderableComponent, IDisposable
{
/// <summary>
/// Gets or sets the RenderableContentControl that encapsulates this component.
/// </summary>
[Parameter]
public object RccContainer { get; set; } = new Object();

[Parameter] public int PollingInterval { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
@*This class is view part of RenderableContentControl. It contains UI generation pipeline.*@

@*Call rendering method over context object*@
<div name="@_context.Symbol.Replace(".","-")" class="@Class">
@RenderComponent(_context)
</div>
@if (Context != null)
{
<div name="@Context.Symbol.Replace(".", "-")" class="@Class">
@RenderComponent(Context)
</div>
}



@code
{
private RenderFragment RenderComponent(ITwinElement element) => __builder =>
{
if (element == null)
return;

// if it is primitive type, just generate
if (element is ITwinPrimitive)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
using AXSharp.Presentation.Blazor.Exceptions;
using System.Reflection;
using System.ComponentModel;
using System.Globalization;
using AXSharp.Connector.ValueTypes;
using System.Xml.Linq;
using AXSharp.Connector.Localizations;

namespace AXSharp.Presentation.Blazor.Controls.RenderableContent
{
Expand All @@ -42,7 +44,7 @@ public partial class RenderableContentControl : ComponentBase, IDisposable
/// Parameter Context accept ITwinElement instance, which is used as base model for UI generation.
/// </summary>
[Parameter]
public object Context
public ITwinElement Context
{
get => _context;
set
Expand Down Expand Up @@ -83,6 +85,14 @@ public string Presentation
/// </summary>
[Parameter]
public string LayoutClass { get; set; }

/// <summary>
/// Gets or sets parent container containing this renderable content control
/// [!NOTE] This method is used in advanced scenarios it must be set explicitly.
/// </summary>
[Parameter]
public ComponentBase ParentContainer { get; set; }

/// <summary>
/// Parameter LayoutChildrenClass, in which children of layouts will be wrapped.
/// </summary>
Expand All @@ -103,10 +113,7 @@ protected override void OnInitialized()
{
base.OnInitialized();

if(_context is null)
{
throw new ParameterWrongTypeRendererException(Context.GetType().ToString());
}

}

/// <summary>
Expand All @@ -121,15 +128,15 @@ public void ForceRender()

protected override void OnParametersSet()
{
Type layoutType = TryLoadLayoutTypeFromProperty(_context);
Type layoutType = TryLoadLayoutTypeFromProperty(Context);
if (layoutType == null)
{
layoutType = TryLoadLayoutType(_context);
layoutType = TryLoadLayoutType(Context);
}
if (layoutType != null) MainLayoutType = layoutType;

_groupContainer = TryLoadGroupTypeFromProperty(_context);
if (_groupContainer == null) _groupContainer = TryLoadGroupType(_context);
_groupContainer = TryLoadGroupTypeFromProperty(Context);
if (_groupContainer == null) _groupContainer = TryLoadGroupType(Context);

if (String.IsNullOrEmpty(Presentation)) Presentation = "";
_viewModelCache.ResetCounter();
Expand Down Expand Up @@ -189,7 +196,16 @@ internal IRenderableComponent ViewLocatorBuilder(Type twinType, ITwinElement twi
//if not found, look at predecessor
component = ViewLocatorBuilder(twinType.BaseType, twin, presentationName);
}
if (component != null) return component;

if (component != null)
{
if (component is RenderableComponentBase)
{
((RenderableComponentBase)component).RccContainer = this;
}

return component;
}
}
return null;
}
Expand Down Expand Up @@ -224,6 +240,7 @@ private RenderFragment CreatePrimitiveComponent(ITwinPrimitive twinPrimitive, IR
__builder.OpenComponent(1, primitiveComponent.GetType());
__builder.AddAttribute(2, "Onliner", twinPrimitive);
__builder.AddAttribute(3, "IsReadOnly", HasReadAccess(twinPrimitive));
__builder.AddAttribute(1, "RccContainer", this);
__builder.CloseComponent();
};

Expand All @@ -234,6 +251,7 @@ private RenderFragment CreateComplexComponent(ITwinObject twin, IRenderableCompo
if (component is IRenderableComplexComponentBase)
{
__builder.AddAttribute(1, "Component", twin);
__builder.AddAttribute(1, "RccContainer", this);
}
else if (component is IRenderableViewModelBase)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public interface IRenderableComponent
/// </summary>
void RemovePolledElements();


}
}

0 comments on commit 735c354

Please sign in to comment.