From d744b94c28b6bdd2fcca44a0acea88ae3c3ba284 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Tue, 20 Oct 2020 16:00:55 +0200 Subject: [PATCH] fixes for modules --- zero.Core/Api/ModulesApi.cs | 18 +++++--- zero.Core/Entities/Modules/ModuleType.cs | 6 +++ zero.Core/Options/ModuleOptions.cs | 6 ++- zero.Debug/TestData/TestPlugin.cs | 2 +- .../App/components/modules/edit-module.vue | 7 ++- .../App/components/modules/module-preview.vue | 4 +- .../App/components/modules/modules-select.vue | 6 +-- .../App/components/modules/modules.vue | 19 +++++--- .../pickers/datePicker/datepicker.vue | 12 ++--- .../dateRangePicker/daterangepicker.vue | 20 ++++----- zero.Web.UI/App/core/editor-field.js | 22 ++++++++- zero.Web.UI/App/editor/fields/datepicker.vue | 45 +++++++++++++++++++ .../App/editor/fields/daterangepicker.vue | 41 +++++++++++++---- zero.Web.UI/App/editor/fields/modules.vue | 6 ++- zero.Web.UI/App/resources/modules.js | 4 +- zero.Web/Controllers/ModulesController.cs | 2 +- 16 files changed, 169 insertions(+), 51 deletions(-) create mode 100644 zero.Web.UI/App/editor/fields/datepicker.vue diff --git a/zero.Core/Api/ModulesApi.cs b/zero.Core/Api/ModulesApi.cs index 7d4ad71c..64e09b10 100644 --- a/zero.Core/Api/ModulesApi.cs +++ b/zero.Core/Api/ModulesApi.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using zero.Core.Entities; using zero.Core.Options; @@ -16,9 +17,16 @@ namespace zero.Core.Api /// - public IList GetModuleTypes() + public IList GetModuleTypes(string[] tags = default) { - return Options.Modules.GetAllItems().ToList(); + IEnumerable modules = Options.Modules.GetAllItems(); + + if (tags?.Length > 0) + { + modules = modules.Where(x => x.Tags.Any(t => tags.Contains(t, StringComparer.InvariantCultureIgnoreCase))); + } + + return modules.ToList(); } @@ -33,9 +41,9 @@ namespace zero.Core.Api public interface IModulesApi { /// - /// Get all available module types + /// Get all available module types (can be limited to the passed tags) /// - IList GetModuleTypes(); + IList GetModuleTypes(string[] tags = default); /// /// Get a specific module type by alias diff --git a/zero.Core/Entities/Modules/ModuleType.cs b/zero.Core/Entities/Modules/ModuleType.cs index 5dd54458..0f2cd5c8 100644 --- a/zero.Core/Entities/Modules/ModuleType.cs +++ b/zero.Core/Entities/Modules/ModuleType.cs @@ -47,6 +47,11 @@ namespace zero.Core.Entities /// public string Group { get; set; } + /// + /// Defining tags for a module type allows you to query for them + /// + public List Tags { get; set; } = new List(); + /// /// Page types where this module type is not allowed. /// This will only work when operating within the page context. @@ -68,6 +73,7 @@ namespace zero.Core.Entities Description = model.Description, Icon = model.Icon, Group = model.Group, + Tags = model.Tags, DisallowedPageTypes = model.DisallowedPageTypes }; } diff --git a/zero.Core/Options/ModuleOptions.cs b/zero.Core/Options/ModuleOptions.cs index 0869ca70..4703d921 100644 --- a/zero.Core/Options/ModuleOptions.cs +++ b/zero.Core/Options/ModuleOptions.cs @@ -18,7 +18,7 @@ namespace zero.Core.Options } - public void Add(string alias, string name, string description, string icon, string group = null, List disallowedPageTypes = null) where T : Module, new() + public void Add(string alias, string name, string description, string icon, string group = null, List tags = null, List disallowedPageTypes = null) where T : Module, new() { Items.Add(new ModuleType(typeof(T)) { @@ -27,12 +27,13 @@ namespace zero.Core.Options Description = description, Icon = icon, Group = group, + Tags = tags ?? new List(), DisallowedPageTypes = disallowedPageTypes ?? new List() }); } - public void Add(Type type, string alias, string name, string description, string icon, string group = null, List disallowedPageTypes = null) + public void Add(Type type, string alias, string name, string description, string icon, string group = null, List tags = null, List disallowedPageTypes = null) { Items.Add(new ModuleType(type) { @@ -41,6 +42,7 @@ namespace zero.Core.Options Description = description, Icon = icon, Group = group, + Tags = tags ?? new List(), DisallowedPageTypes = disallowedPageTypes ?? new List() }); } diff --git a/zero.Debug/TestData/TestPlugin.cs b/zero.Debug/TestData/TestPlugin.cs index 42049a68..6947aad3 100644 --- a/zero.Debug/TestData/TestPlugin.cs +++ b/zero.Debug/TestData/TestPlugin.cs @@ -38,7 +38,7 @@ namespace zero.TestData zero.Modules.Add("richtext", "Richtext", "Simple richtext block editor", "fth-align-left", "Texts"); zero.Modules.Add("headline", "Headline", "Headline with optional subline", "fth-underline", "Texts"); - zero.Modules.Add("textWithImage", "Text with image", "Short textblock with image", "fth-layers", "Texts", new List() { "root" }); + zero.Modules.Add("textWithImage", "Text with image", "Short textblock with image", "fth-layers", "Texts", disallowedPageTypes: new List() { "root" }); zero.Modules.Add("gallery", "Gallery", "Image gallery grid", "fth-image", "Media"); zero.Modules.Add("download", "Downloads", "List containing downloads", "fth-download", "Misc"); zero.Modules.Add("offset", "Offset", "Offset between two modules", "fth-code", "Misc"); diff --git a/zero.Web.UI/App/components/modules/edit-module.vue b/zero.Web.UI/App/components/modules/edit-module.vue index e840b857..d9e9df4b 100644 --- a/zero.Web.UI/App/components/modules/edit-module.vue +++ b/zero.Web.UI/App/components/modules/edit-module.vue @@ -14,7 +14,7 @@
- +
@@ -41,9 +41,14 @@ loading: true, state: 'default', meta: {}, + editor: null, model: {} }), + created() + { + this.editor = this.config.editor; + }, methods: { diff --git a/zero.Web.UI/App/components/modules/module-preview.vue b/zero.Web.UI/App/components/modules/module-preview.vue index 5eda7488..afb5364a 100644 --- a/zero.Web.UI/App/components/modules/module-preview.vue +++ b/zero.Web.UI/App/components/modules/module-preview.vue @@ -1,7 +1,7 @@