@nocobase/plugin-collection-tree 1.4.0-alpha → 1.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/externalVersion.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.4.0-alpha",
|
|
11
|
+
"@nocobase/client": "1.4.0-alpha.0",
|
|
12
12
|
"lodash": "4.17.21",
|
|
13
|
-
"@nocobase/database": "1.4.0-alpha",
|
|
14
|
-
"@nocobase/utils": "1.4.0-alpha",
|
|
15
|
-
"@nocobase/data-source-manager": "1.4.0-alpha",
|
|
16
|
-
"@nocobase/server": "1.4.0-alpha",
|
|
13
|
+
"@nocobase/database": "1.4.0-alpha.0",
|
|
14
|
+
"@nocobase/utils": "1.4.0-alpha.0",
|
|
15
|
+
"@nocobase/data-source-manager": "1.4.0-alpha.0",
|
|
16
|
+
"@nocobase/server": "1.4.0-alpha.0",
|
|
17
17
|
"sequelize": "6.35.2"
|
|
18
18
|
};
|
|
@@ -75,8 +75,10 @@ class collection_tree_default extends import_server.Migration {
|
|
|
75
75
|
}
|
|
76
76
|
]
|
|
77
77
|
};
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const collectionInstance = this.db.getCollection(treeCollection.name);
|
|
79
|
+
const treeCollectionSchema = collectionInstance.collectionSchema();
|
|
80
|
+
if (this.app.db.inDialect("postgres") && treeCollectionSchema != this.app.db.options.schema) {
|
|
81
|
+
collectionOptions["schema"] = treeCollectionSchema;
|
|
80
82
|
}
|
|
81
83
|
this.app.db.collection(collectionOptions);
|
|
82
84
|
const treeExistsInDb = await this.app.db.getCollection(name).existsInDb({ transaction });
|
|
@@ -91,8 +93,8 @@ class collection_tree_default extends import_server.Migration {
|
|
|
91
93
|
{ type: "integer", name: "parentId" }
|
|
92
94
|
]
|
|
93
95
|
};
|
|
94
|
-
if (
|
|
95
|
-
opts["schema"] =
|
|
96
|
+
if (treeCollectionSchema != this.app.db.options.schema) {
|
|
97
|
+
opts["schema"] = treeCollectionSchema;
|
|
96
98
|
}
|
|
97
99
|
this.app.db.collection(opts);
|
|
98
100
|
const chunkSize = 1e3;
|
package/dist/server/plugin.d.ts
CHANGED
package/dist/server/plugin.js
CHANGED
|
@@ -43,9 +43,6 @@ var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
|
43
43
|
var import_server = require("@nocobase/server");
|
|
44
44
|
var import_lodash = __toESM(require("lodash"));
|
|
45
45
|
var import_tree_collection = require("./tree-collection");
|
|
46
|
-
const getFilterTargetKey = (model) => {
|
|
47
|
-
return model.constructor.collection.filterTargetKey;
|
|
48
|
-
};
|
|
49
46
|
class PluginCollectionTreeServer extends import_server.Plugin {
|
|
50
47
|
async beforeLoad() {
|
|
51
48
|
const condition = (options) => {
|
|
@@ -74,7 +71,7 @@ class PluginCollectionTreeServer extends import_server.Plugin {
|
|
|
74
71
|
});
|
|
75
72
|
this.db.on(`${collection.name}.afterCreate`, async (model, options2) => {
|
|
76
73
|
const { transaction } = options2;
|
|
77
|
-
const tk =
|
|
74
|
+
const tk = collection.filterTargetKey;
|
|
78
75
|
let path = `/${model.get(tk)}`;
|
|
79
76
|
path = await this.getTreePath(model, path, collection, name, transaction);
|
|
80
77
|
const rootPk = path.split("/")[1];
|
|
@@ -88,45 +85,30 @@ class PluginCollectionTreeServer extends import_server.Plugin {
|
|
|
88
85
|
});
|
|
89
86
|
});
|
|
90
87
|
this.db.on(`${collection.name}.afterUpdate`, async (model, options2) => {
|
|
91
|
-
const tk =
|
|
88
|
+
const tk = collection.filterTargetKey;
|
|
92
89
|
if (!(model._changed.has(tk) || model._changed.has(parentForeignKey))) {
|
|
93
90
|
return;
|
|
94
91
|
}
|
|
95
92
|
const { transaction } = options2;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const relatedNodes = await this.app.db.getRepository(name).find({
|
|
107
|
-
filter: {
|
|
108
|
-
path: {
|
|
109
|
-
$startsWith: `${pathData.get("path")}`
|
|
110
|
-
}
|
|
93
|
+
await this.updateTreePath(model, collection, name, transaction);
|
|
94
|
+
});
|
|
95
|
+
this.db.on(`${collection.name}.afterBulkUpdate`, async (options2) => {
|
|
96
|
+
const tk = collection.filterTargetKey;
|
|
97
|
+
if (!(options2.where && options2.where[tk])) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const instances = await this.db.getRepository(collection.name).find({
|
|
101
|
+
where: {
|
|
102
|
+
[tk]: options2.where[tk]
|
|
111
103
|
},
|
|
112
|
-
transaction
|
|
104
|
+
transaction: options2.transaction
|
|
113
105
|
});
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
await this.app.db.getRepository(name).update({
|
|
117
|
-
values: {
|
|
118
|
-
path: node.get("path").replace(`${pathData.get("path")}`, path),
|
|
119
|
-
rootPk: rootPk ? Number(rootPk) : null
|
|
120
|
-
},
|
|
121
|
-
filter: {
|
|
122
|
-
[nodePkColumnName]: node.get("nodePk")
|
|
123
|
-
},
|
|
124
|
-
transaction
|
|
125
|
-
});
|
|
106
|
+
for (const model of instances) {
|
|
107
|
+
await this.updateTreePath(model, collection, name, options2.transaction);
|
|
126
108
|
}
|
|
127
109
|
});
|
|
128
110
|
this.db.on(`${collection.name}.afterDestroy`, async (model, options2) => {
|
|
129
|
-
const tk =
|
|
111
|
+
const tk = collection.filterTargetKey;
|
|
130
112
|
await this.app.db.getRepository(name).destroy({
|
|
131
113
|
filter: {
|
|
132
114
|
nodePk: model.get(tk)
|
|
@@ -168,7 +150,7 @@ class PluginCollectionTreeServer extends import_server.Plugin {
|
|
|
168
150
|
}
|
|
169
151
|
async getTreePath(model, path, collection, pathCollectionName, transaction) {
|
|
170
152
|
var _a;
|
|
171
|
-
const tk =
|
|
153
|
+
const tk = collection.filterTargetKey;
|
|
172
154
|
const parentForeignKey = ((_a = collection.treeParentField) == null ? void 0 : _a.foreignKey) || "parentId";
|
|
173
155
|
if (model.get(parentForeignKey) && model.get(parentForeignKey) !== null) {
|
|
174
156
|
const parent = await this.app.db.getRepository(collection.name).findOne({
|
|
@@ -199,5 +181,40 @@ class PluginCollectionTreeServer extends import_server.Plugin {
|
|
|
199
181
|
}
|
|
200
182
|
return path;
|
|
201
183
|
}
|
|
184
|
+
async updateTreePath(model, collection, pathCollectionName, transaction) {
|
|
185
|
+
const tk = collection.filterTargetKey;
|
|
186
|
+
let path = `/${model.get(tk)}`;
|
|
187
|
+
path = await this.getTreePath(model, path, collection, pathCollectionName, transaction);
|
|
188
|
+
const collectionTreePath = this.db.getCollection(pathCollectionName);
|
|
189
|
+
const nodePkColumnName = collectionTreePath.getField("nodePk").columnName();
|
|
190
|
+
const pathData = await this.app.db.getRepository(pathCollectionName).findOne({
|
|
191
|
+
filter: {
|
|
192
|
+
[nodePkColumnName]: model.get(tk)
|
|
193
|
+
},
|
|
194
|
+
transaction
|
|
195
|
+
});
|
|
196
|
+
const relatedNodes = await this.app.db.getRepository(pathCollectionName).find({
|
|
197
|
+
filter: {
|
|
198
|
+
path: {
|
|
199
|
+
$startsWith: `${pathData.get("path")}`
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
transaction
|
|
203
|
+
});
|
|
204
|
+
const rootPk = path.split("/")[1];
|
|
205
|
+
for (const node of relatedNodes) {
|
|
206
|
+
const newPath = node.get("path").replace(pathData.get("path"), path);
|
|
207
|
+
await this.app.db.getRepository(pathCollectionName).update({
|
|
208
|
+
values: {
|
|
209
|
+
path: newPath,
|
|
210
|
+
rootPk: rootPk ? Number(rootPk) : null
|
|
211
|
+
},
|
|
212
|
+
filter: {
|
|
213
|
+
[nodePkColumnName]: node.get("nodePk")
|
|
214
|
+
},
|
|
215
|
+
transaction
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
202
219
|
}
|
|
203
220
|
var plugin_default = PluginCollectionTreeServer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-collection-tree",
|
|
3
|
-
"version": "1.4.0-alpha",
|
|
3
|
+
"version": "1.4.0-alpha.0",
|
|
4
4
|
"displayName": "Collection: Tree",
|
|
5
5
|
"displayName.zh-CN": "数据表:树",
|
|
6
6
|
"description": "Provides tree collection template",
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"@nocobase/server": "1.x",
|
|
15
15
|
"@nocobase/test": "1.x"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "8ffa7b54bbaf720c0c9857da4b19a99110dffc4b"
|
|
18
18
|
}
|