final draft of plugin backoffice modification

This commit is contained in:
2020-05-14 13:32:33 +02:00
parent a2c2621d71
commit c4fb8a9450
33 changed files with 192 additions and 353 deletions
+5 -3
View File
@@ -10,7 +10,7 @@ namespace zero.Core.Api
protected IZeroOptions Options { get; set; }
public PermissionsApi (IZeroOptions options)
public PermissionsApi(IZeroOptions options)
{
Options = options;
}
@@ -38,7 +38,9 @@ namespace zero.Core.Api
// TODO add back spaces
if (Options.Backoffice.Spaces.Count > 0)
IReadOnlyCollection<Space> spaces = Options.Spaces.GetAllItems();
if (spaces.Count > 0)
{
PermissionCollection permissionSpaces = new PermissionCollection()
{
@@ -47,7 +49,7 @@ namespace zero.Core.Api
Description = "@permission.collections.spaces_description"
};
foreach (Space space in Options.Backoffice.Spaces)
foreach (Space space in spaces)
{
permissionSpaces.Items.Add(new Permission(Permissions.Spaces.PREFIX + space.Alias, space.Name, null, PermissionValueType.ReadWrite));
}
+7 -6
View File
@@ -1,7 +1,8 @@
using Microsoft.Extensions.Options;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using zero.Core.Entities;
using zero.Core.Options;
namespace zero.Core.Api
{
@@ -17,16 +18,16 @@ namespace zero.Core.Api
/// <inheritdoc />
public SectionCollection GetAll()
public IReadOnlyCollection<ISection> GetAll()
{
return Options.Backoffice.Sections;
return Options.Sections.GetAllItems();
}
/// <inheritdoc />
public ISection GetByAlias(string alias)
{
return Options.Backoffice.Sections.FirstOrDefault(section => section.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase));
return Options.Sections.GetAllItems().FirstOrDefault(section => section.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase));
}
}
@@ -36,7 +37,7 @@ namespace zero.Core.Api
/// <summary>
/// Get all available backoffice sections
/// </summary>
SectionCollection GetAll();
IReadOnlyCollection<ISection> GetAll();
/// <summary>
/// Get backoffice section by alias
+5 -4
View File
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using zero.Core.Entities;
using zero.Core.Options;
namespace zero.Core.Api
{
public class SettingsApi : ISettingsApi
{
protected IZeroOptions Options { get; private set; }
protected IZeroOptions Options { get; set; }
public SettingsApi(IZeroOptions options)
@@ -15,9 +16,9 @@ namespace zero.Core.Api
/// <inheritdoc />
public IList<SettingsGroup> GetAreas()
public IReadOnlyCollection<SettingsGroup> GetAreas()
{
return Options.Backoffice.Settings;
return Options.Settings.GetAllItems();
}
}
@@ -27,6 +28,6 @@ namespace zero.Core.Api
/// <summary>
/// Get settings areas for backoffice display and grouping
/// </summary>
IList<SettingsGroup> GetAreas();
IReadOnlyCollection<SettingsGroup> GetAreas();
}
}
+1
View File
@@ -12,6 +12,7 @@ using System.Threading.Tasks;
using zero.Core.Entities;
using zero.Core.Entities.Setup;
using zero.Core.Identity;
using zero.Core.Options;
using zero.Core.Validation;
+8 -10
View File
@@ -9,6 +9,7 @@ using System.Linq;
using System.Threading.Tasks;
using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Options;
using zero.Core.Plugins;
using zero.Core.Renderer;
@@ -20,31 +21,28 @@ namespace zero.Core.Api
protected IPermissionsApi PermissionsApi { get; private set; }
protected IZeroOptions Options { get; private set; }
protected IZeroPluginConfiguration PluginBuilder { get; private set; }
protected IZeroOptions Options { get; set; }
public SpacesApi(IDocumentStore raven, IPermissionsApi permissionsApi, IZeroOptions options, IZeroPluginConfiguration pluginBuilder)
public SpacesApi(IDocumentStore raven, IPermissionsApi permissionsApi, IZeroOptions options)
{
Raven = raven;
PermissionsApi = permissionsApi;
Options = options;
PluginBuilder = pluginBuilder;
}
/// <inheritdoc />
public Space GetByAlias(string alias)
{
return PluginBuilder.Spaces.FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase));
return Options.Spaces.GetAllItems().FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase));
}
/// <inheritdoc />
public SpaceCollection GetAll()
public IReadOnlyCollection<Space> GetAll()
{
return PluginBuilder.Spaces;
return Options.Spaces.GetAllItems();
}
@@ -58,7 +56,7 @@ namespace zero.Core.Api
return null;
}
AbstractGenericRenderer renderer = PluginBuilder.Renderers.FirstOrDefault(x => x.TargetType == space.Type);
AbstractGenericRenderer renderer = Options.Renderers.GetAllItems().FirstOrDefault(x => x.TargetType == space.Type);
if (renderer == null)
{
@@ -190,7 +188,7 @@ namespace zero.Core.Api
/// <summary>
/// Get all spaces
/// </summary>
SpaceCollection GetAll();
IReadOnlyCollection<Space> GetAll();
/// <summary>
/// Get editor configuration for a space
+1
View File
@@ -4,6 +4,7 @@ using System;
using System.Threading.Tasks;
using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Options;
namespace zero.Core.Api
{
@@ -1,43 +0,0 @@
using System;
using System.Collections.Generic;
namespace zero.Core.Entities
{
public class PageTypeCollection : List<PageType>
{
public void Add<T>(PageType<T> pageType) where T : Page, new()
{
Add(PageType.Convert(pageType));
}
public void Add<T>(string alias, string name, string description, string icon, bool allowAsRoot = false, bool allowAllChildrenTypes = false, List<string> 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<string> allowedChildrenTypes = null)
{
Add(new PageType(type)
{
Alias = alias,
Name = name,
Description = description,
Icon = icon,
AllowAsRoot = allowAsRoot,
AllowAllChildrenTypes = allowAllChildrenTypes,
AllowedChildrenTypes = allowedChildrenTypes
});
}
}
}
@@ -1,88 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace zero.Core.Entities
{
public class SpaceCollection : List<Space>
{
public Space GetByAlias(string alias)
{
return this.FirstOrDefault(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase));
}
public void Add<T>() where T : Space, new()
{
Add(new T());
}
public void AddList<T>(string alias, string name, string description, string icon) where T : SpaceContent, new()
{
Add(new Space()
{
Alias = alias,
View = SpaceView.List,
Name = name,
Description = description,
Icon = icon,
Type = typeof(T)
});
}
public void AddEditor<T>(string alias, string name, string description, string icon) where T : SpaceContent, new()
{
Add(new Space()
{
Alias = alias,
View = SpaceView.Editor,
Name = name,
Description = description,
Icon = icon,
Type = typeof(T)
});
}
public void AddSeparator()
{
Space lastSpace = this.LastOrDefault();
if (lastSpace != null)
{
lastSpace.LineBelow = true;
}
}
public void AddCustom<T>(string componentPath, string alias, string name, string description, string icon) where T : SpaceContent, new()
{
Add(new Space()
{
Alias = alias,
View = SpaceView.Custom,
ComponentPath = componentPath,
Name = name,
Description = description,
Icon = icon,
Type = typeof(T)
});
}
public void AddCustom(string componentPath, string alias, string name, string description, string icon)
{
Add(new Space()
{
Alias = alias,
View = SpaceView.Custom,
ComponentPath = componentPath,
Name = name,
Description = description,
Icon = icon
});
}
}
}
-6
View File
@@ -4,12 +4,6 @@ namespace zero.Core.Options
{
public class FeatureOptions : ZeroBackofficeCollection<IFeature>, IZeroCollectionOptions
{
public FeatureOptions()
{
}
public void Add<T>() where T : IFeature, new()
{
Items.Add(new T());
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace zero.Core.Options
{
public interface IZeroCollectionOptions
{
}
}
@@ -1,11 +1,19 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
namespace zero.Core.Options
{
public abstract class ZeroBackofficeCollection<T>
{
protected IList<T> Items { get; set; } = new List<T>();
protected List<T> Items { get; set; } = new List<T>();
public IReadOnlyCollection<T> GetAllItems()
{
return Items.AsReadOnly();
}
}
}
+72 -2
View File
@@ -11,6 +11,13 @@ namespace zero.Core.Options
DefaultLanguage = SupportedLanguages[0];
TokenExpiration = 60;
BackofficePath = "/zero";
Sections = new SectionOptions();
Features = new FeatureOptions();
Pages = new PageOptions();
Permissions = new PermissionOptions();
Renderers = new RendererOptions();
Settings = new SettingsOptions();
Spaces = new SpaceOptions();
}
/// <inheritdoc />
@@ -32,10 +39,31 @@ namespace zero.Core.Options
public string BackofficePath { get; set; }
/// <inheritdoc />
public IZeroPluginConfiguration Backoffice { get; set; }
//public IZeroPluginConfiguration Backoffice { get; set; }
/// <inheritdoc />
public PluginCollection Plugins { get; set; }
/// <inheritdoc />
public SectionOptions Sections { get; private set; }
/// <inheritdoc />
public FeatureOptions Features { get; private set; }
/// <inheritdoc />
public PageOptions Pages { get; private set; }
/// <inheritdoc />
public PermissionOptions Permissions { get; private set; }
/// <inheritdoc />
public RendererOptions Renderers { get; private set; }
/// <inheritdoc />
public SettingsOptions Settings { get; private set; }
/// <inheritdoc />
public SpaceOptions Spaces { get; private set; }
}
@@ -80,9 +108,51 @@ namespace zero.Core.Options
/// </summary>
string BackofficePath { get; set; }
/// <summary>
///
/// </summary>
PluginCollection Plugins { get; set; }
/// <summary>
///
/// </summary>
SectionOptions Sections { get; }
/// <summary>
///
/// </summary>
FeatureOptions Features { get; }
/// <summary>
///
/// </summary>
PageOptions Pages { get; }
/// <summary>
///
/// </summary>
PermissionOptions Permissions { get; }
/// <summary>
///
/// </summary>
RendererOptions Renderers { get; }
/// <summary>
///
/// </summary>
SettingsOptions Settings { get; }
/// <summary>
///
/// </summary>
SpaceOptions Spaces { get; }
/// <summary>
/// Default settings for the backoffice
/// </summary>
IZeroPluginConfiguration Backoffice { get; set; }
//IZeroPluginConfiguration Backoffice { get; set; }
}
}
+5 -4
View File
@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using zero.Core.Options;
namespace zero.Core.Plugins
{
@@ -7,13 +8,13 @@ namespace zero.Core.Plugins
{
IServiceCollection Services;
IZeroPluginConfiguration Builder;
IZeroOptions Options;
public PluginCollection(IServiceCollection services, IZeroPluginConfiguration builder)
public PluginCollection(IServiceCollection services, IZeroOptions options)
{
Services = services;
Builder = builder;
Options = options;
}
@@ -45,7 +46,7 @@ namespace zero.Core.Plugins
{
try
{
new T().Configure(Services, Builder);
new T().Configure(Services, Options);
}
catch
{
+6 -5
View File
@@ -1,16 +1,17 @@
using Microsoft.Extensions.DependencyInjection;
using zero.Core.Options;
namespace zero.Core.Plugins
{
public abstract class ZeroPlugin : IZeroPlugin
{
public virtual void Configure(IServiceCollection services, IZeroPluginConfiguration zero) { }
//public abstract class ZeroPlugin : IZeroPlugin
//{
// public virtual void Configure(IServiceCollection services, IZeroOptions zero) { }
}
//}
public interface IZeroPlugin
{
void Configure(IServiceCollection services, IZeroPluginConfiguration zero);
void Configure(IServiceCollection services, IZeroOptions zero);
}
}
@@ -1,61 +0,0 @@
using System;
using System.Collections.Generic;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Core.Options;
namespace zero.Core.Plugins
{
public class ZeroPluginConfiguration : IZeroPluginConfiguration
{
public void Configure<T>(Action<T> setupAction) where T : IZeroCollectionOptions
{
setupAction(null); // TODO
}
//public SectionCollection Sections { get; private set; }
//public SpaceOptions Spaces { get; private set; }
//public RendererCollection Renderers { get; private set; }
//public IList<SettingsGroup> Settings { get; private set; }
//public PermissionGroupCollection Permissions { get; private set; }
//public FeatureCollection Features { get; private set; }
//public PageTypeCollection PageTypes { get; private set; }
//public ZeroPluginBuilder()
//{
// Sections = new SectionCollection();
// Spaces = new SpaceOptions();
// Renderers = new RendererCollection();
// Settings = new List<SettingsGroup>();
// Permissions = new PermissionGroupCollection();
// Features = new FeatureCollection();
// PageTypes = new PageTypeCollection();
//}
}
public interface IZeroPluginConfiguration
{
//SectionCollection Sections { get; }
//SpaceOptions Spaces { get; }
//RendererCollection Renderers { get; }
//IList<SettingsGroup> Settings { get; }
//PermissionGroupCollection Permissions { get; }
//FeatureCollection Features { get; }
//PageTypeCollection PageTypes { get; }
void Configure<T>(Action<T> setupAction) where T : IZeroCollectionOptions;
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ namespace zero.Core.Renderer
}
public abstract class AbstractRenderer<T> : IRenderer where T : new()
public abstract class AbstractRenderer<T> : IRenderer<T>, IRenderer where T : new()
{
const string METHOD_FIELD = "field";
+1 -1
View File
@@ -22,7 +22,7 @@ namespace zero.Core.Renderer
void Nested<T>(IRenderer<T> renderer, Action<NestedOptions> optionsBuilder = null);
void Renderer<T>(IRenderer<T> renderer, Action<RendererOptions> optionsBuilder = null);
void Renderer<T>(IRenderer<T> renderer, Action<DefaultRendererOptions> optionsBuilder = null);
void Custom(string path, Func<object> optionsBuilder = null);
}
@@ -0,0 +1,7 @@
namespace zero.Core.Renderer
{
public class DefaultRendererOptions : AbstractFieldOptions
{
}
}
@@ -1,7 +0,0 @@
namespace zero.Core.Renderer
{
public class RendererOptions : AbstractFieldOptions
{
}
}
+1 -1
View File
@@ -78,7 +78,7 @@ namespace zero.Core.Renderer
View = "rte";
}
public void Renderer<T>(IRenderer<T> renderer, Action<RendererOptions> optionsBuilder = null)
public void Renderer<T>(IRenderer<T> renderer, Action<DefaultRendererOptions> optionsBuilder = null)
{
View = "_renderer";
CustomRenderer = renderer.ToGenericRenderer();
-25
View File
@@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using zero.Core.Entities;
using zero.Core.Identity;
namespace zero.Core
{
public class ZeroBackofficeCollection
{
public SectionCollection Sections { get; private set; }
public SpaceCollection Spaces { get; private set; }
public RendererCollection Renderers { get; private set; }
public IList<SettingsGroup> Settings { get; private set; }
public PermissionGroupCollection Permissions { get; private set; }
public FeatureCollection Features { get; private set; }
public PageTypeCollection PageTypes { get; private set; }
}
}
+17 -29
View File
@@ -9,41 +9,29 @@ namespace zero.TestData
{
public class TestPlugin : IZeroPlugin
{
public void Configure(IServiceCollection services, IZeroPluginConfiguration zero)
public void Configure(IServiceCollection services, IZeroOptions zero)
{
services.AddTransient<ITestService, TestService>();
zero.Configure<SpaceOptions>(opts =>
{
opts.AddList<TeamMember>("team", "Team", "Our team members", "fth-users");
opts.AddList<News>("news", "News", "Articles about the company", "fth-edit");
opts.AddSeparator();
opts.AddEditor<SocialContent>("social", "Social", "Links to social media", "fth-twitter");
});
zero.Spaces.AddList<TeamMember>("team", "Team", "Our team members", "fth-users");
zero.Spaces.AddList<News>("news", "News", "Articles about the company", "fth-edit");
zero.Spaces.AddSeparator();
zero.Spaces.AddEditor<SocialContent>("social", "Social", "Links to social media", "fth-twitter");
zero.Configure<FeatureOptions>(opts =>
{
opts.Add(TestFeatures.Wishlist, "Wishlist", "Frontend wishlist for logged-in users");
opts.Add(TestFeatures.SocialShopping, "Social shopping", "Integrate products into social media portals");
});
zero.Features.Add(TestFeatures.Wishlist, "Wishlist", "Frontend wishlist for logged-in users");
zero.Features.Add(TestFeatures.SocialShopping, "Social shopping", "Integrate products into social media portals");
zero.Configure<RendererOptions>(opts =>
{
opts.Add<TeamMemberRenderer>();
opts.Add<SocialContentRenderer>();
opts.Add<OptionsPagePartialRenderer>();
opts.Add<MetaPagePartialRenderer>();
opts.Add<NewsPageRenderer>();
opts.Add<RedirectPageRenderer>();
opts.Add<ContentPageRenderer>();
});
zero.Renderers.Add<TeamMemberRenderer>();
zero.Renderers.Add<SocialContentRenderer>();
zero.Renderers.Add<OptionsPagePartialRenderer>();
zero.Renderers.Add<MetaPagePartialRenderer>();
zero.Renderers.Add<NewsPageRenderer>();
zero.Renderers.Add<RedirectPageRenderer>();
zero.Renderers.Add<ContentPageRenderer>();
zero.Configure<PageOptions>(opts =>
{
opts.Add<NewsPage>("news", "News", "News about the company", "fth-book");
opts.Add<ContentPage>("content", "Page", "Page consisting of modules", "fth-box", true, true);
opts.Add<RedirectPage>("redirect", "Redirect", "Redirect to another page or an external URL", "fth-box", true, false, new List<string>() { "content", "redirect" });
});
zero.Pages.Add<NewsPage>("news", "News", "News about the company", "fth-book");
zero.Pages.Add<ContentPage>("content", "Page", "Page consisting of modules", "fth-box", true, true);
zero.Pages.Add<RedirectPage>("redirect", "Redirect", "Redirect to another page or an external URL", "fth-box", true, false, new List<string>() { "content", "redirect" });
}
}
}
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Core.Options;
using zero.Web.Models;
namespace zero.Web.Controllers
@@ -55,7 +56,7 @@ namespace zero.Web.Controllers
/// </summary>
public IActionResult GetAllFeatures()
{
return Json(Options.Backoffice.Features);
return Json(Options.Features.GetAllItems());
}
@@ -7,6 +7,7 @@ using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Core.Mapper;
using zero.Core.Options;
using zero.Web.Filters;
using zero.Web.Mapper;
using zero.Web.Models;
+3 -2
View File
@@ -9,6 +9,7 @@ using zero.Core;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Core.Options;
using zero.Core.Plugins;
using zero.Core.Renderer;
@@ -34,7 +35,7 @@ namespace zero.Web.Controllers
[HttpGet]
[ZeroAuthorize(false)]
public IActionResult GetPlugins([FromServices] IEnumerable<ZeroPlugin> plugins)
public IActionResult GetPlugins([FromServices] IEnumerable<IZeroPlugin> plugins)
{
return Json(plugins);
}
@@ -103,7 +104,7 @@ namespace zero.Web.Controllers
{
Space space = SpacesApi.GetByAlias(alias);
AbstractGenericRenderer renderer = Options.Backoffice.Renderers.FirstOrDefault(x => x.TargetType == space.Type);
AbstractGenericRenderer renderer = Options.Renderers.GetAllItems().FirstOrDefault(x => x.TargetType == space.Type);
if (renderer == null)
{
+4 -2
View File
@@ -14,14 +14,16 @@ namespace zero.Web.Controllers
IAuthenticationApi AuthenticationApi;
IUserRolesApi RolesApi;
ILanguagesApi LanguagesApi;
IPermissionsApi PermissionsApi;
public UsersController(IUserApi api, IAuthenticationApi authenticationApi, IUserRolesApi rolesApi, ILanguagesApi languagesApi)
public UsersController(IUserApi api, IAuthenticationApi authenticationApi, IUserRolesApi rolesApi, ILanguagesApi languagesApi, IPermissionsApi permissionsApi)
{
Api = api;
AuthenticationApi = authenticationApi;
RolesApi = rolesApi;
LanguagesApi = languagesApi;
PermissionsApi = permissionsApi;
}
@@ -58,7 +60,7 @@ namespace zero.Web.Controllers
/// </summary>
public IActionResult GetAllPermissions()
{
return Json(Options.Backoffice.Permissions);
return Json(PermissionsApi.GetAll());
}
+9 -20
View File
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using zero.Core;
using zero.Core.Options;
using zero.Core.Plugins;
using zero.Web.Sections;
@@ -7,28 +8,16 @@ namespace zero.Web.Defaults
{
public class DefaultBackofficePlugin : IZeroPlugin
{
public void Configure(IServiceCollection services, IZeroPluginConfiguration zero)
public void Configure(IServiceCollection services, IZeroOptions zero)
{
zero.Configure<SectionOptions>(opts =>
{
opts.Add<DashboardSection>();
opts.Add<PagesSection>();
opts.Add<SpacesSection>();
opts.Add<MediaSection>();
opts.Add<SettingsSection>();
});
zero.Sections.Add<DashboardSection>();
zero.Sections.Add<PagesSection>();
zero.Sections.Add<SpacesSection>();
zero.Sections.Add<MediaSection>();
zero.Sections.Add<SettingsSection>();
zero.Configure<SettingsOptions>(opts =>
{
opts.AddGroup<SystemSettings>();
opts.AddGroup<PluginSettings>();
});
zero.Configure<PermissionOptions>(opts =>
{
});
zero.Settings.AddGroup<SystemSettings>();
zero.Settings.AddGroup<PluginSettings>();
}
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
@using zero.Core.Extensions
@inject Microsoft.Extensions.Options.IOptionsMonitor<zero.Core.ZeroOptions> Options
@inject zero.Core.Options.IZeroOptions Options
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
@@ -23,7 +23,7 @@
<div id="application"></div>
<script>
window.zero = window.zero || {};
zero.path = "@Options.CurrentValue.BackofficePath.EnsureEndsWith('/')";
zero.path = "@Options.BackofficePath.EnsureEndsWith('/')";
</script>
<script src="~/Assets/setup.js" asp-append-version="true"></script>
</body>
+2 -1
View File
@@ -6,6 +6,7 @@ using System;
using System.IO;
using zero.Core;
using zero.Core.Extensions;
using zero.Core.Options;
namespace zero.Web
{
@@ -13,7 +14,7 @@ namespace zero.Web
{
public static IApplicationBuilder UseZero(this IApplicationBuilder app)
{
ZeroOptions options = app.ApplicationServices.GetService<IOptionsMonitor<ZeroOptions>>().CurrentValue;
IZeroOptions options = app.ApplicationServices.GetService<IZeroOptions>();
string path = options.BackofficePath.EnsureStartsWith('/').TrimEnd('/');
+12 -16
View File
@@ -18,8 +18,10 @@ using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Identity;
using zero.Core.Mapper;
using zero.Core.Options;
using zero.Core.Plugins;
using zero.Core.Validation;
using zero.Web.Defaults;
using zero.Web.Mapper;
namespace zero.Web
@@ -32,16 +34,12 @@ namespace zero.Web
IConfiguration Configuration { get; set; }
IZeroPluginConfiguration PluginBuilder { get; set; }
public ZeroBuilder(IServiceCollection services, IConfiguration configuration)
{
Services = services;
Configuration = configuration;
PluginBuilder = new ZeroPluginConfiguration();
//CultureInfo cultureInfo = new CultureInfo("en-US");
//cultureInfo.NumberFormat.CurrencySymbol = "€";
//CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
@@ -62,16 +60,16 @@ namespace zero.Web
/// </summary>
void AddConfiguration()
{
Services.Configure<ZeroOptions>(Configuration.GetSection("Zero"));
Services.PostConfigureAll<ZeroOptions>(opts =>
{
opts.ZeroVersion = "0.0.1.0"; // TODO
opts.Plugins = new PluginCollection(Services, PluginBuilder);
opts.Plugins.Add<DefaultBackofficePlugin>();
opts.Backoffice = PluginBuilder;
});
Services.AddOptions<ZeroOptions>()
.Bind(Configuration.GetSection("Zero"))
.Configure(opts =>
{
opts.ZeroVersion = "0.0.1.0"; // TODO
opts.Plugins = new PluginCollection(Services, opts);
opts.Plugins.Add<DefaultBackofficePlugin>();
});
Services.AddTransient<IZeroOptions>(factory => factory.GetService<IOptionsMonitor<ZeroOptions>>().CurrentValue);
Services.AddTransient<IZeroOptions>(factory => factory.GetService<IOptionsMonitor<ZeroOptions>>().CurrentValue);
}
@@ -110,8 +108,6 @@ namespace zero.Web
Services.AddScoped<IPermissionsApi, PermissionsApi>();
Services.AddScoped<IMediaApi, MediaApi>();
Services.AddScoped<IMediaUpload, MediaUpload>();
Services.AddSingleton(PluginBuilder);
}
@@ -265,7 +261,7 @@ namespace zero.Web
/// </summary>
public ZeroBuilder WithOptions(Action<ZeroOptions> configureOptions)
{
Services.PostConfigure(configureOptions);
Services.Configure(configureOptions);
return this;
}
}
+4 -9
View File
@@ -1,21 +1,16 @@
using System;
using System.Net;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using zero.Core;
using zero.Core.Options;
namespace zero.Web
{
public class ZeroMiddleware
{
private RequestDelegate Next { get; set; }
private ZeroOptions Options { get; set; }
private IZeroOptions Options { get; set; }
public ZeroMiddleware(RequestDelegate next, ZeroOptions options)
public ZeroMiddleware(RequestDelegate next, IZeroOptions options)
{
Next = next;
Options = options;
+1 -1
View File
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using zero.Core;
using zero.Core.Options;
namespace zero.Web
{
+4 -2
View File
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.IO;
@@ -13,6 +14,7 @@ using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Identity;
using zero.Core.Mapper;
using zero.Core.Options;
using zero.Web.Models;
using zero.Web.Sections;
@@ -77,7 +79,7 @@ namespace zero.Web
List<ZeroVueSection> sections = new List<ZeroVueSection>();
foreach (ISection section in Options.Backoffice.Sections)
foreach (ISection section in Options.Sections.GetAllItems())
{
if (!isSuperUser && !Permission.CanReadKey(permissions, section.Alias, true))
{
@@ -161,7 +163,7 @@ namespace zero.Web
List<ZeroVueSettingsGroup> groups = new List<ZeroVueSettingsGroup>();
foreach (SettingsGroup group in Options.Backoffice.Settings)
foreach (SettingsGroup group in Options.Settings.GetAllItems())
{
List<ZeroVueSettingsArea> areas = new List<ZeroVueSettingsArea>();