diff --git a/Oqtane.Client/Modules/HtmlText/Index.razor b/Oqtane.Client/Modules/HtmlText/Index.razor index 77f7b95d..b02ee9ff 100644 --- a/Oqtane.Client/Modules/HtmlText/Index.razor +++ b/Oqtane.Client/Modules/HtmlText/Index.razor @@ -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) diff --git a/Oqtane.Client/UI/ContainerBuilder.razor b/Oqtane.Client/UI/ContainerBuilder.razor index 15cc7fbc..4d895570 100644 --- a/Oqtane.Client/UI/ContainerBuilder.razor +++ b/Oqtane.Client/UI/ContainerBuilder.razor @@ -2,7 +2,7 @@ @namespace Oqtane.UI @inject SiteState SiteState -@if (_visible) +@if (ComponentType != null && _visible) { @@ -17,12 +17,11 @@ } - } @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; } - - } diff --git a/Oqtane.Client/UI/ModuleInstance.razor b/Oqtane.Client/UI/ModuleInstance.razor index 78ae6d5c..7c45a106 100644 --- a/Oqtane.Client/UI/ModuleInstance.razor +++ b/Oqtane.Client/UI/ModuleInstance.razor @@ -5,7 +5,7 @@ @if (CurrentException is null) { - if (_messagePosition == "top") + if (_message != "" && _messagePosition == "top") { } @@ -17,7 +17,7 @@
} } - if (_messagePosition == "bottom") + if (_message != "" && _messagePosition == "bottom") { } @@ -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 { { "ModuleInstance", this } }; - return; + ModuleType = Type.GetType(ModuleState.ModuleType); + if (ModuleType != null) + { + ModuleParameters = new Dictionary { { "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"; } } diff --git a/Oqtane.Client/UI/PageState.cs b/Oqtane.Client/UI/PageState.cs index ccde8fc2..86c3d5a1 100644 --- a/Oqtane.Client/UI/PageState.cs +++ b/Oqtane.Client/UI/PageState.cs @@ -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; + } } } diff --git a/Oqtane.Client/UI/Pane.razor b/Oqtane.Client/UI/Pane.razor index 1ad17b6f..ed487f24 100644 --- a/Oqtane.Client/UI/Pane.razor +++ b/Oqtane.Client/UI/Pane.razor @@ -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(); } } diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor index 51877aa0..b538afb1 100644 --- a/Oqtane.Client/UI/SiteRouter.razor +++ b/Oqtane.Client/UI/SiteRouter.razor @@ -508,6 +508,7 @@ } module.PaneModuleIndex = paneindex[module.Pane.ToLower()]; + module.Action = action; // container fallback if (string.IsNullOrEmpty(module.ContainerType)) diff --git a/Oqtane.Shared/Models/Module.cs b/Oqtane.Shared/Models/Module.cs index 07c2a507..49c35ded 100644 --- a/Oqtane.Shared/Models/Module.cs +++ b/Oqtane.Shared/Models/Module.cs @@ -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