tachybase_todo/packages/presets/nocobase/src/index.ts
YANG QIA 3aa65cb30c
feat: data visualization (#2160)
* feat(charts-v2): init

* chore(charts-v2): init chart renderer

* feat(chart-v2): add chart grid and initializer

* feat(chart-v2): improve ui

* feat(chart-v2): ui

* feat(charts-v2): query sort ui

* feat(charts-v2): field select component

* feat(charts-v2): improve ui && add query action

* feat(charts-v2): imporve ui, work in progress

* fix(charts-v2): chart renderer request api twice

* feat(charts-v2): add dimension formatter

* feat(charts-v2): filter, sort, limit

* feat(charts-v2): sql mode ui

* feat(charts-v2): support duplicate & sql mode

* fix(charts-v2): wrong defaultValue of json config

* feat(charts-v2): transformer ui

* feat(charts-v2): transformer

* chore(charts-v2): rename transfromer to transform

* feat(charts-v2): support cache

* feat(charts-v2): add acl provider

* chore(charts-v2): hide sql mode

* refactor(charts-v2): add renderer provider

* feat: collection permission check

* feat(charts-v2): add antd statistic

* test(charts-v2): backend

* chore: improve code

* test(charts-v2): add test

* chore: add Chinese translation

* fix(charts-v2): locale switch bug

* chore: add dependency

* feat(charts-v2): init chart config from query

* feat: change layout

* test: fix frontend test

* feat: improve auto infer

* fix: ui issues

* chore: translation

* fix: sql error

* fix: some issues

* feat: support table

* fix: bug

* chore: improve code and fix query

* feat: add config reference

* chore: add translation

* fix: process data due to pg issue

* test: fix parseBuilder

* chore: upgrade formily to 2.2.25

* fix: some issues and import style

* fix: bug when query with sort

* feat: parse enum data

* fix: yarn.lock

* fix: type error

* fix: infer bug and frontend test

* test: fix frontend

* fix: test

* feat: improve preview

* chore: downgrade formily

* feat: support associations, draft, in testing

* fix: typo

* test: frontend & backend

* fix: infer bug

* feat: measure selection of statistics

* fix: bug of group by alias

* fix: some issues

* fix: order issues

* fix: yarn.lock

* chore: fix filter include & 'data-visualization'

* style: improve style

* docs: add readme

* chore: add translation

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
2023-06-30 20:49:44 +08:00

131 lines
3.3 KiB
TypeScript

import { Plugin } from '@nocobase/server';
import _ from 'lodash';
import path from 'path';
export class PresetNocoBase extends Plugin {
builtInPlugins = [
'error-handler',
'collection-manager',
'ui-schema-storage',
'ui-routes-storage',
'file-manager',
'system-settings',
'sequence-field',
'verification',
'users',
'acl',
'china-region',
'workflow',
'client',
'export',
'import',
'audit-logs',
'duplicator',
'iframe-block',
'formula-field',
'charts',
'data-visualization',
'auth',
'sms-auth',
];
localPlugins = [
'sample-hello',
'multi-app-manager',
'multi-app-share-collection',
'oidc',
'saml',
'map',
'snapshot-field',
'graph-collection-manager',
'mobile-client',
'api-keys',
];
splitNames(name: string) {
return (name || '').split(',').filter(Boolean);
}
getBuiltInPlugins() {
const { PRESET_NOCOBASE_PLUGINS, APPEND_PRESET_BUILT_IN_PLUGINS } = process.env;
return _.uniq(
this.splitNames(APPEND_PRESET_BUILT_IN_PLUGINS || PRESET_NOCOBASE_PLUGINS).concat(this.builtInPlugins),
);
}
getLocalPlugins() {
const { APPEND_PRESET_LOCAL_PLUGINS } = process.env;
return _.uniq(this.splitNames(APPEND_PRESET_LOCAL_PLUGINS).concat(this.localPlugins));
}
async addBuiltInPlugins(options?: any) {
const builtInPlugins = this.getBuiltInPlugins();
await this.app.pm.add(builtInPlugins, {
enabled: true,
builtIn: true,
installed: true,
});
const localPlugins = this.getLocalPlugins();
await this.app.pm.add(localPlugins, {});
await this.app.reload({ method: options.method });
}
afterAdd() {
this.app.on('beforeLoad', async (app, options) => {
if (options?.method !== 'upgrade') {
return;
}
const version = await this.app.version.get();
console.log(`The version number before upgrade is ${version}`);
});
this.app.on('beforeUpgrade', async () => {
const result = await this.app.version.satisfies('<0.8.0-alpha.1');
if (result) {
console.log(`Initialize all built-in plugins beforeUpgrade`);
await this.addBuiltInPlugins({ method: 'upgrade' });
}
const builtInPlugins = this.getBuiltInPlugins();
const plugins = await this.app.db.getRepository('applicationPlugins').find();
const pluginNames = plugins.map((p) => p.name);
await this.app.pm.add(
builtInPlugins.filter((plugin) => !pluginNames.includes(plugin)),
{
enabled: true,
builtIn: true,
installed: true,
},
);
const localPlugins = this.getLocalPlugins();
await this.app.pm.add(
localPlugins.filter((plugin) => !pluginNames.includes(plugin)),
{},
);
await this.app.reload({ method: 'upgrade' });
await this.app.db.sync();
await this.app.db.getRepository<any>('collections').load();
});
this.app.on('beforeInstall', async () => {
console.log(`Initialize all built-in plugins beforeInstall in ${this.app.name}`);
await this.addBuiltInPlugins({ method: 'install' });
});
}
beforeLoad() {
this.db.addMigrations({
namespace: this.getName(),
directory: path.resolve(__dirname, './migrations'),
context: {
plugin: this,
},
});
}
}
export default PresetNocoBase;