diff --git a/zero.Core/Api/ModulesApi.cs b/zero.Core/Api/ModulesApi.cs
index 64e09b10..154d0376 100644
--- a/zero.Core/Api/ModulesApi.cs
+++ b/zero.Core/Api/ModulesApi.cs
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Threading.Tasks;
using zero.Core.Entities;
+using zero.Core.Extensions;
+using zero.Core.Handlers;
using zero.Core.Options;
namespace zero.Core.Api
@@ -10,23 +13,41 @@ namespace zero.Core.Api
{
protected IZeroOptions Options { get; private set; }
- public ModulesApi(IZeroOptions options, IBackofficeStore store) : base(store)
+ protected IHandlerHolder Handler { get; private set; }
+
+ public ModulesApi(IZeroOptions options, IBackofficeStore store, IHandlerHolder handler) : base(store)
{
Options = options;
+ Handler = handler;
}
///
- public IList GetModuleTypes(string[] tags = default)
+ public async Task> GetModuleTypes(string[] tags = default, string pageId = default)
{
- IEnumerable modules = Options.Modules.GetAllItems();
+ IEnumerable types = Options.Modules.GetAllItems();
+ List modules = types.ToList();
+ IPage page = null;
+
+ if (!pageId.IsNullOrEmpty())
+ {
+ page = await GetById(pageId);
+ }
if (tags?.Length > 0)
{
- modules = modules.Where(x => x.Tags.Any(t => tags.Contains(t, StringComparer.InvariantCultureIgnoreCase)));
+ modules = types.Where(x => x.Tags.Any(t => tags.Contains(t, StringComparer.InvariantCultureIgnoreCase))).ToList();
}
- return modules.ToList();
+ IModuleTypeHandler handler = Handler.Get();
+
+ // if there is no registered handler we just allow all page types
+ if (handler == null)
+ {
+ return modules;
+ }
+
+ return handler.GetAllowedModuleTypes(Backoffice.Context.Application, types, page, tags)?.ToList() ?? new();
}
@@ -43,7 +64,7 @@ namespace zero.Core.Api
///
/// Get all available module types (can be limited to the passed tags)
///
- IList GetModuleTypes(string[] tags = default);
+ Task> GetModuleTypes(string[] tags = default, string pageId = default);
///
/// Get a specific module type by alias
diff --git a/zero.Core/Api/PagesApi.cs b/zero.Core/Api/PagesApi.cs
index 1b3ad61a..c6d5ba23 100644
--- a/zero.Core/Api/PagesApi.cs
+++ b/zero.Core/Api/PagesApi.cs
@@ -118,7 +118,6 @@ namespace zero.Core.Api
return types.ToList();
}
-
return handler.GetAllowedPageTypes(Backoffice.Context.Application, types, parents)?.ToList() ?? new();
}
diff --git a/zero.Core/Handlers/IModuleTypeHandler.cs b/zero.Core/Handlers/IModuleTypeHandler.cs
new file mode 100644
index 00000000..76759f6d
--- /dev/null
+++ b/zero.Core/Handlers/IModuleTypeHandler.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using zero.Core.Entities;
+
+namespace zero.Core.Handlers
+{
+ public interface IModuleTypeHandler : IHandler
+ {
+ IEnumerable GetAllowedModuleTypes(IApplication application, IEnumerable registeredTypes, IPage page = default, string[] tags = default);
+ }
+}
diff --git a/zero.Web.UI/App/components/header-bar.vue b/zero.Web.UI/App/components/header-bar.vue
index d300bfb2..d2a854f5 100644
--- a/zero.Web.UI/App/components/header-bar.vue
+++ b/zero.Web.UI/App/components/header-bar.vue
@@ -2,7 +2,7 @@