nocobase/packages/plugins/@nocobase/plugin-collection-tree/src/server/plugin.ts

201 lines
7.0 KiB
TypeScript
Raw Normal View History

feat: allows to filter child nodes in tree table blocks (#5096) * feat(database): allows to filter child nodes in tree collections (#4770) * feat(collection-tree): add collection tree plugin * feat(collection-tree): add collection tree path handle function * feat(collection-tree): add collection tree path root and depth column handle function * feat(collection-tree): add exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): add collection tree to build in plugin * feat(collection-tree): modify collection tree plugin version * feat(collection-tree): fix collection tree build bug * feat(collection-tree): fix tree collection path create bug and add tree table search function * feat(collection-tree): add tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table search function * feat(collection-tree): fix tree table search function * feat(collection-tree): improve tree table search filter function * feat(collection-tree): update collection tree plugin version and preset package dependancy * feat(collection-tree): improve tree collection function * feat(collection-tree): remove the duplicate function * feat(collection-tree): fix tree collection db exist bug * feat(collection-tree): improve tree collection db variable name * feat(collection-tree): remove migration file * feat(collection-tree): add collection tree sync create function * feat(collection-tree): add collection tree sync create function * feat(collection-tree): disable collection tree search function * feat(collection-tree): enable collection tree search function * feat(collection-tree): modify collection tree signal to adapt test case * feat(collection-tree): modify code to fix test case * feat(collection-tree): improve code and abstract define collection tree path * feat(collection-tree): modify rootPK to rootPk to avoid underscored behavior * feat(collection-tree): update collection tree version and add collection tree plugin for test * feat(collection-tree): fix filter collection tree root null bug * feat(collection-tree): migrate tree test case to collection tree plugin directory * feat(collection-tree): add transaction for collection tree table delete * feat(collection-tree): fix collection tree switch bug * feat(collection-tree): remove tree filter switch * feat(collection-tree): fix test case * feat(collection-tree): fix test case * feat(collection-tree): fix DB UNDERSCORED bug * feat(collection-tree): fix relate collections not exist bug * feat(collection-tree): add common parent function * feat(collection-tree): add compatible function for sqlite * feat(collection-tree): modify collection tree path create method * feat(collection-tree): migrate tree test case to no acl * feat(collection-tree): migrate tree test case to no acl and fix collections undefined bug * feat(collection-tree): migrate tree test case * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): improve tree search function * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): split the collection tree test to new file and fix filterbytk bug * feat(collection-tree): fix filter tree collection primary key bug * feat(collection-tree): remove recursive test case and fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug and modify test case * feat(collection-tree): add parentid column for tree collection and modify test case * feat(collection-tree): disable sync exist tree collection path table create logic * feat(collection-tree): add sync exist tree collection path table create logic on plugin afterLoad * feat(collection-tree): remove debug code * feat(collection-tree): fix collection tree delete bug * feat(collection-tree): improve collection tree filter find and count implement * feat(collection-tree): improve path table name variable implement * feat(collection-tree): remove unnecessary plugin for test case code * feat(collection-tree): add await for delete synchronous path function * feat(collection-tree): improve tree path create function * feat(collection-tree): remove unnecessary code * feat(collection-tree): remove unnecessary code * feat(collection-tree): improve tree path create function * feat(collection-tree): improve tree filter function * feat(collection-tree): improve tree filter datasource to dynamic * feat(collection-tree): improve find common parent code * feat(collection-tree): add collection tree path table not found warning log * feat(collection-tree): improve get collection primary key implementation * feat(collection-tree): fix tree root path not delete bug and tree path definition bug * feat(collection-tree): fix findAndCount function variable definition bug * feat(collection-tree): modify migrate exist collection tree migration function * feat(collection-tree): correct variable name * feat(collection-tree): remove duplicate code * feat(collection-tree): fix sync exist collection tree path function variable bug * feat(collection-tree): improve collection tree path update logic * feat(collection-tree): remove await for get collection * test: add test cases * feat(collection-tree): modify filter parameter for collection tree * feat(collection-tree): remove await for get collection * feat(collection-tree): remove necessary code * feat(collection-tree): add exist tree collection path migration function * feat(collection-tree): remove unused sync exist tree collection table function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): fix migration rootPk variable bug * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): improve get tree path logic * feat(collection-tree): remove unused test case code * feat(collection-tree): add sync collection tree test case * feat(collection-tree): add tree path test case and fix migration bug * feat(collection-tree): add migration db variable * feat(collection-tree): change logger function * feat(collection-tree): remove unused library * feat(collection-tree): add plugin information * feat(collection-tree): remove await for get collection and use this.db instead of this.app.db * feat(collection-tree): improve the performance of exist data migration to path table * feat(collection-tree): modify get tree path implement to avoid infinite loop bug * feat(collection-tree): fix path create bug * feat(collection-tree): add index for path table * feat(collection-tree): fix related node path bug when some node parent changed * feat(collection-tree): add transaction for get tree path function * feat(collection-tree): add tree path test case * feat(collection-tree): change parent field id name to dynamic * feat(collection-tree): migrate some test case to path.test.ts file * feat(collection-tree): add some test case for path table * feat(collection-tree): fix sqlite and mysql json type search path data bug * feat(collection-tree): fix sqlite query related data sql bug * feat(collection-tree): fix list action test case query data with related data bug * feat(collection-tree): try to fix mysql test case bug to remove index * feat(collection-tree): remove unnecessary code * chore: string field with length option * feat(collection-tree): change path type to string and set max length to 1024 * fix: merge conflicts * feat(collection-tree): modify query path filter to adapt the path change to string * feat(collection-tree): remove append parent condition * feat(collection-tree): split the path test case * feat(collection-tree): remove unused code and fix test case plugin bug * feat(collection-tree): improve get tree path implementation * feat(collection-tree): disable one failed test case for full test * feat(collection-tree): add transaction for collection tree migration * feat(collection-tree): fix collection tree migration bug * feat(collection-tree): remove sqlite handle condition code * feat(collection-tree): add tree test case * feat(collection-tree): add tree test case * feat(collection-tree): modify test case to match the expection * feat(collection-tree): modify tree implementation to root parent * feat(collection-tree): remove unused function * feat(collection-tree): add count function to solve tree data pagination implementation * feat(collection-tree): split tree failed test case to legacy file * feat(collection-tree): correct legacy tree test case to expection * feat(collection-tree): add new tree test for legacy test case to meet expection * feat(collection-tree): fix legacy test case to meet expection * feat(collection-tree): modify legacy test case to meet expection and add new test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): add tree test case * feat(collection-tree): add tree count test case * feat(collection-tree): add tree find and count test case * feat(collection-tree): add tree find one test case * feat(collection-tree): improve migration get path performance * feat(collection-tree): improve get tree path function to avoid undefined parent data situation * feat(collection-tree): add tree and raw parameter variable * fix: test * feat(collection-tree): modify index length * feat(collection-tree): fix index snake case bug * feat(collection-tree): improve tree filter search * feat(collection-tree): fix tree search pagination parameter omit bug * chore: optimize * chore: optimize * fix: build * fix: type * fix: bug * chore: move tree repo to plugin * fix: build * fix: test * chore: remove ts-ignore * fix: issue of getting filter target key --------- Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com> * fix(tree): issue of building tree node map (#5072) --------- Co-authored-by: jimmy201602 <zhengge2012@gmail.com> Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com>
2024-08-21 06:57:01 +00:00
/**
* 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, SequelizeCollectionManager } from '@nocobase/data-source-manager';
import { Collection, DestroyOptions, Model, SyncOptions } from '@nocobase/database';
import { Plugin } from '@nocobase/server';
feat: allows to filter child nodes in tree table blocks (#5096) * feat(database): allows to filter child nodes in tree collections (#4770) * feat(collection-tree): add collection tree plugin * feat(collection-tree): add collection tree path handle function * feat(collection-tree): add collection tree path root and depth column handle function * feat(collection-tree): add exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): add collection tree to build in plugin * feat(collection-tree): modify collection tree plugin version * feat(collection-tree): fix collection tree build bug * feat(collection-tree): fix tree collection path create bug and add tree table search function * feat(collection-tree): add tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table search function * feat(collection-tree): fix tree table search function * feat(collection-tree): improve tree table search filter function * feat(collection-tree): update collection tree plugin version and preset package dependancy * feat(collection-tree): improve tree collection function * feat(collection-tree): remove the duplicate function * feat(collection-tree): fix tree collection db exist bug * feat(collection-tree): improve tree collection db variable name * feat(collection-tree): remove migration file * feat(collection-tree): add collection tree sync create function * feat(collection-tree): add collection tree sync create function * feat(collection-tree): disable collection tree search function * feat(collection-tree): enable collection tree search function * feat(collection-tree): modify collection tree signal to adapt test case * feat(collection-tree): modify code to fix test case * feat(collection-tree): improve code and abstract define collection tree path * feat(collection-tree): modify rootPK to rootPk to avoid underscored behavior * feat(collection-tree): update collection tree version and add collection tree plugin for test * feat(collection-tree): fix filter collection tree root null bug * feat(collection-tree): migrate tree test case to collection tree plugin directory * feat(collection-tree): add transaction for collection tree table delete * feat(collection-tree): fix collection tree switch bug * feat(collection-tree): remove tree filter switch * feat(collection-tree): fix test case * feat(collection-tree): fix test case * feat(collection-tree): fix DB UNDERSCORED bug * feat(collection-tree): fix relate collections not exist bug * feat(collection-tree): add common parent function * feat(collection-tree): add compatible function for sqlite * feat(collection-tree): modify collection tree path create method * feat(collection-tree): migrate tree test case to no acl * feat(collection-tree): migrate tree test case to no acl and fix collections undefined bug * feat(collection-tree): migrate tree test case * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): improve tree search function * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): split the collection tree test to new file and fix filterbytk bug * feat(collection-tree): fix filter tree collection primary key bug * feat(collection-tree): remove recursive test case and fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug and modify test case * feat(collection-tree): add parentid column for tree collection and modify test case * feat(collection-tree): disable sync exist tree collection path table create logic * feat(collection-tree): add sync exist tree collection path table create logic on plugin afterLoad * feat(collection-tree): remove debug code * feat(collection-tree): fix collection tree delete bug * feat(collection-tree): improve collection tree filter find and count implement * feat(collection-tree): improve path table name variable implement * feat(collection-tree): remove unnecessary plugin for test case code * feat(collection-tree): add await for delete synchronous path function * feat(collection-tree): improve tree path create function * feat(collection-tree): remove unnecessary code * feat(collection-tree): remove unnecessary code * feat(collection-tree): improve tree path create function * feat(collection-tree): improve tree filter function * feat(collection-tree): improve tree filter datasource to dynamic * feat(collection-tree): improve find common parent code * feat(collection-tree): add collection tree path table not found warning log * feat(collection-tree): improve get collection primary key implementation * feat(collection-tree): fix tree root path not delete bug and tree path definition bug * feat(collection-tree): fix findAndCount function variable definition bug * feat(collection-tree): modify migrate exist collection tree migration function * feat(collection-tree): correct variable name * feat(collection-tree): remove duplicate code * feat(collection-tree): fix sync exist collection tree path function variable bug * feat(collection-tree): improve collection tree path update logic * feat(collection-tree): remove await for get collection * test: add test cases * feat(collection-tree): modify filter parameter for collection tree * feat(collection-tree): remove await for get collection * feat(collection-tree): remove necessary code * feat(collection-tree): add exist tree collection path migration function * feat(collection-tree): remove unused sync exist tree collection table function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): fix migration rootPk variable bug * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): improve get tree path logic * feat(collection-tree): remove unused test case code * feat(collection-tree): add sync collection tree test case * feat(collection-tree): add tree path test case and fix migration bug * feat(collection-tree): add migration db variable * feat(collection-tree): change logger function * feat(collection-tree): remove unused library * feat(collection-tree): add plugin information * feat(collection-tree): remove await for get collection and use this.db instead of this.app.db * feat(collection-tree): improve the performance of exist data migration to path table * feat(collection-tree): modify get tree path implement to avoid infinite loop bug * feat(collection-tree): fix path create bug * feat(collection-tree): add index for path table * feat(collection-tree): fix related node path bug when some node parent changed * feat(collection-tree): add transaction for get tree path function * feat(collection-tree): add tree path test case * feat(collection-tree): change parent field id name to dynamic * feat(collection-tree): migrate some test case to path.test.ts file * feat(collection-tree): add some test case for path table * feat(collection-tree): fix sqlite and mysql json type search path data bug * feat(collection-tree): fix sqlite query related data sql bug * feat(collection-tree): fix list action test case query data with related data bug * feat(collection-tree): try to fix mysql test case bug to remove index * feat(collection-tree): remove unnecessary code * chore: string field with length option * feat(collection-tree): change path type to string and set max length to 1024 * fix: merge conflicts * feat(collection-tree): modify query path filter to adapt the path change to string * feat(collection-tree): remove append parent condition * feat(collection-tree): split the path test case * feat(collection-tree): remove unused code and fix test case plugin bug * feat(collection-tree): improve get tree path implementation * feat(collection-tree): disable one failed test case for full test * feat(collection-tree): add transaction for collection tree migration * feat(collection-tree): fix collection tree migration bug * feat(collection-tree): remove sqlite handle condition code * feat(collection-tree): add tree test case * feat(collection-tree): add tree test case * feat(collection-tree): modify test case to match the expection * feat(collection-tree): modify tree implementation to root parent * feat(collection-tree): remove unused function * feat(collection-tree): add count function to solve tree data pagination implementation * feat(collection-tree): split tree failed test case to legacy file * feat(collection-tree): correct legacy tree test case to expection * feat(collection-tree): add new tree test for legacy test case to meet expection * feat(collection-tree): fix legacy test case to meet expection * feat(collection-tree): modify legacy test case to meet expection and add new test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): add tree test case * feat(collection-tree): add tree count test case * feat(collection-tree): add tree find and count test case * feat(collection-tree): add tree find one test case * feat(collection-tree): improve migration get path performance * feat(collection-tree): improve get tree path function to avoid undefined parent data situation * feat(collection-tree): add tree and raw parameter variable * fix: test * feat(collection-tree): modify index length * feat(collection-tree): fix index snake case bug * feat(collection-tree): improve tree filter search * feat(collection-tree): fix tree search pagination parameter omit bug * chore: optimize * chore: optimize * fix: build * fix: type * fix: bug * chore: move tree repo to plugin * fix: build * fix: test * chore: remove ts-ignore * fix: issue of getting filter target key --------- Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com> * fix(tree): issue of building tree node map (#5072) --------- Co-authored-by: jimmy201602 <zhengge2012@gmail.com> Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com>
2024-08-21 06:57:01 +00:00
import lodash from 'lodash';
import { Transaction } from 'sequelize';
feat: allows to filter child nodes in tree table blocks (#5096) * feat(database): allows to filter child nodes in tree collections (#4770) * feat(collection-tree): add collection tree plugin * feat(collection-tree): add collection tree path handle function * feat(collection-tree): add collection tree path root and depth column handle function * feat(collection-tree): add exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): add collection tree to build in plugin * feat(collection-tree): modify collection tree plugin version * feat(collection-tree): fix collection tree build bug * feat(collection-tree): fix tree collection path create bug and add tree table search function * feat(collection-tree): add tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table search function * feat(collection-tree): fix tree table search function * feat(collection-tree): improve tree table search filter function * feat(collection-tree): update collection tree plugin version and preset package dependancy * feat(collection-tree): improve tree collection function * feat(collection-tree): remove the duplicate function * feat(collection-tree): fix tree collection db exist bug * feat(collection-tree): improve tree collection db variable name * feat(collection-tree): remove migration file * feat(collection-tree): add collection tree sync create function * feat(collection-tree): add collection tree sync create function * feat(collection-tree): disable collection tree search function * feat(collection-tree): enable collection tree search function * feat(collection-tree): modify collection tree signal to adapt test case * feat(collection-tree): modify code to fix test case * feat(collection-tree): improve code and abstract define collection tree path * feat(collection-tree): modify rootPK to rootPk to avoid underscored behavior * feat(collection-tree): update collection tree version and add collection tree plugin for test * feat(collection-tree): fix filter collection tree root null bug * feat(collection-tree): migrate tree test case to collection tree plugin directory * feat(collection-tree): add transaction for collection tree table delete * feat(collection-tree): fix collection tree switch bug * feat(collection-tree): remove tree filter switch * feat(collection-tree): fix test case * feat(collection-tree): fix test case * feat(collection-tree): fix DB UNDERSCORED bug * feat(collection-tree): fix relate collections not exist bug * feat(collection-tree): add common parent function * feat(collection-tree): add compatible function for sqlite * feat(collection-tree): modify collection tree path create method * feat(collection-tree): migrate tree test case to no acl * feat(collection-tree): migrate tree test case to no acl and fix collections undefined bug * feat(collection-tree): migrate tree test case * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): improve tree search function * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): split the collection tree test to new file and fix filterbytk bug * feat(collection-tree): fix filter tree collection primary key bug * feat(collection-tree): remove recursive test case and fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug and modify test case * feat(collection-tree): add parentid column for tree collection and modify test case * feat(collection-tree): disable sync exist tree collection path table create logic * feat(collection-tree): add sync exist tree collection path table create logic on plugin afterLoad * feat(collection-tree): remove debug code * feat(collection-tree): fix collection tree delete bug * feat(collection-tree): improve collection tree filter find and count implement * feat(collection-tree): improve path table name variable implement * feat(collection-tree): remove unnecessary plugin for test case code * feat(collection-tree): add await for delete synchronous path function * feat(collection-tree): improve tree path create function * feat(collection-tree): remove unnecessary code * feat(collection-tree): remove unnecessary code * feat(collection-tree): improve tree path create function * feat(collection-tree): improve tree filter function * feat(collection-tree): improve tree filter datasource to dynamic * feat(collection-tree): improve find common parent code * feat(collection-tree): add collection tree path table not found warning log * feat(collection-tree): improve get collection primary key implementation * feat(collection-tree): fix tree root path not delete bug and tree path definition bug * feat(collection-tree): fix findAndCount function variable definition bug * feat(collection-tree): modify migrate exist collection tree migration function * feat(collection-tree): correct variable name * feat(collection-tree): remove duplicate code * feat(collection-tree): fix sync exist collection tree path function variable bug * feat(collection-tree): improve collection tree path update logic * feat(collection-tree): remove await for get collection * test: add test cases * feat(collection-tree): modify filter parameter for collection tree * feat(collection-tree): remove await for get collection * feat(collection-tree): remove necessary code * feat(collection-tree): add exist tree collection path migration function * feat(collection-tree): remove unused sync exist tree collection table function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): fix migration rootPk variable bug * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): improve get tree path logic * feat(collection-tree): remove unused test case code * feat(collection-tree): add sync collection tree test case * feat(collection-tree): add tree path test case and fix migration bug * feat(collection-tree): add migration db variable * feat(collection-tree): change logger function * feat(collection-tree): remove unused library * feat(collection-tree): add plugin information * feat(collection-tree): remove await for get collection and use this.db instead of this.app.db * feat(collection-tree): improve the performance of exist data migration to path table * feat(collection-tree): modify get tree path implement to avoid infinite loop bug * feat(collection-tree): fix path create bug * feat(collection-tree): add index for path table * feat(collection-tree): fix related node path bug when some node parent changed * feat(collection-tree): add transaction for get tree path function * feat(collection-tree): add tree path test case * feat(collection-tree): change parent field id name to dynamic * feat(collection-tree): migrate some test case to path.test.ts file * feat(collection-tree): add some test case for path table * feat(collection-tree): fix sqlite and mysql json type search path data bug * feat(collection-tree): fix sqlite query related data sql bug * feat(collection-tree): fix list action test case query data with related data bug * feat(collection-tree): try to fix mysql test case bug to remove index * feat(collection-tree): remove unnecessary code * chore: string field with length option * feat(collection-tree): change path type to string and set max length to 1024 * fix: merge conflicts * feat(collection-tree): modify query path filter to adapt the path change to string * feat(collection-tree): remove append parent condition * feat(collection-tree): split the path test case * feat(collection-tree): remove unused code and fix test case plugin bug * feat(collection-tree): improve get tree path implementation * feat(collection-tree): disable one failed test case for full test * feat(collection-tree): add transaction for collection tree migration * feat(collection-tree): fix collection tree migration bug * feat(collection-tree): remove sqlite handle condition code * feat(collection-tree): add tree test case * feat(collection-tree): add tree test case * feat(collection-tree): modify test case to match the expection * feat(collection-tree): modify tree implementation to root parent * feat(collection-tree): remove unused function * feat(collection-tree): add count function to solve tree data pagination implementation * feat(collection-tree): split tree failed test case to legacy file * feat(collection-tree): correct legacy tree test case to expection * feat(collection-tree): add new tree test for legacy test case to meet expection * feat(collection-tree): fix legacy test case to meet expection * feat(collection-tree): modify legacy test case to meet expection and add new test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): add tree test case * feat(collection-tree): add tree count test case * feat(collection-tree): add tree find and count test case * feat(collection-tree): add tree find one test case * feat(collection-tree): improve migration get path performance * feat(collection-tree): improve get tree path function to avoid undefined parent data situation * feat(collection-tree): add tree and raw parameter variable * fix: test * feat(collection-tree): modify index length * feat(collection-tree): fix index snake case bug * feat(collection-tree): improve tree filter search * feat(collection-tree): fix tree search pagination parameter omit bug * chore: optimize * chore: optimize * fix: build * fix: type * fix: bug * chore: move tree repo to plugin * fix: build * fix: test * chore: remove ts-ignore * fix: issue of getting filter target key --------- Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com> * fix(tree): issue of building tree node map (#5072) --------- Co-authored-by: jimmy201602 <zhengge2012@gmail.com> Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com>
2024-08-21 06:57:01 +00:00
import { TreeCollection } from './tree-collection';
const getFilterTargetKey = (model: Model) => {
// @ts-ignore
return model.constructor.collection.filterTargetKey;
};
class PluginCollectionTreeServer extends Plugin {
async beforeLoad() {
const condition = (options) => {
return options.tree;
};
this.app.db.collectionFactory.registerCollectionType(TreeCollection, {
condition,
});
this.app.dataSourceManager.afterAddDataSource((dataSource: DataSource) => {
const collectionManager = dataSource.collectionManager;
if (collectionManager instanceof SequelizeCollectionManager) {
collectionManager.db.on('afterDefineCollection', (collection: Collection) => {
if (!condition(collection.options)) {
return;
}
const name = `${dataSource.name}_${collection.name}_path`;
const parentForeignKey = collection.treeParentField?.foreignKey || 'parentId';
//always define tree path collection
const options = {};
if (collection.options.schema) {
options['schema'] = collection.options.schema;
}
this.defineTreePathCollection(name, options);
feat: allows to filter child nodes in tree table blocks (#5096) * feat(database): allows to filter child nodes in tree collections (#4770) * feat(collection-tree): add collection tree plugin * feat(collection-tree): add collection tree path handle function * feat(collection-tree): add collection tree path root and depth column handle function * feat(collection-tree): add exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): add collection tree to build in plugin * feat(collection-tree): modify collection tree plugin version * feat(collection-tree): fix collection tree build bug * feat(collection-tree): fix tree collection path create bug and add tree table search function * feat(collection-tree): add tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table search function * feat(collection-tree): fix tree table search function * feat(collection-tree): improve tree table search filter function * feat(collection-tree): update collection tree plugin version and preset package dependancy * feat(collection-tree): improve tree collection function * feat(collection-tree): remove the duplicate function * feat(collection-tree): fix tree collection db exist bug * feat(collection-tree): improve tree collection db variable name * feat(collection-tree): remove migration file * feat(collection-tree): add collection tree sync create function * feat(collection-tree): add collection tree sync create function * feat(collection-tree): disable collection tree search function * feat(collection-tree): enable collection tree search function * feat(collection-tree): modify collection tree signal to adapt test case * feat(collection-tree): modify code to fix test case * feat(collection-tree): improve code and abstract define collection tree path * feat(collection-tree): modify rootPK to rootPk to avoid underscored behavior * feat(collection-tree): update collection tree version and add collection tree plugin for test * feat(collection-tree): fix filter collection tree root null bug * feat(collection-tree): migrate tree test case to collection tree plugin directory * feat(collection-tree): add transaction for collection tree table delete * feat(collection-tree): fix collection tree switch bug * feat(collection-tree): remove tree filter switch * feat(collection-tree): fix test case * feat(collection-tree): fix test case * feat(collection-tree): fix DB UNDERSCORED bug * feat(collection-tree): fix relate collections not exist bug * feat(collection-tree): add common parent function * feat(collection-tree): add compatible function for sqlite * feat(collection-tree): modify collection tree path create method * feat(collection-tree): migrate tree test case to no acl * feat(collection-tree): migrate tree test case to no acl and fix collections undefined bug * feat(collection-tree): migrate tree test case * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): improve tree search function * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): split the collection tree test to new file and fix filterbytk bug * feat(collection-tree): fix filter tree collection primary key bug * feat(collection-tree): remove recursive test case and fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug and modify test case * feat(collection-tree): add parentid column for tree collection and modify test case * feat(collection-tree): disable sync exist tree collection path table create logic * feat(collection-tree): add sync exist tree collection path table create logic on plugin afterLoad * feat(collection-tree): remove debug code * feat(collection-tree): fix collection tree delete bug * feat(collection-tree): improve collection tree filter find and count implement * feat(collection-tree): improve path table name variable implement * feat(collection-tree): remove unnecessary plugin for test case code * feat(collection-tree): add await for delete synchronous path function * feat(collection-tree): improve tree path create function * feat(collection-tree): remove unnecessary code * feat(collection-tree): remove unnecessary code * feat(collection-tree): improve tree path create function * feat(collection-tree): improve tree filter function * feat(collection-tree): improve tree filter datasource to dynamic * feat(collection-tree): improve find common parent code * feat(collection-tree): add collection tree path table not found warning log * feat(collection-tree): improve get collection primary key implementation * feat(collection-tree): fix tree root path not delete bug and tree path definition bug * feat(collection-tree): fix findAndCount function variable definition bug * feat(collection-tree): modify migrate exist collection tree migration function * feat(collection-tree): correct variable name * feat(collection-tree): remove duplicate code * feat(collection-tree): fix sync exist collection tree path function variable bug * feat(collection-tree): improve collection tree path update logic * feat(collection-tree): remove await for get collection * test: add test cases * feat(collection-tree): modify filter parameter for collection tree * feat(collection-tree): remove await for get collection * feat(collection-tree): remove necessary code * feat(collection-tree): add exist tree collection path migration function * feat(collection-tree): remove unused sync exist tree collection table function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): fix migration rootPk variable bug * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): improve get tree path logic * feat(collection-tree): remove unused test case code * feat(collection-tree): add sync collection tree test case * feat(collection-tree): add tree path test case and fix migration bug * feat(collection-tree): add migration db variable * feat(collection-tree): change logger function * feat(collection-tree): remove unused library * feat(collection-tree): add plugin information * feat(collection-tree): remove await for get collection and use this.db instead of this.app.db * feat(collection-tree): improve the performance of exist data migration to path table * feat(collection-tree): modify get tree path implement to avoid infinite loop bug * feat(collection-tree): fix path create bug * feat(collection-tree): add index for path table * feat(collection-tree): fix related node path bug when some node parent changed * feat(collection-tree): add transaction for get tree path function * feat(collection-tree): add tree path test case * feat(collection-tree): change parent field id name to dynamic * feat(collection-tree): migrate some test case to path.test.ts file * feat(collection-tree): add some test case for path table * feat(collection-tree): fix sqlite and mysql json type search path data bug * feat(collection-tree): fix sqlite query related data sql bug * feat(collection-tree): fix list action test case query data with related data bug * feat(collection-tree): try to fix mysql test case bug to remove index * feat(collection-tree): remove unnecessary code * chore: string field with length option * feat(collection-tree): change path type to string and set max length to 1024 * fix: merge conflicts * feat(collection-tree): modify query path filter to adapt the path change to string * feat(collection-tree): remove append parent condition * feat(collection-tree): split the path test case * feat(collection-tree): remove unused code and fix test case plugin bug * feat(collection-tree): improve get tree path implementation * feat(collection-tree): disable one failed test case for full test * feat(collection-tree): add transaction for collection tree migration * feat(collection-tree): fix collection tree migration bug * feat(collection-tree): remove sqlite handle condition code * feat(collection-tree): add tree test case * feat(collection-tree): add tree test case * feat(collection-tree): modify test case to match the expection * feat(collection-tree): modify tree implementation to root parent * feat(collection-tree): remove unused function * feat(collection-tree): add count function to solve tree data pagination implementation * feat(collection-tree): split tree failed test case to legacy file * feat(collection-tree): correct legacy tree test case to expection * feat(collection-tree): add new tree test for legacy test case to meet expection * feat(collection-tree): fix legacy test case to meet expection * feat(collection-tree): modify legacy test case to meet expection and add new test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): add tree test case * feat(collection-tree): add tree count test case * feat(collection-tree): add tree find and count test case * feat(collection-tree): add tree find one test case * feat(collection-tree): improve migration get path performance * feat(collection-tree): improve get tree path function to avoid undefined parent data situation * feat(collection-tree): add tree and raw parameter variable * fix: test * feat(collection-tree): modify index length * feat(collection-tree): fix index snake case bug * feat(collection-tree): improve tree filter search * feat(collection-tree): fix tree search pagination parameter omit bug * chore: optimize * chore: optimize * fix: build * fix: type * fix: bug * chore: move tree repo to plugin * fix: build * fix: test * chore: remove ts-ignore * fix: issue of getting filter target key --------- Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com> * fix(tree): issue of building tree node map (#5072) --------- Co-authored-by: jimmy201602 <zhengge2012@gmail.com> Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com>
2024-08-21 06:57:01 +00:00
//afterSync
collectionManager.db.on(`${collection.name}.afterSync`, async ({ transaction }) => {
// trigger tree path collection create logic
await this.db.getCollection(name).sync({ transaction } as SyncOptions);
});
//afterCreate
this.db.on(`${collection.name}.afterCreate`, async (model: Model, options) => {
const { transaction } = options;
const tk = getFilterTargetKey(model);
let path = `/${model.get(tk)}`;
path = await this.getTreePath(model, path, collection, name, transaction);
const rootPk = path.split('/')[1];
await this.app.db.getRepository(name).create({
values: {
nodePk: model.get(tk),
path: path,
rootPk: rootPk ? Number(rootPk) : null,
},
transaction,
});
});
//afterUpdate
this.db.on(`${collection.name}.afterUpdate`, async (model: Model, options) => {
const tk = getFilterTargetKey(model);
// only update parentId and filterTargetKey
if (!(model._changed.has(tk) || model._changed.has(parentForeignKey))) {
return;
}
const { transaction } = options;
let path = `/${model.get(tk)}`;
path = await this.getTreePath(model, path, collection, name, transaction);
const collectionTreePath = this.db.getCollection(name);
const nodePkColumnName = collectionTreePath.getField('nodePk').columnName();
const pathData = await this.app.db.getRepository(name).findOne({
filter: {
[nodePkColumnName]: model.get(tk),
},
transaction,
});
const relatedNodes = await this.app.db.getRepository(name).find({
filter: {
path: {
$startsWith: `${pathData.get('path')}`,
},
},
transaction,
});
const rootPk = path.split('/')[1];
for (const node of relatedNodes) {
await this.app.db.getRepository(name).update({
values: {
path: node.get('path').replace(`${pathData.get('path')}`, path),
rootPk: rootPk ? Number(rootPk) : null,
},
filter: {
[nodePkColumnName]: node.get('nodePk'),
},
transaction,
});
}
});
//afterDestroy
this.db.on(`${collection.name}.afterDestroy`, async (model: Model, options: DestroyOptions) => {
const tk = getFilterTargetKey(model);
await this.app.db.getRepository(name).destroy({
filter: {
nodePk: model.get(tk),
},
transaction: options.transaction,
});
});
});
}
});
this.db.on('collections.afterDestroy', async (collection: Model, { transaction }) => {
const name = `main_${collection.get('name')}_path`;
if (!condition(collection.options)) {
return;
}
const collectionTree = this.db.getCollection(name);
if (collectionTree) {
await this.db.getCollection(name).removeFromDb({ transaction });
}
});
}
private async defineTreePathCollection(name: string, options: { schema?: string }) {
feat: allows to filter child nodes in tree table blocks (#5096) * feat(database): allows to filter child nodes in tree collections (#4770) * feat(collection-tree): add collection tree plugin * feat(collection-tree): add collection tree path handle function * feat(collection-tree): add collection tree path root and depth column handle function * feat(collection-tree): add exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): add collection tree to build in plugin * feat(collection-tree): modify collection tree plugin version * feat(collection-tree): fix collection tree build bug * feat(collection-tree): fix tree collection path create bug and add tree table search function * feat(collection-tree): add tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table search function * feat(collection-tree): fix tree table search function * feat(collection-tree): improve tree table search filter function * feat(collection-tree): update collection tree plugin version and preset package dependancy * feat(collection-tree): improve tree collection function * feat(collection-tree): remove the duplicate function * feat(collection-tree): fix tree collection db exist bug * feat(collection-tree): improve tree collection db variable name * feat(collection-tree): remove migration file * feat(collection-tree): add collection tree sync create function * feat(collection-tree): add collection tree sync create function * feat(collection-tree): disable collection tree search function * feat(collection-tree): enable collection tree search function * feat(collection-tree): modify collection tree signal to adapt test case * feat(collection-tree): modify code to fix test case * feat(collection-tree): improve code and abstract define collection tree path * feat(collection-tree): modify rootPK to rootPk to avoid underscored behavior * feat(collection-tree): update collection tree version and add collection tree plugin for test * feat(collection-tree): fix filter collection tree root null bug * feat(collection-tree): migrate tree test case to collection tree plugin directory * feat(collection-tree): add transaction for collection tree table delete * feat(collection-tree): fix collection tree switch bug * feat(collection-tree): remove tree filter switch * feat(collection-tree): fix test case * feat(collection-tree): fix test case * feat(collection-tree): fix DB UNDERSCORED bug * feat(collection-tree): fix relate collections not exist bug * feat(collection-tree): add common parent function * feat(collection-tree): add compatible function for sqlite * feat(collection-tree): modify collection tree path create method * feat(collection-tree): migrate tree test case to no acl * feat(collection-tree): migrate tree test case to no acl and fix collections undefined bug * feat(collection-tree): migrate tree test case * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): improve tree search function * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): split the collection tree test to new file and fix filterbytk bug * feat(collection-tree): fix filter tree collection primary key bug * feat(collection-tree): remove recursive test case and fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug and modify test case * feat(collection-tree): add parentid column for tree collection and modify test case * feat(collection-tree): disable sync exist tree collection path table create logic * feat(collection-tree): add sync exist tree collection path table create logic on plugin afterLoad * feat(collection-tree): remove debug code * feat(collection-tree): fix collection tree delete bug * feat(collection-tree): improve collection tree filter find and count implement * feat(collection-tree): improve path table name variable implement * feat(collection-tree): remove unnecessary plugin for test case code * feat(collection-tree): add await for delete synchronous path function * feat(collection-tree): improve tree path create function * feat(collection-tree): remove unnecessary code * feat(collection-tree): remove unnecessary code * feat(collection-tree): improve tree path create function * feat(collection-tree): improve tree filter function * feat(collection-tree): improve tree filter datasource to dynamic * feat(collection-tree): improve find common parent code * feat(collection-tree): add collection tree path table not found warning log * feat(collection-tree): improve get collection primary key implementation * feat(collection-tree): fix tree root path not delete bug and tree path definition bug * feat(collection-tree): fix findAndCount function variable definition bug * feat(collection-tree): modify migrate exist collection tree migration function * feat(collection-tree): correct variable name * feat(collection-tree): remove duplicate code * feat(collection-tree): fix sync exist collection tree path function variable bug * feat(collection-tree): improve collection tree path update logic * feat(collection-tree): remove await for get collection * test: add test cases * feat(collection-tree): modify filter parameter for collection tree * feat(collection-tree): remove await for get collection * feat(collection-tree): remove necessary code * feat(collection-tree): add exist tree collection path migration function * feat(collection-tree): remove unused sync exist tree collection table function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): fix migration rootPk variable bug * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): improve get tree path logic * feat(collection-tree): remove unused test case code * feat(collection-tree): add sync collection tree test case * feat(collection-tree): add tree path test case and fix migration bug * feat(collection-tree): add migration db variable * feat(collection-tree): change logger function * feat(collection-tree): remove unused library * feat(collection-tree): add plugin information * feat(collection-tree): remove await for get collection and use this.db instead of this.app.db * feat(collection-tree): improve the performance of exist data migration to path table * feat(collection-tree): modify get tree path implement to avoid infinite loop bug * feat(collection-tree): fix path create bug * feat(collection-tree): add index for path table * feat(collection-tree): fix related node path bug when some node parent changed * feat(collection-tree): add transaction for get tree path function * feat(collection-tree): add tree path test case * feat(collection-tree): change parent field id name to dynamic * feat(collection-tree): migrate some test case to path.test.ts file * feat(collection-tree): add some test case for path table * feat(collection-tree): fix sqlite and mysql json type search path data bug * feat(collection-tree): fix sqlite query related data sql bug * feat(collection-tree): fix list action test case query data with related data bug * feat(collection-tree): try to fix mysql test case bug to remove index * feat(collection-tree): remove unnecessary code * chore: string field with length option * feat(collection-tree): change path type to string and set max length to 1024 * fix: merge conflicts * feat(collection-tree): modify query path filter to adapt the path change to string * feat(collection-tree): remove append parent condition * feat(collection-tree): split the path test case * feat(collection-tree): remove unused code and fix test case plugin bug * feat(collection-tree): improve get tree path implementation * feat(collection-tree): disable one failed test case for full test * feat(collection-tree): add transaction for collection tree migration * feat(collection-tree): fix collection tree migration bug * feat(collection-tree): remove sqlite handle condition code * feat(collection-tree): add tree test case * feat(collection-tree): add tree test case * feat(collection-tree): modify test case to match the expection * feat(collection-tree): modify tree implementation to root parent * feat(collection-tree): remove unused function * feat(collection-tree): add count function to solve tree data pagination implementation * feat(collection-tree): split tree failed test case to legacy file * feat(collection-tree): correct legacy tree test case to expection * feat(collection-tree): add new tree test for legacy test case to meet expection * feat(collection-tree): fix legacy test case to meet expection * feat(collection-tree): modify legacy test case to meet expection and add new test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): add tree test case * feat(collection-tree): add tree count test case * feat(collection-tree): add tree find and count test case * feat(collection-tree): add tree find one test case * feat(collection-tree): improve migration get path performance * feat(collection-tree): improve get tree path function to avoid undefined parent data situation * feat(collection-tree): add tree and raw parameter variable * fix: test * feat(collection-tree): modify index length * feat(collection-tree): fix index snake case bug * feat(collection-tree): improve tree filter search * feat(collection-tree): fix tree search pagination parameter omit bug * chore: optimize * chore: optimize * fix: build * fix: type * fix: bug * chore: move tree repo to plugin * fix: build * fix: test * chore: remove ts-ignore * fix: issue of getting filter target key --------- Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com> * fix(tree): issue of building tree node map (#5072) --------- Co-authored-by: jimmy201602 <zhengge2012@gmail.com> Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com>
2024-08-21 06:57:01 +00:00
this.db.collection({
name,
autoGenId: false,
timestamps: false,
fields: [
{ type: 'integer', name: 'nodePk' },
{ type: 'string', name: 'path', length: 1024 },
{ type: 'integer', name: 'rootPk' },
],
indexes: [
{
fields: [{ name: 'path', length: 191 }],
},
],
...options,
feat: allows to filter child nodes in tree table blocks (#5096) * feat(database): allows to filter child nodes in tree collections (#4770) * feat(collection-tree): add collection tree plugin * feat(collection-tree): add collection tree path handle function * feat(collection-tree): add collection tree path root and depth column handle function * feat(collection-tree): add exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): improve exist tree collection data migrate function * feat(collection-tree): add collection tree to build in plugin * feat(collection-tree): modify collection tree plugin version * feat(collection-tree): fix collection tree build bug * feat(collection-tree): fix tree collection path create bug and add tree table search function * feat(collection-tree): add tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table pagination function * feat(collection-tree): fix tree table search function * feat(collection-tree): fix tree table search function * feat(collection-tree): improve tree table search filter function * feat(collection-tree): update collection tree plugin version and preset package dependancy * feat(collection-tree): improve tree collection function * feat(collection-tree): remove the duplicate function * feat(collection-tree): fix tree collection db exist bug * feat(collection-tree): improve tree collection db variable name * feat(collection-tree): remove migration file * feat(collection-tree): add collection tree sync create function * feat(collection-tree): add collection tree sync create function * feat(collection-tree): disable collection tree search function * feat(collection-tree): enable collection tree search function * feat(collection-tree): modify collection tree signal to adapt test case * feat(collection-tree): modify code to fix test case * feat(collection-tree): improve code and abstract define collection tree path * feat(collection-tree): modify rootPK to rootPk to avoid underscored behavior * feat(collection-tree): update collection tree version and add collection tree plugin for test * feat(collection-tree): fix filter collection tree root null bug * feat(collection-tree): migrate tree test case to collection tree plugin directory * feat(collection-tree): add transaction for collection tree table delete * feat(collection-tree): fix collection tree switch bug * feat(collection-tree): remove tree filter switch * feat(collection-tree): fix test case * feat(collection-tree): fix test case * feat(collection-tree): fix DB UNDERSCORED bug * feat(collection-tree): fix relate collections not exist bug * feat(collection-tree): add common parent function * feat(collection-tree): add compatible function for sqlite * feat(collection-tree): modify collection tree path create method * feat(collection-tree): migrate tree test case to no acl * feat(collection-tree): migrate tree test case to no acl and fix collections undefined bug * feat(collection-tree): migrate tree test case * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): fix test case bug * feat(collection-tree): improve tree search function * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): merge the next branch code to fix confilct * feat(collection-tree): split the collection tree test to new file and fix filterbytk bug * feat(collection-tree): fix filter tree collection primary key bug * feat(collection-tree): remove recursive test case and fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug * feat(collection-tree): fix collection tree filter bug and modify test case * feat(collection-tree): add parentid column for tree collection and modify test case * feat(collection-tree): disable sync exist tree collection path table create logic * feat(collection-tree): add sync exist tree collection path table create logic on plugin afterLoad * feat(collection-tree): remove debug code * feat(collection-tree): fix collection tree delete bug * feat(collection-tree): improve collection tree filter find and count implement * feat(collection-tree): improve path table name variable implement * feat(collection-tree): remove unnecessary plugin for test case code * feat(collection-tree): add await for delete synchronous path function * feat(collection-tree): improve tree path create function * feat(collection-tree): remove unnecessary code * feat(collection-tree): remove unnecessary code * feat(collection-tree): improve tree path create function * feat(collection-tree): improve tree filter function * feat(collection-tree): improve tree filter datasource to dynamic * feat(collection-tree): improve find common parent code * feat(collection-tree): add collection tree path table not found warning log * feat(collection-tree): improve get collection primary key implementation * feat(collection-tree): fix tree root path not delete bug and tree path definition bug * feat(collection-tree): fix findAndCount function variable definition bug * feat(collection-tree): modify migrate exist collection tree migration function * feat(collection-tree): correct variable name * feat(collection-tree): remove duplicate code * feat(collection-tree): fix sync exist collection tree path function variable bug * feat(collection-tree): improve collection tree path update logic * feat(collection-tree): remove await for get collection * test: add test cases * feat(collection-tree): modify filter parameter for collection tree * feat(collection-tree): remove await for get collection * feat(collection-tree): remove necessary code * feat(collection-tree): add exist tree collection path migration function * feat(collection-tree): remove unused sync exist tree collection table function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): fix migration rootPk variable bug * feat(collection-tree): use get method to replace use dataValues function * feat(collection-tree): improve get tree path logic * feat(collection-tree): remove unused test case code * feat(collection-tree): add sync collection tree test case * feat(collection-tree): add tree path test case and fix migration bug * feat(collection-tree): add migration db variable * feat(collection-tree): change logger function * feat(collection-tree): remove unused library * feat(collection-tree): add plugin information * feat(collection-tree): remove await for get collection and use this.db instead of this.app.db * feat(collection-tree): improve the performance of exist data migration to path table * feat(collection-tree): modify get tree path implement to avoid infinite loop bug * feat(collection-tree): fix path create bug * feat(collection-tree): add index for path table * feat(collection-tree): fix related node path bug when some node parent changed * feat(collection-tree): add transaction for get tree path function * feat(collection-tree): add tree path test case * feat(collection-tree): change parent field id name to dynamic * feat(collection-tree): migrate some test case to path.test.ts file * feat(collection-tree): add some test case for path table * feat(collection-tree): fix sqlite and mysql json type search path data bug * feat(collection-tree): fix sqlite query related data sql bug * feat(collection-tree): fix list action test case query data with related data bug * feat(collection-tree): try to fix mysql test case bug to remove index * feat(collection-tree): remove unnecessary code * chore: string field with length option * feat(collection-tree): change path type to string and set max length to 1024 * fix: merge conflicts * feat(collection-tree): modify query path filter to adapt the path change to string * feat(collection-tree): remove append parent condition * feat(collection-tree): split the path test case * feat(collection-tree): remove unused code and fix test case plugin bug * feat(collection-tree): improve get tree path implementation * feat(collection-tree): disable one failed test case for full test * feat(collection-tree): add transaction for collection tree migration * feat(collection-tree): fix collection tree migration bug * feat(collection-tree): remove sqlite handle condition code * feat(collection-tree): add tree test case * feat(collection-tree): add tree test case * feat(collection-tree): modify test case to match the expection * feat(collection-tree): modify tree implementation to root parent * feat(collection-tree): remove unused function * feat(collection-tree): add count function to solve tree data pagination implementation * feat(collection-tree): split tree failed test case to legacy file * feat(collection-tree): correct legacy tree test case to expection * feat(collection-tree): add new tree test for legacy test case to meet expection * feat(collection-tree): fix legacy test case to meet expection * feat(collection-tree): modify legacy test case to meet expection and add new test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): improve tree test case * feat(collection-tree): add tree test case * feat(collection-tree): add tree count test case * feat(collection-tree): add tree find and count test case * feat(collection-tree): add tree find one test case * feat(collection-tree): improve migration get path performance * feat(collection-tree): improve get tree path function to avoid undefined parent data situation * feat(collection-tree): add tree and raw parameter variable * fix: test * feat(collection-tree): modify index length * feat(collection-tree): fix index snake case bug * feat(collection-tree): improve tree filter search * feat(collection-tree): fix tree search pagination parameter omit bug * chore: optimize * chore: optimize * fix: build * fix: type * fix: bug * chore: move tree repo to plugin * fix: build * fix: test * chore: remove ts-ignore * fix: issue of getting filter target key --------- Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com> * fix(tree): issue of building tree node map (#5072) --------- Co-authored-by: jimmy201602 <zhengge2012@gmail.com> Co-authored-by: xilesun <2013xile@gmail.com> Co-authored-by: Chareice <chareice@live.com>
2024-08-21 06:57:01 +00:00
});
}
private async getTreePath(
model: Model,
path: string,
collection: Collection,
pathCollectionName: string,
transaction?: Transaction,
) {
const tk = getFilterTargetKey(model);
const parentForeignKey = collection.treeParentField?.foreignKey || 'parentId';
if (model.get(parentForeignKey) && model.get(parentForeignKey) !== null) {
const parent = await this.app.db.getRepository(collection.name).findOne({
filter: {
[tk]: model.get(parentForeignKey),
},
transaction,
});
if (parent && parent.get(parentForeignKey) !== model.get(tk)) {
path = `/${parent.get(tk)}${path}`;
if (parent.get(parentForeignKey) !== null) {
const collectionTreePath = this.app.db.getCollection(pathCollectionName);
const nodePkColumnName = collectionTreePath.getField('nodePk').columnName();
const parentPathData = await this.app.db.getRepository(pathCollectionName).findOne({
filter: {
[nodePkColumnName]: parent.get(tk),
},
transaction,
});
const parentPath = lodash.get(parentPathData, 'path', null);
if (parentPath == null) {
path = await this.getTreePath(parent, path, collection, pathCollectionName, transaction);
} else {
path = `${parentPath}/${model.get(tk)}`;
}
}
}
}
return path;
}
}
export default PluginCollectionTreeServer;