mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 20:27:22 +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 { 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({
|
||||||
|
@ -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)) {
|
||||||
|
@ -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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user