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

@ -20,6 +20,8 @@
protected override async Task OnParametersSetAsync()
{
try
{
if (PageState.RenderModuleInstance(ModuleState))
{
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
if (htmltext != null)
@ -28,6 +30,7 @@
content = Utilities.FormatContent(content, PageState.Alias, "render");
}
}
}
catch (Exception ex)
{
await logger.LogError(ex, "Error Loading Content {Error}", ex.Message);

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,7 +17,6 @@
<DynamicComponent Type="@ComponentType"></DynamicComponent>
}
</CascadingValue>
}
@code {
@ -53,8 +52,11 @@
_useadminborder = false;
}
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,6 +51,8 @@ else
protected override void OnParametersSet()
{
_message = "";
if (PageState.RenderModuleInstance(ModuleState))
{
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
{
ModuleType = Type.GetType(ModuleState.ModuleType);
@ -71,6 +73,7 @@ else
_messagePosition = "top";
}
}
}
public void AddModuleMessage(string message, MessageType type)
{

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);
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