mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 15:37:36 +00:00
Merge branch 'feat/dataSource-manager' of https://github.com/nocobase/nocobase into feat/dataSource-manager
This commit is contained in:
commit
e69a88db17
@ -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({
|
||||
|
@ -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)) {
|
||||
|
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user