Browse Source
Merge pull request #15486 from abpframework/EngincanV/improve-layout-hooks
Improvements on Layout Hooks
pull/15506/head
Engincan VESKE
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
16 additions and
4 deletions
-
framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Components/LayoutHooks/LayoutHook.razor.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/LayoutHookViewComponent.cs
|
|
|
@ -1,5 +1,4 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Components; |
|
|
|
@ -26,6 +25,7 @@ public partial class LayoutHook : ComponentBase |
|
|
|
if (LayoutHookOptions.Value.Hooks.TryGetValue(Name, out var layoutHooks)) |
|
|
|
{ |
|
|
|
layoutHooks = layoutHooks |
|
|
|
.Where(IsComponentBase) |
|
|
|
.WhereIf(string.IsNullOrWhiteSpace(Layout), x => x.Layout == Layout) |
|
|
|
.ToList(); |
|
|
|
} |
|
|
|
@ -36,4 +36,9 @@ public partial class LayoutHook : ComponentBase |
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual bool IsComponentBase(LayoutHookInfo layoutHook) |
|
|
|
{ |
|
|
|
return typeof(ComponentBase).IsAssignableFrom(layoutHook.ComponentType); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Volo.Abp.Ui.LayoutHooks; |
|
|
|
@ -17,11 +18,17 @@ public class LayoutHookViewComponent : AbpViewComponent |
|
|
|
|
|
|
|
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( |
|
|
|
"~/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/Default.cshtml", |
|
|
|
new LayoutHookViewModel(hooks, layout) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual bool IsViewComponent(LayoutHookInfo layoutHook) |
|
|
|
{ |
|
|
|
return typeof(ViewComponent).IsAssignableFrom(layoutHook.ComponentType); |
|
|
|
} |
|
|
|
} |
|
|
|
|