component rendering optimizations

This commit is contained in:
sbwalker 2024-01-04 13:47:51 -05:00
parent d35ef2d360
commit f75179b2f6
7 changed files with 61 additions and 44 deletions

View File

@ -15,17 +15,20 @@
}
@code {
private string content = "";
private string content = "";
protected override async Task OnParametersSetAsync()
{
try
protected override async Task OnParametersSetAsync()
{
try
{
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
if (PageState.RenderModuleInstance(ModuleState))
{
content = htmltext.Content;
content = Utilities.FormatContent(content, PageState.Alias, "render");
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
{
content = htmltext.Content;
content = Utilities.FormatContent(content, PageState.Alias, "render");
}
}
}
catch (Exception ex)

View File

@ -2,7 +2,7 @@
@namespace Oqtane.UI
@inject SiteState SiteState
@if (_visible)
@if (ComponentType != null && _visible)
{
<a id="@ModuleState.PageModuleId.ToString()"></a>
<CascadingValue Value="@ModuleState">
@ -17,12 +17,11 @@
<DynamicComponent Type="@ComponentType"></DynamicComponent>
}
</CascadingValue>
}
@code {
private bool _visible = true;
private bool _useadminborder = false;
private bool _visible = true;
private bool _useadminborder = false;
public Type ComponentType { get; set; }
[CascadingParameter]
@ -31,12 +30,12 @@
[Parameter]
public Module ModuleState { get; set; }
protected override void OnInitialized()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged;
}
protected override void OnParametersSet()
protected override void OnInitialized()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged;
}
protected override void OnParametersSet()
{
string container = ModuleState.ContainerType;
if (PageState.ModuleId != -1 && PageState.Route.Action != "" && ModuleState.UseAdminContainer)
@ -53,7 +52,10 @@
_useadminborder = false;
}
ComponentType = Type.GetType(container) ?? Type.GetType(Constants.DefaultContainer);
if (PageState.RenderModuleInstance(ModuleState))
{
ComponentType = Type.GetType(container) ?? Type.GetType(Constants.DefaultContainer);
}
}
private void PropertyChanged(object sender, PropertyChangedEventArgs e)
@ -72,6 +74,4 @@
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged;
}
}

View File

@ -5,7 +5,7 @@
@if (CurrentException is null)
{
if (_messagePosition == "top")
if (_message != "" && _messagePosition == "top")
{
<ModuleMessage Message="@_message" Type="@_messageType" />
}
@ -17,7 +17,7 @@
<div class="app-progress-indicator"></div>
}
}
if (_messagePosition == "bottom")
if (_message != "" && _messagePosition == "bottom")
{
<ModuleMessage Message="@_message" Type="@_messageType" />
}
@ -51,24 +51,27 @@ else
protected override void OnParametersSet()
{
_message = "";
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
if (PageState.RenderModuleInstance(ModuleState))
{
ModuleType = Type.GetType(ModuleState.ModuleType);
if (ModuleType != null)
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
{
ModuleParameters = new Dictionary<string, object> { { "ModuleInstance", this } };
return;
ModuleType = Type.GetType(ModuleState.ModuleType);
if (ModuleType != null)
{
ModuleParameters = new Dictionary<string, object> { { "ModuleInstance", this } };
return;
}
// module does not exist with typename specified
_message = string.Format(Localizer["Error.Module.InvalidName"], Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0));
_messageType = MessageType.Error;
_messagePosition = "top";
}
else
{
_message = string.Format(Localizer["Error.Module.InvalidType"], ModuleState.ModuleDefinitionName);
_messageType = MessageType.Error;
_messagePosition = "top";
}
// module does not exist with typename specified
_message = string.Format(Localizer["Error.Module.InvalidName"], Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0));
_messageType = MessageType.Error;
_messagePosition = "top";
}
else
{
_message = string.Format(Localizer["Error.Module.InvalidType"], ModuleState.ModuleDefinitionName);
_messageType = MessageType.Error;
_messagePosition = "top";
}
}

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Oqtane.Models;
namespace Oqtane.UI
@ -38,5 +36,12 @@ namespace Oqtane.UI
{
get { return Site.Languages; }
}
// determines if the PageState matches the ModuleState for component rendering purposes
public bool RenderModuleInstance(Module ModuleState)
{
return Page.PageId == ModuleState.PageId && (ModuleId == -1 || ModuleId == ModuleState.ModuleId) && Action == ModuleState.Action;
}
}
}

View File

@ -95,7 +95,7 @@ else
if (authorized)
{
CreateComponent(builder, module);
CreateComponent(builder, module, module.PageModuleId);
}
}
}
@ -106,7 +106,7 @@ else
// check if user is authorized to view module
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.PermissionList))
{
CreateComponent(builder, module);
CreateComponent(builder, module, -1);
}
}
}
@ -115,11 +115,14 @@ else
};
}
private void CreateComponent(RenderTreeBuilder builder, Module module)
private void CreateComponent(RenderTreeBuilder builder, Module module, int key)
{
builder.OpenComponent(0, Type.GetType(Constants.ContainerComponent));
builder.AddAttribute(1, "ModuleState", module);
builder.SetKey(module.PageModuleId);
if (key != -1)
{
builder.SetKey(module.PageModuleId);
}
builder.CloseComponent();
}
}

View File

@ -508,6 +508,7 @@
}
module.PaneModuleIndex = paneindex[module.Pane.ToLower()];
module.Action = action;
// container fallback
if (string.IsNullOrEmpty(module.ContainerType))

View File

@ -85,6 +85,8 @@ namespace Oqtane.Models
public int PaneModuleIndex { get; set; }
[NotMapped]
public int PaneModuleCount { get; set; }
[NotMapped]
public string Action { get; set; }
#endregion