Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds customized view for rcc that will override locator pattern logic #280

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//try to find complex component (also try predecessors) and generate it
var twin = (ITwinObject)element;
var twinType = twin.GetType();
var component = ViewLocatorBuilder(twinType, twin, Presentation);
var component = ViewLocatorBuilder(twinType, twin, Presentation, PresentationTemplate);
if (component != null)
{
@CreateComplexComponent(twin, component)
Expand Down Expand Up @@ -146,7 +146,7 @@
{
Type mainLayout = null;

var component = ViewLocatorBuilder(twin.GetType(), twin, Presentation);
var component = ViewLocatorBuilder(twin.GetType(), twin, Presentation, PresentationTemplate);
if (component != null)
{
var name = String.IsNullOrEmpty(twin.AttributeName) ? twin.GetSymbolTail() : twin.AttributeName;
Expand Down Expand Up @@ -187,7 +187,7 @@
{
string presentationType = GetDisplayPresentationIfEmpty();
var primitiveKidType = primitiveKid.GetType();
var primitiveComponent = ViewLocatorBuilder(primitiveKidType, primitiveKid, presentationType);
var primitiveComponent = ViewLocatorBuilder(primitiveKidType, primitiveKid, presentationType, PresentationTemplate);
@CreatePrimitiveComponent(primitiveKid, primitiveComponent)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,34 @@ public partial class RenderableContentControl : ComponentBase, IDisposable
/// </summary>
[Parameter] public int PollingInterval { get; set; } = 250;


/// <summary>
/// Gets or sets the presentation template used for displaying data.
/// </summary>
/// <remarks>
/// The presentation template specifies the way the data is formatted and presented to the user.
/// It is a string value that can be assigned using markup syntax or plain text.
/// By default, the presentation template is an empty string. If no presentation template is given
/// the renderer will use the locator pattern to provide the presentation type.
/// </remarks>
/// <value>
/// The presentation template string.
/// </value>
[Parameter]
public string PresentationTemplate
{
get => presentationTemplate;

set
{
if (presentationTemplate != value)
{
presentationTemplate = value;
OnPresentationChanged();
this.ForceRender();
}
}
}

/// <summary>
/// Parameter Context accept ITwinElement instance, which is used as base model for UI generation.
/// </summary>
Expand Down Expand Up @@ -187,8 +214,14 @@ private void UnSubscribeFromPolling()
/// <param name="presentationType">Type of presentation.</param>
/// </summary>

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

if (!string.IsNullOrWhiteSpace(presentationTemplate))
{
return ComponentService.GetComponent(presentationTemplate);
}

var namespc = twinType.Namespace;
//set default namespace if is namespace of primitive types or empty
if (string.IsNullOrEmpty(namespc) || namespc == "AXSharp.Connector.ValueTypes")
Expand All @@ -208,7 +241,7 @@ internal IRenderableComponent ViewLocatorBuilder(Type twinType, ITwinElement twi
if (component == null)
{
//if not found, look at predecessor
component = ViewLocatorBuilder(twinType.BaseType, twin, presentationName);
component = ViewLocatorBuilder(twinType.BaseType, twin, presentationName, PresentationTemplate);
}

if (component != null)
Expand Down Expand Up @@ -269,7 +302,9 @@ private RenderFragment CreateComplexComponent(ITwinObject twin, IRenderableCompo
}
else if (component is IRenderableViewModelBase)
{
__builder.AddAttribute(1, "TwinContainer", new TwinContainerObject(twin, _viewModelCache.CreateCacheId(_navigationManager.Uri, twin.Symbol, Presentation.ToLower())));
__builder.AddAttribute(1, "TwinContainer", new TwinContainerObject(twin,
_viewModelCache.CreateCacheId(_navigationManager.Uri, twin.Symbol,
Presentation.ToLower())));
}
else
{
Expand Down Expand Up @@ -474,6 +509,7 @@ private string GetDisplayPresentationIfEmpty()

private bool shouldRender = false;
private string _presentation;
private string presentationTemplate = null;

protected override bool ShouldRender()
{
Expand Down