2021-07-11 22:20:54 +08:00
|
|
|
import path from 'path';
|
2021-09-23 00:16:04 +08:00
|
|
|
import { PluginOptions } from '@nocobase/server';
|
2021-07-11 22:20:54 +08:00
|
|
|
import { registerModels } from '@nocobase/database';
|
|
|
|
import * as models from './models';
|
2021-07-12 22:13:48 +08:00
|
|
|
import getAccessible from './actions/getAccessible';
|
2021-09-11 18:53:26 +08:00
|
|
|
import * as uiSchema from './ui-schema';
|
2021-07-11 22:20:54 +08:00
|
|
|
|
2021-09-23 00:16:04 +08:00
|
|
|
export default {
|
|
|
|
name: 'ui-router',
|
|
|
|
async load() {
|
|
|
|
const database = this.app.db;
|
|
|
|
registerModels(models);
|
2021-07-11 22:20:54 +08:00
|
|
|
|
2021-09-23 00:16:04 +08:00
|
|
|
database.import({
|
|
|
|
directory: path.resolve(__dirname, 'collections'),
|
|
|
|
});
|
|
|
|
|
|
|
|
this.app.resourcer.registerActionHandler('routes:getAccessible', getAccessible);
|
|
|
|
|
|
|
|
const Route = database.getModel('routes');
|
|
|
|
|
|
|
|
this.app.on('db.init', async () => {
|
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
type: 'redirect',
|
|
|
|
from: '/',
|
|
|
|
to: '/admin',
|
|
|
|
exact: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'route',
|
|
|
|
path: '/admin/:name(.+)?',
|
|
|
|
component: 'AdminLayout',
|
2021-11-08 19:32:59 +08:00
|
|
|
title: `NocoBase`,
|
2021-09-23 00:16:04 +08:00
|
|
|
uiSchema: uiSchema.menu,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'route',
|
|
|
|
component: 'AuthLayout',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
type: 'route',
|
2021-11-08 19:32:59 +08:00
|
|
|
path: '/signin',
|
2021-09-23 00:16:04 +08:00
|
|
|
component: 'RouteSchemaRenderer',
|
2021-11-08 19:32:59 +08:00
|
|
|
title: `{{t("Sign in")}}`,
|
|
|
|
uiSchema: uiSchema.signin,
|
2021-09-23 00:16:04 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'route',
|
2021-11-08 19:32:59 +08:00
|
|
|
path: '/signup',
|
2021-09-23 00:16:04 +08:00
|
|
|
component: 'RouteSchemaRenderer',
|
2021-11-08 19:32:59 +08:00
|
|
|
title: `{{t("Sign up")}}`,
|
|
|
|
uiSchema: uiSchema.signup,
|
2021-09-23 00:16:04 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
for (const item of data) {
|
|
|
|
const route = await Route.create(item);
|
|
|
|
await route.updateAssociations(item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} as PluginOptions;
|