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 { ResourceManager } from './resource-manager';
import { loadDefaultActions } from './load-default-actions'; import { loadDefaultActions } from './load-default-actions';
import { ICollectionManager } from './types'; import { ICollectionManager } from './types';
import EventEmitter from 'events';
export abstract class DataSource { export abstract class DataSource extends EventEmitter {
public collectionManager: ICollectionManager; public collectionManager: ICollectionManager;
public resourceManager: ResourceManager; public resourceManager: ResourceManager;
public acl: ACL; public acl: ACL;
constructor(protected options: any) { constructor(protected options: any) {
super();
this.acl = this.createACL(); this.acl = this.createACL();
this.resourceManager = this.createResourceManager({ this.resourceManager = this.createResourceManager({

View File

@ -45,8 +45,8 @@ const availableActions: {
}; };
export class DataSourceModel extends Model { export class DataSourceModel extends Model {
async loadIntoApplication(options: { app: Application; transaction?: Transaction }) { async loadIntoApplication(options: { app: Application; transaction?: Transaction; loadAtAfterStart?: boolean }) {
const { app, transaction } = options; const { app, loadAtAfterStart } = options;
const dataSourceKey = this.get('key'); const dataSourceKey = this.get('key');
@ -72,6 +72,12 @@ export class DataSourceModel extends Model {
name: this.get('key'), name: this.get('key'),
}); });
if (loadAtAfterStart) {
dataSource.on('loadMessage', ({ message }) => {
app.setMaintainingMessage(`${message} in data source ${this.get('displayName')}`);
});
}
const acl = dataSource.acl; const acl = dataSource.acl;
for (const [actionName, actionParams] of Object.entries(availableActions)) { 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) => { this.app.on('afterStart', async (app: Application) => {
const dataSourcesRecords: DataSourceModel[] = await this.app.db.getRepository('dataSources').find(); const dataSourcesRecords: DataSourceModel[] = await this.app.db.getRepository('dataSources').find();
for (const dataSourceRecord of dataSourcesRecords) {
dataSourceRecord.loadIntoApplication({ const loadPromises = dataSourcesRecords.map((dataSourceRecord) =>
app, dataSourceRecord.loadIntoApplication({ app, loadAtAfterStart: true }),
}); );
}
this.app.setMaintainingMessage('Loading data sources...');
await Promise.all(loadPromises);
}); });
this.app.db.on('dataSourcesRolesResources.afterSaveWithAssociations', async (model, options) => { this.app.db.on('dataSourcesRolesResources.afterSaveWithAssociations', async (model, options) => {