mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
# Conflicts: # packages/core/client/src/flow/components/EllipsisWithTooltip.tsx # packages/core/client/src/flow/components/ExpiresRadio/index.tsx # packages/core/client/src/flow/components/index.tsx # packages/core/client/src/flow/models/data-blocks/form/components/EllipsisWithTooltip.tsx # packages/core/client/src/flow/models/data-blocks/form/components/ExpiresRadio/index.tsx # packages/core/client/src/flow/models/data-blocks/form/components/index.tsx # packages/core/client/src/flow/models/data-blocks/form/fields/AssociationSelectFieldModel/index.tsx # packages/core/client/src/flow/models/data-blocks/form/fields/DateTimeFieldModel/DateTimeFieldModel.tsx # packages/core/client/src/flow/models/data-blocks/form/fields/DateTimeFieldModel/UnixTimestampFieldModel.tsx # packages/core/client/src/flow/models/data-blocks/form/fields/MarkdownFieldModel/index.tsx # packages/core/client/src/flow/models/form/components/EllipsisWithTooltip.tsx # packages/core/client/src/flow/models/form/components/ExpiresRadio/index.tsx # packages/core/client/src/flow/models/form/components/index.tsx
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
/**
|
|
* This file is part of the NocoBase (R) project.
|
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
* Authors: NocoBase Team.
|
|
*
|
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
*/
|
|
|
|
import { DataSource, DataSourceManager, FlowModel } from '@nocobase/flow-engine';
|
|
import _ from 'lodash';
|
|
import { Plugin } from '../application/Plugin';
|
|
import { FlowEngineRunner } from './FlowEngineRunner';
|
|
import { MockFlowModelRepository } from './FlowModelRepository';
|
|
import { FlowRoute } from './FlowPage';
|
|
import * as models from './models';
|
|
import { DateTimeFormat } from './flowSetting/DateTimeFormat';
|
|
|
|
export class PluginFlowEngine extends Plugin {
|
|
async load() {
|
|
this.app.addComponents({ FlowRoute });
|
|
this.app.flowEngine.setModelRepository(new MockFlowModelRepository());
|
|
const filteredModels = Object.fromEntries(
|
|
Object.entries(models).filter(
|
|
([, ModelClass]) => typeof ModelClass === 'function' && ModelClass.prototype instanceof FlowModel,
|
|
),
|
|
);
|
|
console.log('Registering flow models:', Object.keys(filteredModels));
|
|
this.flowEngine.registerModels(filteredModels);
|
|
const dataSourceManager = new DataSourceManager();
|
|
this.flowEngine.context['flowEngine'] = this.flowEngine;
|
|
this.flowEngine.context['app'] = this.app;
|
|
this.flowEngine.context['api'] = this.app.apiClient;
|
|
this.flowEngine.context['dataSourceManager'] = dataSourceManager;
|
|
try {
|
|
const response = await this.app.apiClient.request<any>({
|
|
url: '/collections:listMeta',
|
|
});
|
|
const mainDataSource = new DataSource({
|
|
name: 'main',
|
|
displayName: 'Main',
|
|
});
|
|
dataSourceManager.addDataSource(mainDataSource);
|
|
const collections = response.data?.data || [];
|
|
collections.forEach((collection) => {
|
|
mainDataSource.addCollection(collection);
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to load collections:', error);
|
|
// Optionally, you can throw an error or handle it as needed
|
|
}
|
|
this.app.addProvider(FlowEngineRunner, {});
|
|
|
|
// 注册通用 flow
|
|
this.flowEngine.registerAction(DateTimeFormat);
|
|
}
|
|
}
|
|
|
|
// Export all models for external use
|
|
export * from './models';
|