tryhard
This commit is contained in:
@@ -1,26 +1,25 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core.Options;
|
||||
|
||||
namespace zero.Core.Plugins
|
||||
{
|
||||
public abstract class ZeroPlugin
|
||||
public abstract class ZeroPlugin : IZeroPlugin
|
||||
{
|
||||
public string Name { get; protected set; }
|
||||
public IZeroPluginOptions Options { get; } = new ZeroPluginOptions();
|
||||
|
||||
public string Description { get; set; }
|
||||
public virtual void ConfigureServices(IServiceCollection services, IConfiguration configuration) { }
|
||||
|
||||
public virtual void ConfigureServices(IServiceCollection services) { }
|
||||
|
||||
public virtual void Configure(IZeroPluginOptions plugin, IZeroOptions zero) { }
|
||||
public virtual void Configure(IZeroOptions zero) { }
|
||||
}
|
||||
|
||||
|
||||
public interface IZeroPlugin
|
||||
{
|
||||
IZeroPluginOptions Options { get; }
|
||||
|
||||
void ConfigureServices(IServiceCollection services, IConfiguration configuration);
|
||||
|
||||
void Configure(IZeroPluginOptions plugin, IZeroOptions zero);
|
||||
void Configure(IZeroOptions zero);
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,24 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Collections.Generic;
|
||||
using zero.Commerce.Options;
|
||||
using zero.Core.Extensions;
|
||||
using zero.Core.Messages;
|
||||
using zero.Core.Options;
|
||||
using zero.Core.Plugins;
|
||||
using zero.Core.Extensions;
|
||||
using zero.Debug.Sync;
|
||||
using zero.Debug.TestData;
|
||||
using zero.Core.Messages;
|
||||
|
||||
namespace zero.TestData
|
||||
{
|
||||
public class TestPlugin : IZeroPlugin
|
||||
public class TestPlugin : ZeroPlugin
|
||||
{
|
||||
public void Configure(IZeroPluginOptions plugin, IZeroOptions zero)
|
||||
public TestPlugin()
|
||||
{
|
||||
Options.Name = "Test plugin";
|
||||
}
|
||||
|
||||
|
||||
public override void Configure(IZeroOptions zero)
|
||||
{
|
||||
plugin.Name = "Test Plugin";
|
||||
//ISection spaceSection = zero.Sections.GetAllItems().FirstOrDefault(x => x.Alias == Constants.Sections.Spaces);
|
||||
//zero.Sections.Remove(spaceSection);
|
||||
|
||||
@@ -41,7 +45,7 @@ namespace zero.TestData
|
||||
zero.Modules.Add<NestedModule>("nested", "Nested", "Add nested modules", "fth-layers", "Misc");
|
||||
}
|
||||
|
||||
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
||||
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddHostedService<TestPluginStartup>();
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@
|
||||
}
|
||||
|
||||
this.loaded = true;
|
||||
console.info(this.attach);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import routerConfig from '../config/router.config.js'
|
||||
class Zero
|
||||
{
|
||||
static install;
|
||||
static instance;
|
||||
|
||||
config = { ...options };
|
||||
|
||||
@@ -23,6 +24,7 @@ class Zero
|
||||
#lists = [];
|
||||
#routes = [];
|
||||
#router = null;
|
||||
#setupDone = false;
|
||||
|
||||
|
||||
constructor(vue, opts)
|
||||
@@ -76,10 +78,24 @@ class Zero
|
||||
|
||||
//console.info(this.#vue.router);
|
||||
|
||||
this.#setupDone = true;
|
||||
//EventHub.$emit('zero.setup');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Installs a zero plugin by a given path
|
||||
* Each plugin is a superset of a vue (client) plugin and can therefore hook into the vue system
|
||||
*/
|
||||
useByPath(pluginPath)
|
||||
{
|
||||
//const plugin = import('../../../' + pluginPath + '/plugin.js').then(res =>
|
||||
//{
|
||||
// this.use(res.default);
|
||||
//});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Installs a zero plugin
|
||||
* Each plugin is a superset of a vue (client) plugin and can therefore hook into the vue system
|
||||
@@ -94,7 +110,14 @@ class Zero
|
||||
this.#plugins.push(plugin);
|
||||
|
||||
// append routes
|
||||
plugin.routes.forEach(x => this.#routes.push(x));
|
||||
if (this.#setupDone)
|
||||
{
|
||||
this.#router.addRoutes(plugin.routes);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.routes.forEach(x => this.#routes.push(x));
|
||||
}
|
||||
|
||||
// append editors
|
||||
plugin.editors.forEach(x => this.#editors.push(x));
|
||||
@@ -146,16 +169,31 @@ Zero.install = (vue, opts) =>
|
||||
{
|
||||
const zero = new Zero(vue, opts);
|
||||
|
||||
Zero.instance = zero;
|
||||
|
||||
Object.defineProperty(vue.prototype, 'zero', {
|
||||
get: () => zero
|
||||
});
|
||||
|
||||
zero.setup();
|
||||
|
||||
// router mixin
|
||||
Vue.mixin({
|
||||
router: zero.router
|
||||
});
|
||||
|
||||
// add plugins
|
||||
//__zero.plugins.filter(x => !!x.pluginPath).forEach(x =>
|
||||
//{
|
||||
// zero.useByPath(x.pluginPath);
|
||||
//});
|
||||
|
||||
//import('@/../zero.Commerce/Plugins/zero.Commerce/plugin.js').then(res =>
|
||||
//{
|
||||
// zero.use(res.default);
|
||||
//});
|
||||
};
|
||||
|
||||
window.XZERO = Zero;
|
||||
|
||||
export default Zero;
|
||||
@@ -1,3 +1,9 @@
|
||||
|
||||
//console.log(process.env);
|
||||
// TODO
|
||||
// maybe we can make an HTTP request here to get plugin paths and install them
|
||||
// as well as set other fields in config as aliases.
|
||||
|
||||
module.exports = {
|
||||
|
||||
// disable hashes in filenames
|
||||
|
||||
@@ -11,9 +11,34 @@ using zero.Web.Sections;
|
||||
|
||||
namespace zero.Web.Defaults
|
||||
{
|
||||
internal class ZeroBackofficePlugin : IZeroPlugin
|
||||
internal class ZeroBackofficePlugin : ZeroPlugin
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
||||
public ZeroBackofficePlugin()
|
||||
{
|
||||
Options.Name = "zero.Defaults";
|
||||
Options.LocalizationPaths.Add("~/Resources/Localization/zero.{lang}.json");
|
||||
}
|
||||
|
||||
|
||||
public override void Configure(IZeroOptions zero)
|
||||
{
|
||||
zero.Sections.Add<DashboardSection>();
|
||||
zero.Sections.Add<PagesSection>();
|
||||
zero.Sections.Add<SpacesSection>();
|
||||
zero.Sections.Add<MediaSection>();
|
||||
zero.Sections.Add<SettingsSection>();
|
||||
|
||||
zero.Settings.AddGroup<SystemSettings>();
|
||||
//zero.Settings.AddGroup<PluginSettings>();
|
||||
|
||||
zero.Permissions.AddCollection<SectionPermissions>();
|
||||
zero.Permissions.AddCollection<ModulePermissions>();
|
||||
zero.Permissions.AddCollection<SettingsPermissions>();
|
||||
zero.Permissions.AddCollection<SpacePermissions>();
|
||||
}
|
||||
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
//services.AddAll(typeof(IValidator<>), ServiceLifetime.Scoped);
|
||||
//services.AddAll(typeof(IValidator), ServiceLifetime.Scoped);
|
||||
@@ -62,25 +87,5 @@ namespace zero.Web.Defaults
|
||||
services.AddTransient<IModulesApi, ModulesApi>();
|
||||
services.AddTransient<IRecycleBinApi, RecycleBinApi>();
|
||||
}
|
||||
|
||||
public void Configure(IZeroPluginOptions plugin, IZeroOptions zero)
|
||||
{
|
||||
plugin.Name = "zero.Defaults";
|
||||
plugin.LocalizationPaths.Add("~/Resources/Localization/zero.{lang}.json");
|
||||
|
||||
zero.Sections.Add<DashboardSection>();
|
||||
zero.Sections.Add<PagesSection>();
|
||||
zero.Sections.Add<SpacesSection>();
|
||||
zero.Sections.Add<MediaSection>();
|
||||
zero.Sections.Add<SettingsSection>();
|
||||
|
||||
zero.Settings.AddGroup<SystemSettings>();
|
||||
//zero.Settings.AddGroup<PluginSettings>();
|
||||
|
||||
zero.Permissions.AddCollection<SectionPermissions>();
|
||||
zero.Permissions.AddCollection<ModulePermissions>();
|
||||
zero.Permissions.AddCollection<SettingsPermissions>();
|
||||
zero.Permissions.AddCollection<SpacePermissions>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ namespace zero.Web
|
||||
|
||||
plugin.ConfigureServices(Services, Configuration);
|
||||
|
||||
Services.Configure<ZeroOptions>(opts => plugin.Configure(new ZeroPluginOptions(), opts));
|
||||
Services.Configure<ZeroOptions>(opts => plugin.Configure(opts));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
+20
-1
@@ -54,7 +54,7 @@ namespace zero.Web
|
||||
config.ApiPath = config.Path + "api/";
|
||||
config.PluginPath = "@/Plugins";
|
||||
config.Version = Options.ZeroVersion;
|
||||
config.PluginCount = 2; // TODO Plugins.Count();
|
||||
config.PluginCount = Plugins.Count();
|
||||
config.ErrorFieldNone = Constants.ErrorFieldNone;
|
||||
config.Sections = CreateSections();
|
||||
config.Translations = CreateTranslations();
|
||||
@@ -79,6 +79,13 @@ namespace zero.Web
|
||||
};
|
||||
}
|
||||
|
||||
config.Plugins = Plugins.Select(x => new ZeroVuePlugin()
|
||||
{
|
||||
Name = x.Options.Name,
|
||||
Description = x.Options.Description,
|
||||
PluginPath = x.Options.PluginPath
|
||||
}).ToList();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -297,6 +304,8 @@ namespace zero.Web
|
||||
|
||||
public string PluginPath { get; set; }
|
||||
|
||||
public IList<ZeroVuePlugin> Plugins { get; set; } = new List<ZeroVuePlugin>();
|
||||
|
||||
public string Version { get; set; }
|
||||
|
||||
public int PluginCount { get; set; }
|
||||
@@ -339,6 +348,16 @@ namespace zero.Web
|
||||
}
|
||||
|
||||
|
||||
public class ZeroVuePlugin
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string PluginPath { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class ZeroVueSettingsGroup
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user