* fix: add field linkage on setting default datetime * fix: fix dateonly timezone problem * fix: improve test * docs(DatePicker): add demos * fix(DatePicker): should return the beginning of a second * feat(DatePicker): support non-UTC * refactor: rename * fix(RangePicker): get correct end date * test(mapDatePicker): add test * test(mapRangePicker): add test * feat(Filter): use non-UTC to filter * feat(FilterBlock): use non-UTC to filter * feat: add '$dateBetween' operator in datetime * feat: use RangePicker on toggled to 'dateBetween' operator * feat: set ranges for RangePicker * feat: backend support to parse 'dateBetween' operator * fix: fix build error * fix: adaptive content width * feat: support to use var on data scope * feat: add parse-variables plugin * feat: support to parse variables * feat: support only to set system variables * test: rename * feat: cover all * fix: fix build error * feat(RangePicker): extend more shortcut keys * feat(parse-variables): support more date var * feat: support user variables * feat: disable unmatched options * fix: use component name to filter option * fix: fix build error * feat: remove some operator of id * chore: remove useless operators * fix: built in plugin * refactor: move to core from plugin * refactor: remove code of plugin * refactor: remove useless code * fix: should after acl * Update server.ts * fix: compatible with old version * feat: test cases * refactor: rename to 'is between' * refactor: parse filter * fix: improve code * feat: test cases * fix: fix error * fix: improve parse date * fix: date variables * fix: day range * fix: test error * fix: typo * fix: test error * feat: $user variable * fix: toDate * fix: fix the value range of shortcuts * feat: add quarter and test * feat: support to use user's association fields to filter * refactor: use maxDepth * refactor: remove useless code * fix: make AssociationSelect.Designer to support variables * fix: getField * fix: parse utc * fix: remove only * fix: filter by ctx.db.getFieldByPath * fix: avoid error * fix: add translation * fix(RangePicker): can be set to empty * feat(utils): add hasEmptyValue * fix: should not save empty * fix: last few days should include today * fix: limit user variable type to display * fix: parse filter error * fix: empty * test: [skip ci] * fix: remove ';' * feat: improve code --------- Co-authored-by: chenos <chenlinxh@gmail.com>
105 lines
2.9 KiB
TypeScript
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: 'collection-manager',
|
|
directory: path.resolve(__dirname, './migrations'),
|
|
context: {
|
|
plugin: this,
|
|
},
|
|
});
|
|
|
|
await this.importCollections(resolve(__dirname, 'collections'));
|
|
}
|
|
}
|
|
|
|
export default UiSchemaStoragePlugin;
|