tachybase_todo/packages/plugin-ui-routes-storage/src/index.ts
ChengLei Shao 81978711e4
featPlugin multiple apps (#248)
* feat: multiple apps plugin

* feat: multipleAppManager in Application

* stage

* fix: export error

* test: multiple app

* application model

* feat: create application with plugins

* load and install after sub application created

* create subApp database beforeInstall

* sub apps listen to main app start & stop events

* refactor: getPluginName as package name

* feat: load apps on mainApp starts

* fix: test

* feat: beforeGetApplication event

* fix: test

* fix: test with sqlite memory database

* test: lazyLoad application

* fix: test with sqlite memory

* chore: clone database collection & promise.all
2022-03-28 22:01:10 +08:00

104 lines
2.6 KiB
TypeScript

import { skip } from '@nocobase/acl';
import { MagicAttributeModel } from '@nocobase/database';
import { Plugin } from '@nocobase/server';
import { resolve } from 'path';
import { getAccessible } from './actions/getAccessible';
export class UiRoutesStoragePlugin extends Plugin {
getName(): string {
return this.getPackageName(__dirname);
}
async install() {
const repository = this.app.db.getRepository('uiRoutes');
const routes = [
{
type: 'redirect',
from: '/',
to: '/admin',
exact: true,
},
{
type: 'route',
uiSchema: {
type: 'void',
'x-component': 'Menu',
'x-designer': 'Menu.Designer',
'x-initializer': 'MenuItemInitializers',
'x-component-props': {
mode: 'mix',
theme: 'dark',
// defaultSelectedUid: 'u8',
onSelect: '{{ onSelect }}',
sideMenuRefScopeKey: 'sideMenuRef',
},
properties: {},
},
path: '/admin/:name(.+)?',
component: 'AdminLayout',
title: 'NocoBase Admin',
routes: [
// test...
{
type: 'route',
path: '/admin/workflows/:id',
component: 'WorkflowPage',
},
// {
// type: 'route',
// path: '/admin/block-templates/:key',
// component: 'BlockTemplateDetails',
// },
// {
// type: 'route',
// path: '/admin/block-templates',
// component: 'BlockTemplatePage',
// },
{
type: 'route',
path: '/admin/:name(.+)?',
component: 'RouteSchemaComponent',
},
],
},
{
type: 'route',
component: 'AuthLayout',
routes: [
{
type: 'route',
path: '/signin',
component: 'SigninPage',
},
{
type: 'route',
path: '/signup',
component: 'SignupPage',
},
],
},
];
for (const values of routes) {
await repository.create({
values,
});
}
}
async load() {
this.app.resourcer.registerActionHandler('uiRoutes:getAccessible', getAccessible);
this.app.db.registerModels({ MagicAttributeModel });
this.app.db.import({
directory: resolve(__dirname, 'collections'),
});
this.app.acl.use(
skip({
resourceName: 'uiRoutes',
actionName: 'getAccessible',
}),
);
}
}
export default UiRoutesStoragePlugin;