Files
mixtape/zero.Web.UI/app/core/plugin.ts
T

92 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-10-16 11:23:54 +02:00
class Plugin
{
#name;
#onInstall;
routes = [];
2020-10-18 23:47:59 +02:00
editors = [];
2020-10-19 14:48:21 +02:00
lists = [];
2020-10-16 11:23:54 +02:00
constructor(name)
{
this.#name = name;
}
get name()
{
return this.#name;
}
get install()
{
return this.#onInstall;
}
set install(callback)
{
this.#onInstall = callback;
}
/*
* Add a new vue form renderer to the global configuration
*/
2020-10-18 23:47:59 +02:00
addEditor(config)
2020-10-16 11:23:54 +02:00
{
2020-10-18 23:47:59 +02:00
this.editors.push(config);
2020-10-16 11:23:54 +02:00
}
2020-10-19 14:48:21 +02:00
2020-10-16 11:23:54 +02:00
/*
* Adds new form renderers to the global configuration
* Can either by an array (where a key of the child object is `alias`) or an object where the key is the renderer alias
*/
2020-10-18 23:47:59 +02:00
addEditors(editors)
2020-10-16 11:23:54 +02:00
{
2020-10-18 23:47:59 +02:00
let items = !Array.isArray(editors) ? Object.values(editors) : editors;
items.forEach(item => this.addEditor(item));
2020-10-16 11:23:54 +02:00
}
2020-10-19 14:48:21 +02:00
/*
* Add a new vue list renderer to the global configuration
*/
addList(config)
{
this.lists.push(config);
}
/*
* Adds new list renderers to the global configuration
* Can either by an array (where a key of the child object is `alias`) or an object where the key is the renderer alias
*/
addLists(lists)
{
let items = !Array.isArray(lists) ? Object.values(lists) : lists;
items.forEach(item => this.addList(item));
}
2020-10-16 11:23:54 +02:00
/*
* Add a new route to vue-router
*/
addRoute(route)
{
this.routes.push(route);
}
2020-10-19 14:48:21 +02:00
2020-10-16 11:23:54 +02:00
/*
* Adds new routes to vue-router
*/
addRoutes(routes)
{
2020-10-16 14:02:10 +02:00
routes.forEach(route => this.addRoute(route));
2020-10-16 11:23:54 +02:00
}
};
export default Plugin;