* feat: add automations plugin * feat: support users views as submenu * fix: reload users collection options on initialization * 表单细节 * 细节更新 * filterable * fix: can not disassociate before destroy data * 暂存 * 表单联动细节 * 补充细节 * 补充测试和细节改进 * 补充细节和测试 * 再来一波更新
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import Database, { registerModels } from '@nocobase/database';
|
|
import Resourcer from '@nocobase/resourcer';
|
|
import path from 'path';
|
|
import { AutomationModel } from './models/automation';
|
|
import { AutomationJobModel } from './models/automation-job';
|
|
|
|
export default async function (options = {}) {
|
|
const database: Database = this.database;
|
|
const resourcer: Resourcer = this.resourcer;
|
|
|
|
registerModels({
|
|
AutomationModel,
|
|
AutomationJobModel,
|
|
});
|
|
|
|
database.import({
|
|
directory: path.resolve(__dirname, 'collections'),
|
|
});
|
|
|
|
const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);
|
|
|
|
Automation.addHook('afterCreate', async (model: AutomationModel) => {
|
|
model.get('enabled') && await model.loadJobs();
|
|
});
|
|
|
|
Automation.addHook('afterUpdate', async (model: AutomationModel) => {
|
|
if (!model.changed('enabled' as any)) {
|
|
return;
|
|
}
|
|
model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();
|
|
});
|
|
|
|
Automation.addHook('beforeDestroy', async (model: AutomationModel) => {
|
|
await model.cancelJobs();
|
|
});
|
|
|
|
AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {
|
|
await model.bootstrap();
|
|
});
|
|
|
|
AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {
|
|
await model.cancel();
|
|
});
|
|
}
|