Browse Source

Improvements on Layout Hooks

pull/15486/head
Engincan VESKE 3 years ago
parent
commit
69dca2baa6
  1. 9
      framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Components/LayoutHooks/LayoutHook.razor.cs
  2. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/LayoutHookViewComponent.cs

9
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Components/LayoutHooks/LayoutHook.razor.cs

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@ -26,6 +25,7 @@ public partial class LayoutHook : ComponentBase
if (LayoutHookOptions.Value.Hooks.TryGetValue(Name, out var layoutHooks)) if (LayoutHookOptions.Value.Hooks.TryGetValue(Name, out var layoutHooks))
{ {
layoutHooks = layoutHooks layoutHooks = layoutHooks
.Where(IsComponentBase)
.WhereIf(string.IsNullOrWhiteSpace(Layout), x => x.Layout == Layout) .WhereIf(string.IsNullOrWhiteSpace(Layout), x => x.Layout == Layout)
.ToList(); .ToList();
} }
@ -36,4 +36,9 @@ public partial class LayoutHook : ComponentBase
return Task.CompletedTask; return Task.CompletedTask;
} }
protected virtual bool IsComponentBase(LayoutHookInfo layoutHook)
{
return typeof(ComponentBase).IsAssignableFrom(layoutHook.ComponentType);
}
} }

11
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/LayoutHookViewComponent.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Ui.LayoutHooks; using Volo.Abp.Ui.LayoutHooks;
@ -17,11 +18,17 @@ public class LayoutHookViewComponent : AbpViewComponent
public virtual IViewComponentResult Invoke(string name, string layout) public virtual IViewComponentResult Invoke(string name, string layout)
{ {
var hooks = Options.Hooks.GetOrDefault(name)?.ToArray() ?? Array.Empty<LayoutHookInfo>(); var hooks = Options.Hooks.GetOrDefault(name)?.Where(IsViewComponent).ToArray()
?? Array.Empty<LayoutHookInfo>();
return View( return View(
"~/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/Default.cshtml", "~/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/Default.cshtml",
new LayoutHookViewModel(hooks, layout) new LayoutHookViewModel(hooks, layout)
); );
} }
protected virtual bool IsViewComponent(LayoutHookInfo layoutHook)
{
return typeof(ViewComponent).IsAssignableFrom(layoutHook.ComponentType);
}
} }

Loading…
Cancel
Save