Merge branch 'feat/dataSource-manager' of https://github.com/nocobase/nocobase into feat/dataSource-manager

This commit is contained in:
dream2023 2024-02-02 10:35:39 +08:00
commit e69a88db17
3 changed files with 19 additions and 8 deletions

View File

@ -4,13 +4,16 @@ import compose from 'koa-compose';
import { ResourceManager } from './resource-manager';
import { loadDefaultActions } from './load-default-actions';
import { ICollectionManager } from './types';
import EventEmitter from 'events';
export abstract class DataSource {
export abstract class DataSource extends EventEmitter {
public collectionManager: ICollectionManager;
public resourceManager: ResourceManager;
public acl: ACL;
constructor(protected options: any) {
super();
this.acl = this.createACL();
this.resourceManager = this.createResourceManager({

View File

@ -45,8 +45,8 @@ const availableActions: {
};
export class DataSourceModel extends Model {
async loadIntoApplication(options: { app: Application; transaction?: Transaction }) {
const { app, transaction } = options;
async loadIntoApplication(options: { app: Application; transaction?: Transaction; loadAtAfterStart?: boolean }) {
const { app, loadAtAfterStart } = options;
const dataSourceKey = this.get('key');
@ -72,6 +72,12 @@ export class DataSourceModel extends Model {
name: this.get('key'),
});
if (loadAtAfterStart) {
dataSource.on('loadMessage', ({ message }) => {
app.setMaintainingMessage(`${message} in data source ${this.get('displayName')}`);
});
}
const acl = dataSource.acl;
for (const [actionName, actionParams] of Object.entries(availableActions)) {

View File

@ -227,11 +227,13 @@ export class PluginDataSourceManagerServer extends Plugin {
this.app.on('afterStart', async (app: Application) => {
const dataSourcesRecords: DataSourceModel[] = await this.app.db.getRepository('dataSources').find();
for (const dataSourceRecord of dataSourcesRecords) {
dataSourceRecord.loadIntoApplication({
app,
});
}
const loadPromises = dataSourcesRecords.map((dataSourceRecord) =>
dataSourceRecord.loadIntoApplication({ app, loadAtAfterStart: true }),
);
this.app.setMaintainingMessage('Loading data sources...');
await Promise.all(loadPromises);
});
this.app.db.on('dataSourcesRolesResources.afterSaveWithAssociations', async (model, options) => {