@nocobase/plugin-field-sort 1.5.0-beta.9 → 1.5.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 +6 -6
- package/dist/server/action.js +23 -23
- package/dist/server/sort-field.js +13 -10
- package/package.json +2 -2
package/dist/externalVersion.js
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.5.0
|
|
12
|
-
"@nocobase/database": "1.5.0-beta.9",
|
|
13
|
-
"@nocobase/actions": "1.5.0-beta.9",
|
|
14
|
-
"@nocobase/server": "1.5.0-beta.9",
|
|
15
|
-
"@nocobase/data-source-manager": "1.5.0-beta.9",
|
|
11
|
+
"@nocobase/client": "1.5.0",
|
|
16
12
|
"lodash": "4.17.21",
|
|
13
|
+
"@nocobase/database": "1.5.0",
|
|
14
|
+
"@nocobase/actions": "1.5.0",
|
|
15
|
+
"@nocobase/server": "1.5.0",
|
|
16
|
+
"@nocobase/data-source-manager": "1.5.0",
|
|
17
17
|
"sequelize": "6.35.2",
|
|
18
|
-
"@nocobase/lock-manager": "1.5.0
|
|
18
|
+
"@nocobase/lock-manager": "1.5.0"
|
|
19
19
|
};
|
package/dist/server/action.js
CHANGED
|
@@ -30,6 +30,7 @@ __export(action_exports, {
|
|
|
30
30
|
move: () => move
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(action_exports);
|
|
33
|
+
var import_lodash = require("lodash");
|
|
33
34
|
var import_database = require("@nocobase/database");
|
|
34
35
|
var import_sort_field = require("./sort-field");
|
|
35
36
|
async function move(ctx, next) {
|
|
@@ -78,42 +79,42 @@ class SortableCollection {
|
|
|
78
79
|
}
|
|
79
80
|
// insert source position to target position
|
|
80
81
|
async move(sourceInstanceId, targetInstanceId, options = {}) {
|
|
81
|
-
|
|
82
|
+
let sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
|
82
83
|
const targetInstance = await this.collection.repository.findByTargetKey(targetInstanceId);
|
|
83
84
|
if (this.scopeKey && sourceInstance.get(this.scopeKey) !== targetInstance.get(this.scopeKey)) {
|
|
84
|
-
await
|
|
85
|
-
|
|
85
|
+
[sourceInstance] = await this.collection.repository.update({
|
|
86
|
+
filterByTk: sourceInstanceId,
|
|
87
|
+
values: {
|
|
88
|
+
[this.scopeKey]: targetInstance.get(this.scopeKey)
|
|
89
|
+
}
|
|
86
90
|
});
|
|
87
91
|
}
|
|
88
92
|
await this.sameScopeMove(sourceInstance, targetInstance, options);
|
|
89
93
|
}
|
|
90
94
|
async changeScope(sourceInstanceId, targetScope, method) {
|
|
91
|
-
|
|
95
|
+
let sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
|
92
96
|
const targetScopeValue = targetScope[this.scopeKey];
|
|
93
97
|
if (targetScopeValue && sourceInstance.get(this.scopeKey) !== targetScopeValue) {
|
|
94
|
-
await
|
|
95
|
-
|
|
98
|
+
[sourceInstance] = await this.collection.repository.update({
|
|
99
|
+
filterByTk: sourceInstanceId,
|
|
100
|
+
values: {
|
|
96
101
|
[this.scopeKey]: targetScopeValue
|
|
97
102
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
);
|
|
103
|
+
silent: false
|
|
104
|
+
});
|
|
102
105
|
if (method === "prepend") {
|
|
103
106
|
await this.sticky(sourceInstanceId);
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
async sticky(sourceInstanceId) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
+
await this.collection.repository.update({
|
|
112
|
+
filterByTk: sourceInstanceId,
|
|
113
|
+
values: {
|
|
111
114
|
[this.field.get("name")]: 0
|
|
112
115
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
);
|
|
116
|
+
silent: true
|
|
117
|
+
});
|
|
117
118
|
}
|
|
118
119
|
async sameScopeMove(sourceInstance, targetInstance, options) {
|
|
119
120
|
const fieldName = this.field.get("name");
|
|
@@ -151,14 +152,13 @@ class SortableCollection {
|
|
|
151
152
|
by: change,
|
|
152
153
|
silent: true
|
|
153
154
|
});
|
|
154
|
-
await
|
|
155
|
-
|
|
155
|
+
await this.collection.repository.update({
|
|
156
|
+
filterByTk: this.collection.isMultiFilterTargetKey() ? (0, import_lodash.pick)(sourceInstance, this.collection.filterTargetKey) : sourceInstance.get(this.collection.filterTargetKey),
|
|
157
|
+
values: {
|
|
156
158
|
[fieldName]: targetSort
|
|
157
159
|
},
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
);
|
|
160
|
+
silent: true
|
|
161
|
+
});
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -68,16 +68,6 @@ class SortField extends import_database.Field {
|
|
|
68
68
|
};
|
|
69
69
|
initRecordsSortValue = async (options) => {
|
|
70
70
|
const { transaction } = options;
|
|
71
|
-
const orderField = (() => {
|
|
72
|
-
const model = this.collection.model;
|
|
73
|
-
if (model.primaryKeyAttribute) {
|
|
74
|
-
return model.primaryKeyAttribute;
|
|
75
|
-
}
|
|
76
|
-
if (model.rawAttributes["createdAt"]) {
|
|
77
|
-
return model.rawAttributes["createdAt"].field;
|
|
78
|
-
}
|
|
79
|
-
throw new Error(`can not find order key for collection ${this.collection.name}`);
|
|
80
|
-
})();
|
|
81
71
|
const needInit = async (scopeKey2 = null, scopeValue = null) => {
|
|
82
72
|
const filter = {};
|
|
83
73
|
if (scopeKey2 && scopeValue) {
|
|
@@ -97,6 +87,19 @@ class SortField extends import_database.Field {
|
|
|
97
87
|
return emptyCount === totalCount && emptyCount > 0;
|
|
98
88
|
};
|
|
99
89
|
const doInit = async (scopeKey2 = null, scopeValue = null) => {
|
|
90
|
+
const orderField = (() => {
|
|
91
|
+
const model = this.collection.model;
|
|
92
|
+
if (model.primaryKeyAttribute) {
|
|
93
|
+
const primaryKeyAttribute = model.rawAttributes[model.primaryKeyAttribute];
|
|
94
|
+
if (primaryKeyAttribute.autoIncrement) {
|
|
95
|
+
return primaryKeyAttribute.field;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (model.rawAttributes["createdAt"]) {
|
|
99
|
+
return model.rawAttributes["createdAt"].field;
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`can not find order key for collection ${this.collection.name}`);
|
|
102
|
+
})();
|
|
100
103
|
const queryInterface = this.collection.db.sequelize.getQueryInterface();
|
|
101
104
|
if (scopeKey2) {
|
|
102
105
|
const scopeAttribute = this.collection.model.rawAttributes[scopeKey2];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-field-sort",
|
|
3
|
-
"version": "1.5.0
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"displayName": "Collection field: Sort",
|
|
6
6
|
"displayName.zh-CN": "数据表字段:排序",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"keywords": [
|
|
21
21
|
"Collection fields"
|
|
22
22
|
],
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "1eae52e1fc837e9b1c6b63fc31bda7945b6101e9"
|
|
24
24
|
}
|