tachybase_todo/packages/plugins/ui-schema-storage/src/server.ts
katherinehhh 55efa40cdd
refactor: association field (#1838)
* feat: association field

* fix: bug

* refactor: association field

* style: style improve

* style: style improve

* refactor: support subtable

* refactor: support file collection

* refactor: locale improve

* refactor: subtable improve

* refactor: association select  improve

* refactor: association select  improve

* refactor: association select  improve

* refactor: useAssociationNames

* refactor: enable link

* refactor: selector

* refactor: selector

* refactor: locale improve

* refactor: on demand loading of relational data

* refactor: locale improve

* refactor: select button

* refactor: association field

* refactor: formformBlock provider

* refactor: formformBlock provider

* refactor: internalSelect recordPicker

* refactor: formBlocklockProvider

* fix: addNewer schema

* fix: useServiceOptions

* fix: useCreateActionProps

* fix: useCreateActionProps

* refactor: nester delete

* refactor: nester delete in detail

* refactor: subTable suport select

* refactor: subTable suport select

* style: style improve

* style: style improve

* chore: fileManger

* fix: association readPrety

* fix: filemanger

* refactor: field mode

* refactor: enable link

* chore: error message

* refactor: association schemaInitialize

* refactor: association schemaInitialize

* refactor: currentMode

* refactor: field mode default value

* fix: file manage readPretty

* fix: appends

* chore: file manage readPretty

* fix: updateAssociationValues

* fix: updateAssociationValues

* fix: updateAssociationValues

* fix: nester appends

* fix: nester appends

* fix:  tree collection association fields

* fix:  tree collection association fields

* fix: nester appends

* fix: subtable to select field value missing

* fix: subtable to select field value missing

* fix: compatible with historical blocks

* fix: compatible with historical blocks

* fix: compatible with historical blocks

* feat: add migration

* fix: filter block allow add new

* fix: compatible with historical blocks

* fix: skip if not RecordPicker

* fix: compatible with historical blocks

* fix: detail block not support nester

* fix: association select support data scope and sort setting

* fix: appends on demand loading

* fix: asociationSelect support multiple

* fix: recordPicker -> AssociationField

* fix: add migration

* fix: audit logs not show assication data

* fix: flattenNestedList

* refactor: file manager field mode

* refactor: field mode refactor

* fix: subtable action

* fix: subtable appends

* refactor: code improve

* fix: nester add new

* feat: sub table

* fix: data scope not effect immediately

* fix: association add new

* fix: association field failed to  add new and mutual influence

* style: style improve

* style: style improve

* refactor: updateAssociationValues

* refactor: form init values

* refactor: select options

* fix: form initialValues

* fix: record picker values

* fix: field value change when field mode change

* fix: select data scope

* feat: add migration

* fix: table column enable link

* fix: table column enable link

* refactor: locale improve

* fix: migration

* fix: mutiple config

* fix: readPretty enable link

* fix: appends on demand

* fix: enable link style

* refactor: locale improve

* refactor: locale improve

* feat: sub-form migration

* fix: skip migration

* fix: translation

* fix: skip migration

* fix: getLabelFormatValue

* fix: error TS2339: Property 'find' does not exist on type 'string | SchemaEnum<any>'

* refactor: remove the logic code for converting old record picker

* refactor: locale

* refactor: locale

* fix: sub-table should not support add new

* refactor: code improve

* refactor: locale

* fix: compatibility history Subtable

* fix: improve

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
Co-authored-by: Chareice <chareice@live.com>
2023-05-11 12:47:31 +08:00

105 lines
2.9 KiB
TypeScript

import { MagicAttributeModel } from '@nocobase/database';
import { Plugin } from '@nocobase/server';
import { uid } from '@nocobase/utils';
import path, { resolve } from 'path';
import { uiSchemaActions } from './actions/ui-schema-action';
import { UiSchemaModel } from './model';
import UiSchemaRepository from './repository';
import { ServerHooks } from './server-hooks';
import { ServerHookModel } from './server-hooks/model';
export class UiSchemaStoragePlugin extends Plugin {
serverHooks: ServerHooks;
registerRepository() {
this.app.db.registerRepositories({
UiSchemaRepository,
});
}
async beforeLoad() {
const db = this.app.db;
this.serverHooks = new ServerHooks(db);
this.app.db.registerModels({ MagicAttributeModel, UiSchemaModel, ServerHookModel });
this.registerRepository();
this.app.acl.registerSnippet({
name: `pm.${this.name}.block-templates`,
actions: ['uiSchemaTemplates:*'],
});
this.app.acl.registerSnippet({
name: 'ui.uiSchemas',
actions: [
'uiSchemas:insert',
'uiSchemas:insertNewSchema',
'uiSchemas:remove',
'uiSchemas:patch',
'uiSchemas:batchPatch',
'uiSchemas:clearAncestor',
'uiSchemas:insertBeforeBegin',
'uiSchemas:insertAfterBegin',
'uiSchemas:insertBeforeEnd',
'uiSchemas:insertAfterEnd',
'uiSchemas:insertAdjacent',
'uiSchemas:saveAsTemplate',
],
});
db.on('uiSchemas.beforeCreate', function setUid(model) {
if (!model.get('name')) {
model.set('name', uid());
}
});
db.on('uiSchemas.afterCreate', async function insertSchema(model, options) {
const { transaction } = options;
const uiSchemaRepository = db.getCollection('uiSchemas').repository as UiSchemaRepository;
const context = options.context;
if (context?.disableInsertHook) {
return;
}
await uiSchemaRepository.insert(model.toJSON(), {
transaction,
});
});
db.on('uiSchemas.afterUpdate', async function patchSchema(model, options) {
const { transaction } = options;
const uiSchemaRepository = db.getCollection('uiSchemas').repository as UiSchemaRepository;
await uiSchemaRepository.patch(model.toJSON(), {
transaction,
});
});
this.app.resourcer.define({
name: 'uiSchemas',
actions: uiSchemaActions,
});
this.app.acl.allow('uiSchemas', ['getProperties', 'getJsonSchema'], 'loggedIn');
this.app.acl.allow('uiSchemaTemplates', ['get', 'list'], 'loggedIn');
}
async load() {
this.db.addMigrations({
namespace: 'ui-schema-storage',
directory: path.resolve(__dirname, './migrations'),
context: {
plugin: this,
},
});
await this.importCollections(resolve(__dirname, 'collections'));
}
}
export default UiSchemaStoragePlugin;