component rendering optimizations
This commit is contained in:
parent
d35ef2d360
commit
f75179b2f6
|
@ -15,17 +15,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private string content = "";
|
private string content = "";
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
|
if (PageState.RenderModuleInstance(ModuleState))
|
||||||
if (htmltext != null)
|
|
||||||
{
|
{
|
||||||
content = htmltext.Content;
|
var htmltext = await HtmlTextService.GetHtmlTextAsync(ModuleState.ModuleId);
|
||||||
content = Utilities.FormatContent(content, PageState.Alias, "render");
|
if (htmltext != null)
|
||||||
|
{
|
||||||
|
content = htmltext.Content;
|
||||||
|
content = Utilities.FormatContent(content, PageState.Alias, "render");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
@namespace Oqtane.UI
|
@namespace Oqtane.UI
|
||||||
@inject SiteState SiteState
|
@inject SiteState SiteState
|
||||||
|
|
||||||
@if (_visible)
|
@if (ComponentType != null && _visible)
|
||||||
{
|
{
|
||||||
<a id="@ModuleState.PageModuleId.ToString()"></a>
|
<a id="@ModuleState.PageModuleId.ToString()"></a>
|
||||||
<CascadingValue Value="@ModuleState">
|
<CascadingValue Value="@ModuleState">
|
||||||
|
@ -17,12 +17,11 @@
|
||||||
<DynamicComponent Type="@ComponentType"></DynamicComponent>
|
<DynamicComponent Type="@ComponentType"></DynamicComponent>
|
||||||
}
|
}
|
||||||
</CascadingValue>
|
</CascadingValue>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private bool _visible = true;
|
private bool _visible = true;
|
||||||
private bool _useadminborder = false;
|
private bool _useadminborder = false;
|
||||||
public Type ComponentType { get; set; }
|
public Type ComponentType { get; set; }
|
||||||
|
|
||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
|
@ -31,12 +30,12 @@
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Module ModuleState { get; set; }
|
public Module ModuleState { get; set; }
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged;
|
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
string container = ModuleState.ContainerType;
|
string container = ModuleState.ContainerType;
|
||||||
if (PageState.ModuleId != -1 && PageState.Route.Action != "" && ModuleState.UseAdminContainer)
|
if (PageState.ModuleId != -1 && PageState.Route.Action != "" && ModuleState.UseAdminContainer)
|
||||||
|
@ -53,7 +52,10 @@
|
||||||
_useadminborder = false;
|
_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)
|
private void PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
|
@ -72,6 +74,4 @@
|
||||||
{
|
{
|
||||||
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged;
|
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
@if (CurrentException is null)
|
@if (CurrentException is null)
|
||||||
{
|
{
|
||||||
if (_messagePosition == "top")
|
if (_message != "" && _messagePosition == "top")
|
||||||
{
|
{
|
||||||
<ModuleMessage Message="@_message" Type="@_messageType" />
|
<ModuleMessage Message="@_message" Type="@_messageType" />
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
<div class="app-progress-indicator"></div>
|
<div class="app-progress-indicator"></div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_messagePosition == "bottom")
|
if (_message != "" && _messagePosition == "bottom")
|
||||||
{
|
{
|
||||||
<ModuleMessage Message="@_message" Type="@_messageType" />
|
<ModuleMessage Message="@_message" Type="@_messageType" />
|
||||||
}
|
}
|
||||||
|
@ -51,24 +51,27 @@ else
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
_message = "";
|
_message = "";
|
||||||
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
|
if (PageState.RenderModuleInstance(ModuleState))
|
||||||
{
|
{
|
||||||
ModuleType = Type.GetType(ModuleState.ModuleType);
|
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
|
||||||
if (ModuleType != null)
|
|
||||||
{
|
{
|
||||||
ModuleParameters = new Dictionary<string, object> { { "ModuleInstance", this } };
|
ModuleType = Type.GetType(ModuleState.ModuleType);
|
||||||
return;
|
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";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.UI
|
namespace Oqtane.UI
|
||||||
|
@ -38,5 +36,12 @@ namespace Oqtane.UI
|
||||||
{
|
{
|
||||||
get { return Site.Languages; }
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ else
|
||||||
|
|
||||||
if (authorized)
|
if (authorized)
|
||||||
{
|
{
|
||||||
CreateComponent(builder, module);
|
CreateComponent(builder, module, module.PageModuleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ else
|
||||||
// check if user is authorized to view module
|
// check if user is authorized to view module
|
||||||
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.PermissionList))
|
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.OpenComponent(0, Type.GetType(Constants.ContainerComponent));
|
||||||
builder.AddAttribute(1, "ModuleState", module);
|
builder.AddAttribute(1, "ModuleState", module);
|
||||||
builder.SetKey(module.PageModuleId);
|
if (key != -1)
|
||||||
|
{
|
||||||
|
builder.SetKey(module.PageModuleId);
|
||||||
|
}
|
||||||
builder.CloseComponent();
|
builder.CloseComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,6 +508,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
module.PaneModuleIndex = paneindex[module.Pane.ToLower()];
|
module.PaneModuleIndex = paneindex[module.Pane.ToLower()];
|
||||||
|
module.Action = action;
|
||||||
|
|
||||||
// container fallback
|
// container fallback
|
||||||
if (string.IsNullOrEmpty(module.ContainerType))
|
if (string.IsNullOrEmpty(module.ContainerType))
|
||||||
|
|
|
@ -85,6 +85,8 @@ namespace Oqtane.Models
|
||||||
public int PaneModuleIndex { get; set; }
|
public int PaneModuleIndex { get; set; }
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int PaneModuleCount { get; set; }
|
public int PaneModuleCount { get; set; }
|
||||||
|
[NotMapped]
|
||||||
|
public string Action { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user