mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 00:36:07 +00:00
8e4336cbe1
* feat: getRepository * getRepository return type * export action * refactor(plugin-acl): plugin * refactor(plugin-action-logs): plugin class * refactor(plugin-china-region): plugin class * refactor: plugin class * fix: cli start command * feat: pass install-command options into app.install * fix: cli args Co-authored-by: chenos <chenlinxh@gmail.com>
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { MagicAttributeModel } from '@nocobase/database';
|
|
import { Plugin } from '@nocobase/server';
|
|
import path from 'path';
|
|
import { uiSchemaActions } from './actions/ui-schema-action';
|
|
import UiSchemaRepository from './repository';
|
|
|
|
export default class PluginUiSchema extends Plugin {
|
|
registerRepository() {
|
|
this.app.db.registerRepositories({
|
|
UiSchemaRepository,
|
|
});
|
|
}
|
|
|
|
async beforeLoad() {
|
|
const db = this.app.db;
|
|
|
|
this.app.db.registerModels({ MagicAttributeModel });
|
|
|
|
this.registerRepository();
|
|
|
|
db.on('ui_schemas.beforeCreate', (model) => {
|
|
model.set('uid', model.get('x-uid'));
|
|
});
|
|
|
|
db.on('ui_schemas.afterCreate', async (model, options) => {
|
|
const { transaction } = options;
|
|
const uiSchemaRepository = db.getCollection('ui_schemas').repository as UiSchemaRepository;
|
|
|
|
await uiSchemaRepository.insert(model.toJSON(), {
|
|
transaction,
|
|
});
|
|
});
|
|
|
|
db.on('ui_schemas.afterUpdate', async (model, options) => {
|
|
const { transaction } = options;
|
|
const uiSchemaRepository = db.getCollection('ui_schemas').repository as UiSchemaRepository;
|
|
|
|
await uiSchemaRepository.patch(model.toJSON(), {
|
|
transaction,
|
|
});
|
|
});
|
|
|
|
this.app.resourcer.define({
|
|
name: 'ui_schemas',
|
|
actions: uiSchemaActions,
|
|
});
|
|
}
|
|
|
|
async load() {
|
|
await this.db.import({
|
|
directory: path.resolve(__dirname, 'collections'),
|
|
});
|
|
}
|
|
}
|