From 8904d8f8f8a79fc1be8b224c24aa55f857dd7f0d Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Tue, 12 May 2020 13:42:01 +0200 Subject: [PATCH] first draft of plugins --- zero.Core/Api/Plugins.cs | 35 ++++++++ zero.Core/Api/SpacesApi.cs | 19 +++-- zero.Core/Entities/Pages/Page.cs | 2 +- zero.Core/Entities/Pages/PageType.cs | 80 +++++++++++++++++++ .../Entities/Pages/PageTypeCollection.cs | 43 ++++++++++ zero.Core/Plugins/ZeroPlugin.cs | 2 + zero.Core/Renderer/IRendererFieldBuilder.cs | 2 + zero.Core/Renderer/Options/RendererOptions.cs | 7 ++ zero.Core/Renderer/RendererFieldBuilder.cs | 13 ++- zero.Debug/Resources/tree-1.debug.json | 46 +++++++++++ zero.Debug/Resources/tree.debug.json | 20 +++++ zero.Debug/Startup.cs | 5 +- zero.Debug/TestData/Pages/ContentPage.cs | 14 ++++ zero.Debug/TestData/Pages/MetaPagePartial.cs | 21 +++++ zero.Debug/TestData/Pages/NewsPage.cs | 12 +++ .../TestData/Pages/OptionsPagePartial.cs | 9 +++ zero.Debug/TestData/Pages/RedirectPage.cs | 12 +++ .../TestData/Renderers/ContentPageRenderer.cs | 37 +++++++++ .../Renderers/MetaPagePartialRenderer.cs | 33 ++++++++ .../TestData/Renderers/NewsPageRenderer.cs | 32 ++++++++ .../Renderers/OptionsPagePartialRenderer.cs | 27 +++++++ .../Renderers/RedirectPageRenderer.cs | 36 +++++++++ zero.Debug/TestData/Test2Plugin.cs | 43 ++++++++++ zero.Web/Controllers/TestController.cs | 9 +++ zero.Web/ZeroBuilder.cs | 6 +- zero.Web/ZeroServiceCollectionExtensions.cs | 2 +- 26 files changed, 554 insertions(+), 13 deletions(-) create mode 100644 zero.Core/Api/Plugins.cs create mode 100644 zero.Core/Entities/Pages/PageType.cs create mode 100644 zero.Core/Entities/Pages/PageTypeCollection.cs create mode 100644 zero.Core/Renderer/Options/RendererOptions.cs create mode 100644 zero.Debug/Resources/tree-1.debug.json create mode 100644 zero.Debug/Resources/tree.debug.json create mode 100644 zero.Debug/TestData/Pages/ContentPage.cs create mode 100644 zero.Debug/TestData/Pages/MetaPagePartial.cs create mode 100644 zero.Debug/TestData/Pages/NewsPage.cs create mode 100644 zero.Debug/TestData/Pages/OptionsPagePartial.cs create mode 100644 zero.Debug/TestData/Pages/RedirectPage.cs create mode 100644 zero.Debug/TestData/Renderers/ContentPageRenderer.cs create mode 100644 zero.Debug/TestData/Renderers/MetaPagePartialRenderer.cs create mode 100644 zero.Debug/TestData/Renderers/NewsPageRenderer.cs create mode 100644 zero.Debug/TestData/Renderers/OptionsPagePartialRenderer.cs create mode 100644 zero.Debug/TestData/Renderers/RedirectPageRenderer.cs create mode 100644 zero.Debug/TestData/Test2Plugin.cs diff --git a/zero.Core/Api/Plugins.cs b/zero.Core/Api/Plugins.cs new file mode 100644 index 00000000..8275824c --- /dev/null +++ b/zero.Core/Api/Plugins.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using zero.Core.Plugins; + +namespace zero.Core.Api +{ + public class Plugins : ZeroPlugin, IPlugins + { + IEnumerable Items; + + + public Plugins(IEnumerable plugins) + { + Items = plugins; + + foreach (ZeroPlugin plugin in plugins) + { + Spaces.AddRange(plugin.Spaces); + Features.AddRange(plugin.Features); + PageTypes.AddRange(plugin.PageTypes); + Permissions.AddRange(plugin.Permissions); + Renderers.AddRange(plugin.Renderers); + Sections.AddRange(plugin.Sections); + } + } + } + + + public interface IPlugins + { + + } +} diff --git a/zero.Core/Api/SpacesApi.cs b/zero.Core/Api/SpacesApi.cs index e0550c57..53477bcd 100644 --- a/zero.Core/Api/SpacesApi.cs +++ b/zero.Core/Api/SpacesApi.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Threading.Tasks; using zero.Core.Entities; using zero.Core.Extensions; +using zero.Core.Plugins; using zero.Core.Renderer; namespace zero.Core.Api @@ -21,26 +22,31 @@ namespace zero.Core.Api protected IZeroOptions Options { get; private set; } + protected IEnumerable Plugins { get; private set; } - public SpacesApi(IDocumentStore raven, IPermissionsApi permissionsApi, IZeroOptions options) + + public SpacesApi(IDocumentStore raven, IPermissionsApi permissionsApi, IZeroOptions options, IEnumerable plugins) { Raven = raven; PermissionsApi = permissionsApi; Options = options; + Plugins = plugins; } /// public Space GetByAlias(string alias) { - return Options.Backoffice.Spaces.FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase)); + return Plugins.SelectMany(x => x.Spaces).FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase)); } /// public SpaceCollection GetAll() { - return Options.Backoffice.Spaces; + var collection = new SpaceCollection(); + collection.AddRange(Plugins.SelectMany(x => x.Spaces)); + return collection; } @@ -54,7 +60,7 @@ namespace zero.Core.Api return null; } - AbstractGenericRenderer renderer = Options.Backoffice.Renderers.FirstOrDefault(x => x.TargetType == space.Type); + AbstractGenericRenderer renderer = Plugins.SelectMany(x => x.Renderers).FirstOrDefault(x => x.TargetType == space.Type); if (renderer == null) { @@ -122,7 +128,10 @@ namespace zero.Core.Api /// public async Task> Save(string alias, T model) where T : SpaceContent { - Space space = Options.Backoffice.Spaces.GetByAlias(alias); + var collection = new SpaceCollection(); + collection.AddRange(Plugins.SelectMany(x => x.Spaces)); + + Space space = collection.GetByAlias(alias); RendererConfig config = GetEditorConfig(alias); if (config.Validator != null) diff --git a/zero.Core/Entities/Pages/Page.cs b/zero.Core/Entities/Pages/Page.cs index 312a53e2..6ad9988f 100644 --- a/zero.Core/Entities/Pages/Page.cs +++ b/zero.Core/Entities/Pages/Page.cs @@ -9,4 +9,4 @@ /// public string AppId { get; set; } } -} +} \ No newline at end of file diff --git a/zero.Core/Entities/Pages/PageType.cs b/zero.Core/Entities/Pages/PageType.cs new file mode 100644 index 00000000..735640ff --- /dev/null +++ b/zero.Core/Entities/Pages/PageType.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; + +namespace zero.Core.Entities +{ + /// + /// A page type holds information about a Page implementation + /// + public class PageType : PageType where T : Page, new() + { + public PageType() : base(typeof(T)) { } + } + + + /// + /// A page type holds information about a Page implementation + /// + public class PageType + { + /// + /// Type of the associated page class + /// + public Type ContentType { get; private set; } + + /// + /// Alias for querying + /// + public string Alias { get; set; } + + /// + /// Name of the page type + /// + public string Name { get; set; } + + /// + /// Optional description + /// + public string Description { get; set; } + + /// + /// Icon of the page type + /// + public string Icon { get; set; } + + /// + /// Whether this page type can be used as a website entry point + /// + public bool AllowAsRoot { get; set; } + + /// + /// Whether all page types can be created as children of this type + /// + public bool AllowAllChildrenTypes { get; set; } + + /// + /// Page types which are allowed as children + /// + public List AllowedChildrenTypes { get; set; } = new List(); + + + public PageType(Type type) + { + ContentType = type; + } + + public static PageType Convert(PageType model) where T : Page, new() + { + return new PageType(model.ContentType) + { + Alias = model.Alias, + Name = model.Name, + Description = model.Description, + Icon = model.Icon, + AllowAllChildrenTypes = model.AllowAllChildrenTypes, + AllowedChildrenTypes = model.AllowedChildrenTypes, + AllowAsRoot = model.AllowAsRoot + }; + } + } +} diff --git a/zero.Core/Entities/Pages/PageTypeCollection.cs b/zero.Core/Entities/Pages/PageTypeCollection.cs new file mode 100644 index 00000000..ddf56868 --- /dev/null +++ b/zero.Core/Entities/Pages/PageTypeCollection.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; + +namespace zero.Core.Entities +{ + public class PageTypeCollection : List + { + public void Add(PageType pageType) where T : Page, new() + { + Add(PageType.Convert(pageType)); + } + + + public void Add(string alias, string name, string description, string icon, bool allowAsRoot = false, bool allowAllChildrenTypes = false, List allowedChildrenTypes = null) where T : Page, new() + { + Add(new PageType(typeof(T)) + { + Alias = alias, + Name = name, + Description = description, + Icon = icon, + AllowAsRoot = allowAsRoot, + AllowAllChildrenTypes = allowAllChildrenTypes, + AllowedChildrenTypes = allowedChildrenTypes + }); + } + + + public void Add(Type type, string alias, string name, string description, string icon, bool allowAsRoot = false, bool allowAllChildrenTypes = false, List allowedChildrenTypes = null) + { + Add(new PageType(type) + { + Alias = alias, + Name = name, + Description = description, + Icon = icon, + AllowAsRoot = allowAsRoot, + AllowAllChildrenTypes = allowAllChildrenTypes, + AllowedChildrenTypes = allowedChildrenTypes + }); + } + } +} diff --git a/zero.Core/Plugins/ZeroPlugin.cs b/zero.Core/Plugins/ZeroPlugin.cs index 4232d7ca..6fd5371a 100644 --- a/zero.Core/Plugins/ZeroPlugin.cs +++ b/zero.Core/Plugins/ZeroPlugin.cs @@ -21,6 +21,8 @@ namespace zero.Core.Plugins public FeatureCollection Features { get; private set; } = new FeatureCollection(); + public PageTypeCollection PageTypes { get; private set; } = new PageTypeCollection(); + public IMapper Mapper { get; private set; } protected virtual IServiceCollection ConfigureServices(IServiceCollection services) diff --git a/zero.Core/Renderer/IRendererFieldBuilder.cs b/zero.Core/Renderer/IRendererFieldBuilder.cs index f2900e19..112dc66b 100644 --- a/zero.Core/Renderer/IRendererFieldBuilder.cs +++ b/zero.Core/Renderer/IRendererFieldBuilder.cs @@ -22,6 +22,8 @@ namespace zero.Core.Renderer void Nested(IRenderer renderer, Action optionsBuilder = null); + void Renderer(IRenderer renderer, Action optionsBuilder = null); + void Custom(string path, Func optionsBuilder = null); } } diff --git a/zero.Core/Renderer/Options/RendererOptions.cs b/zero.Core/Renderer/Options/RendererOptions.cs new file mode 100644 index 00000000..b387dac9 --- /dev/null +++ b/zero.Core/Renderer/Options/RendererOptions.cs @@ -0,0 +1,7 @@ +namespace zero.Core.Renderer +{ + public class RendererOptions : AbstractFieldOptions + { + + } +} diff --git a/zero.Core/Renderer/RendererFieldBuilder.cs b/zero.Core/Renderer/RendererFieldBuilder.cs index e53d486f..9d9e025c 100644 --- a/zero.Core/Renderer/RendererFieldBuilder.cs +++ b/zero.Core/Renderer/RendererFieldBuilder.cs @@ -10,7 +10,7 @@ namespace zero.Core.Renderer object Options = null; - AbstractGenericRenderer Renderer = null; + AbstractGenericRenderer CustomRenderer = null; internal class Data @@ -31,7 +31,7 @@ namespace zero.Core.Renderer View = View, ComponentPath = ComponentPath, Options = Options, - Renderer = Renderer + Renderer = CustomRenderer }; } @@ -64,7 +64,7 @@ namespace zero.Core.Renderer public void Nested(IRenderer renderer, Action optionsBuilder = null) { View = "nested"; - Renderer = renderer.ToGenericRenderer(); + CustomRenderer = renderer.ToGenericRenderer(); Options = BuildOptions(optionsBuilder); } @@ -78,6 +78,13 @@ namespace zero.Core.Renderer View = "rte"; } + public void Renderer(IRenderer renderer, Action optionsBuilder = null) + { + View = "_renderer"; + CustomRenderer = renderer.ToGenericRenderer(); + Options = BuildOptions(optionsBuilder); + } + public void State(Action optionsBuilder = null) { View = "state"; diff --git a/zero.Debug/Resources/tree-1.debug.json b/zero.Debug/Resources/tree-1.debug.json new file mode 100644 index 00000000..1decdf0c --- /dev/null +++ b/zero.Debug/Resources/tree-1.debug.json @@ -0,0 +1,46 @@ +[ + { + "id": "10", + "parentId": "1", + "sort": 0, + "name": "Products", + "icon": "fth-folder", + "hasChildren": false + }, + { + "id": "11", + "parentId": "1", + "sort": 1, + "name": "Checkout", + "icon": "fth-folder", + "hasChildren": false + }, + { + "id": "12", + "parentId": "1", + "sort": 2, + "name": "About us", + "icon": "fth-folder", + "modifier": { + "name": "Redirect", + "icon": "fth-arrow-up-right" + }, + "hasChildren": false + }, + { + "id": "13", + "parentId": "1", + "sort": 3, + "name": "Support", + "icon": "fth-folder", + "hasChildren": true + }, + { + "id": "14", + "parentId": "1", + "sort": 4, + "name": "News", + "icon": "fth-folder", + "hasChildren": false + } +] \ No newline at end of file diff --git a/zero.Debug/Resources/tree.debug.json b/zero.Debug/Resources/tree.debug.json new file mode 100644 index 00000000..8cc32f1b --- /dev/null +++ b/zero.Debug/Resources/tree.debug.json @@ -0,0 +1,20 @@ +[ + { + "id": "1", + "parentId": null, + "sort": 0, + "name": "Home", + "description": "Entry point on the website", + "icon": "fth-home", + "hasChildren": true + }, + { + "id": "recyclebin", + "parentId": null, + "sort": 1000, + "name": "@page.recyclebin.name", + "description": "@page.recyclebin.description", + "icon": "fth-trash", + "hasChildren": false + } +] \ No newline at end of file diff --git a/zero.Debug/Startup.cs b/zero.Debug/Startup.cs index b79868e9..784a06b3 100644 --- a/zero.Debug/Startup.cs +++ b/zero.Debug/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using zero.TestData; using zero.Web; namespace zero.Debug @@ -34,7 +35,9 @@ namespace zero.Debug options.LoginPath = "/Account/Index"; }); - services.AddZero(Configuration); + services.AddZero(Configuration) + .AddPlugin() + .AddPlugin(); services.AddMvc(); services.Configure(opts => opts.AutomaticAuthentication = false); diff --git a/zero.Debug/TestData/Pages/ContentPage.cs b/zero.Debug/TestData/Pages/ContentPage.cs new file mode 100644 index 00000000..a333ef53 --- /dev/null +++ b/zero.Debug/TestData/Pages/ContentPage.cs @@ -0,0 +1,14 @@ +using System; +using zero.Core.Entities; + +namespace zero.TestData +{ + public class ContentPage : Page + { + public MetaPagePartial Meta { get; set; } = new MetaPagePartial(); + + public OptionsPagePartial Options { get; set; } = new OptionsPagePartial(); + + public string Text { get; set; } + } +} diff --git a/zero.Debug/TestData/Pages/MetaPagePartial.cs b/zero.Debug/TestData/Pages/MetaPagePartial.cs new file mode 100644 index 00000000..aa704eaa --- /dev/null +++ b/zero.Debug/TestData/Pages/MetaPagePartial.cs @@ -0,0 +1,21 @@ +using zero.Core.Entities; + +namespace zero.TestData +{ + public class MetaPagePartial + { + public bool HideInTitle { get; set; } + + public string TitleOverride { get; set; } + + public string TitleOverrideAll { get; set; } + + public string SeoDescription { get; set; } + + public Media SeoImage { get; set; } + + public bool NoFollow { get; set; } + + public bool NoIndex { get; set; } + } +} diff --git a/zero.Debug/TestData/Pages/NewsPage.cs b/zero.Debug/TestData/Pages/NewsPage.cs new file mode 100644 index 00000000..a04ec5b1 --- /dev/null +++ b/zero.Debug/TestData/Pages/NewsPage.cs @@ -0,0 +1,12 @@ +using System; +using zero.Core.Entities; + +namespace zero.TestData +{ + public class NewsPage : Page + { + public DateTimeOffset PublishDate { get; set; } + + public string Text { get; set; } + } +} diff --git a/zero.Debug/TestData/Pages/OptionsPagePartial.cs b/zero.Debug/TestData/Pages/OptionsPagePartial.cs new file mode 100644 index 00000000..f4b160e6 --- /dev/null +++ b/zero.Debug/TestData/Pages/OptionsPagePartial.cs @@ -0,0 +1,9 @@ +using zero.Core.Entities; + +namespace zero.TestData +{ + public class OptionsPagePartial + { + public bool HideInNavigation { get; set; } + } +} diff --git a/zero.Debug/TestData/Pages/RedirectPage.cs b/zero.Debug/TestData/Pages/RedirectPage.cs new file mode 100644 index 00000000..6aa380cd --- /dev/null +++ b/zero.Debug/TestData/Pages/RedirectPage.cs @@ -0,0 +1,12 @@ +using System; +using zero.Core.Entities; + +namespace zero.TestData +{ + public class RedirectPage : Page + { + public OptionsPagePartial Options { get; set; } = new OptionsPagePartial(); + + public string Link { get; set; } + } +} diff --git a/zero.Debug/TestData/Renderers/ContentPageRenderer.cs b/zero.Debug/TestData/Renderers/ContentPageRenderer.cs new file mode 100644 index 00000000..cdd6c111 --- /dev/null +++ b/zero.Debug/TestData/Renderers/ContentPageRenderer.cs @@ -0,0 +1,37 @@ +using FluentValidation; +using zero.Core.Renderer; + +namespace zero.TestData +{ + public class ContentPageRenderer : AbstractRenderer + { + public ContentPageRenderer() + { + LabelTemplate = "@_test.fields.{0}"; + DescriptionTemplate = "@_test.fields.{0}_text"; + + Validator = new ContentPageValidator(); + + Field(x => x.Name, required: true).Text(); + + Tab("Options", () => + { + Field(x => x.Options).Renderer(new OptionsPagePartialRenderer()); + }); + + Tab("Meta", () => + { + Field(x => x.Meta).Renderer(new MetaPagePartialRenderer()); + }); + } + } + + + public class ContentPageValidator : AbstractValidator + { + public ContentPageValidator() + { + RuleFor(x => x.Name).NotEmpty().MaximumLength(30); + } + } +} diff --git a/zero.Debug/TestData/Renderers/MetaPagePartialRenderer.cs b/zero.Debug/TestData/Renderers/MetaPagePartialRenderer.cs new file mode 100644 index 00000000..7c2f2823 --- /dev/null +++ b/zero.Debug/TestData/Renderers/MetaPagePartialRenderer.cs @@ -0,0 +1,33 @@ +using FluentValidation; +using zero.Core.Renderer; + +namespace zero.TestData +{ + public class MetaPagePartialRenderer : AbstractRenderer + { + public MetaPagePartialRenderer() + { + LabelTemplate = "@_test.fields.{0}"; + DescriptionTemplate = "@_test.fields.{0}_text"; + + Validator = new MetaPagePartialValidator(); + + Field(x => x.HideInTitle).Toggle(); + Field(x => x.TitleOverride).Text(); + Field(x => x.TitleOverrideAll).Text(); + Field(x => x.SeoDescription).Textarea(opts => opts.MaxLength = 160); + Field(x => x.SeoImage).Media(); + Field(x => x.NoFollow).Toggle(); + Field(x => x.NoIndex).Toggle(); + } + } + + + public class MetaPagePartialValidator : AbstractValidator + { + public MetaPagePartialValidator() + { + RuleFor(x => x.SeoDescription).MaximumLength(160); + } + } +} diff --git a/zero.Debug/TestData/Renderers/NewsPageRenderer.cs b/zero.Debug/TestData/Renderers/NewsPageRenderer.cs new file mode 100644 index 00000000..da4b9578 --- /dev/null +++ b/zero.Debug/TestData/Renderers/NewsPageRenderer.cs @@ -0,0 +1,32 @@ +using FluentValidation; +using System; +using System.Collections.Generic; +using System.Text; +using zero.Core.Renderer; + +namespace zero.TestData +{ + public class NewsPageRenderer : AbstractRenderer + { + public NewsPageRenderer() + { + LabelTemplate = "@_test.fields.{0}"; + DescriptionTemplate = "@_test.fields.{0}_text"; + + Validator = new NewsPageValidator(); + + Field(x => x.Name, required: true).Text(opts => opts.Placeholder = "Enter your name"); + Field(x => x.Text, required: true).Rte(); + } + } + + + public class NewsPageValidator : AbstractValidator + { + public NewsPageValidator() + { + RuleFor(x => x.Name).NotEmpty().MaximumLength(30); + RuleFor(x => x.Text).NotEmpty(); + } + } +} diff --git a/zero.Debug/TestData/Renderers/OptionsPagePartialRenderer.cs b/zero.Debug/TestData/Renderers/OptionsPagePartialRenderer.cs new file mode 100644 index 00000000..406e7e28 --- /dev/null +++ b/zero.Debug/TestData/Renderers/OptionsPagePartialRenderer.cs @@ -0,0 +1,27 @@ +using FluentValidation; +using zero.Core.Renderer; + +namespace zero.TestData +{ + public class OptionsPagePartialRenderer : AbstractRenderer + { + public OptionsPagePartialRenderer() + { + LabelTemplate = "@_test.fields.{0}"; + DescriptionTemplate = "@_test.fields.{0}_text"; + + Validator = new OptionsPagePartialValidator(); + + Field(x => x.HideInNavigation).Toggle(); + } + } + + + public class OptionsPagePartialValidator : AbstractValidator + { + public OptionsPagePartialValidator() + { + + } + } +} diff --git a/zero.Debug/TestData/Renderers/RedirectPageRenderer.cs b/zero.Debug/TestData/Renderers/RedirectPageRenderer.cs new file mode 100644 index 00000000..373fc406 --- /dev/null +++ b/zero.Debug/TestData/Renderers/RedirectPageRenderer.cs @@ -0,0 +1,36 @@ +using FluentValidation; +using System; +using System.Collections.Generic; +using System.Text; +using zero.Core.Renderer; + +namespace zero.TestData +{ + public class RedirectPageRenderer : AbstractRenderer + { + public RedirectPageRenderer() + { + LabelTemplate = "@_test.fields.{0}"; + DescriptionTemplate = "@_test.fields.{0}_text"; + + Validator = new RedirectPageValidator(); + + Field(x => x.Name, required: true).Text(opts => opts.Placeholder = "Enter your name"); + Field(x => x.Link, required: true).Text(); + + Tab("Options", () => + { + Field(x => x.Options).Renderer(new OptionsPagePartialRenderer()); + }); + } + } + + + public class RedirectPageValidator : AbstractValidator + { + public RedirectPageValidator() + { + RuleFor(x => x.Name).NotEmpty().MaximumLength(30); + } + } +} diff --git a/zero.Debug/TestData/Test2Plugin.cs b/zero.Debug/TestData/Test2Plugin.cs new file mode 100644 index 00000000..fd920f16 --- /dev/null +++ b/zero.Debug/TestData/Test2Plugin.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using zero.Core.Entities; +using zero.Core.Plugins; + +namespace zero.TestData +{ + public class Test2Plugin : ZeroPlugin + { + public Test2Plugin() + { + PageTypes.Add(new PageType() + { + Alias = "news", + Name = "News", + Description = "News about the company", + Icon = "fth-book" + }); + + PageTypes.Add(new PageType() + { + Alias = "content", + Name = "Page", + Description = "Page consisting of modules", + AllowAsRoot = true, + AllowAllChildrenTypes = true + }); + + PageTypes.Add(new PageType() + { + Alias = "redirect", + Name = "Redirect", + Description = "Redirect to another page or an external URL", + AllowedChildrenTypes = new List() { "content", "redirect" } + }); + + Renderers.Add(); + Renderers.Add(); + Renderers.Add(); + Renderers.Add(); + Renderers.Add(); + } + } +} diff --git a/zero.Web/Controllers/TestController.cs b/zero.Web/Controllers/TestController.cs index 84b34bde..1b033f26 100644 --- a/zero.Web/Controllers/TestController.cs +++ b/zero.Web/Controllers/TestController.cs @@ -9,6 +9,7 @@ using zero.Core; using zero.Core.Api; using zero.Core.Entities; using zero.Core.Identity; +using zero.Core.Plugins; using zero.Core.Renderer; namespace zero.Web.Controllers @@ -31,6 +32,14 @@ namespace zero.Web.Controllers } + [HttpGet] + [ZeroAuthorize(false)] + public IActionResult GetPlugins([FromServices] IEnumerable plugins) + { + return Json(plugins); + } + + //[HttpGet] //[ZeroAuthorize(false)] //public IActionResult RenderConfig() diff --git a/zero.Web/ZeroBuilder.cs b/zero.Web/ZeroBuilder.cs index e7b12ac5..10d74c21 100644 --- a/zero.Web/ZeroBuilder.cs +++ b/zero.Web/ZeroBuilder.cs @@ -54,6 +54,8 @@ namespace zero.Web ConfigureIdentity(); AddServices(); + + AddPlugin(x => x.GetService().Backoffice); } @@ -267,7 +269,7 @@ namespace zero.Web /// public ZeroBuilder AddPlugin() where T : ZeroPlugin { - Services.AddTransient(); + Services.AddTransient(); return this; } @@ -277,7 +279,7 @@ namespace zero.Web /// public ZeroBuilder AddPlugin(Func implementationFactory) where T : ZeroPlugin { - Services.AddTransient(implementationFactory); + Services.AddTransient(implementationFactory); return this; } } diff --git a/zero.Web/ZeroServiceCollectionExtensions.cs b/zero.Web/ZeroServiceCollectionExtensions.cs index c1fd8551..c953c023 100644 --- a/zero.Web/ZeroServiceCollectionExtensions.cs +++ b/zero.Web/ZeroServiceCollectionExtensions.cs @@ -17,4 +17,4 @@ namespace zero.Web return services.AddZero(configuration).WithOptions(setupAction); } } -} +} \ No newline at end of file