@tachybase/plugin-workflow-approval 1.5.1 → 1.6.1
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/client/base/ApprovalPane.schema.d.ts +81 -11
- package/dist/client/common/components/ApprovalsSummary.d.ts +11 -0
- package/dist/client/common/components/SimpleTable.d.ts +24 -0
- package/dist/client/common/components/WorkflowApproval.d.ts +4 -0
- package/dist/client/common/components/index.d.ts +5 -0
- package/dist/client/common/tools/cleanAssociationIds.d.ts +9 -0
- package/dist/client/index.js +34 -70
- package/dist/client/user-interface/h5/common/approval-columns/summary.column.d.ts +7 -0
- package/dist/client/user-interface/h5/common/processSummary.d.ts +14 -0
- package/dist/client/user-interface/h5/todos/component/TabApprovalItem.d.ts +1 -1
- package/dist/common/constants.d.ts +6 -0
- package/dist/common/constants.js +14 -2
- package/dist/common/interface.d.js +15 -0
- package/dist/common/utils.d.ts +2 -0
- package/dist/common/utils.js +46 -0
- package/dist/externalVersion.js +10 -9
- package/dist/locale/en-US.json +3 -1
- package/dist/locale/zh-CN.json +2 -1
- package/dist/server/actions/approvalCarbonCopy.d.ts +1 -1
- package/dist/server/actions/approvalCarbonCopy.js +7 -7
- package/dist/server/actions/approvalRecords.d.ts +2 -2
- package/dist/server/actions/approvalRecords.js +19 -19
- package/dist/server/actions/approvals.d.ts +6 -6
- package/dist/server/actions/approvals.js +65 -82
- package/dist/server/actions/index.js +1 -1
- package/dist/server/actions/workflows.d.ts +1 -1
- package/dist/server/actions/workflows.js +3 -3
- package/dist/server/plugin.js +0 -3
- package/dist/server/tools.d.ts +4 -7
- package/dist/server/tools.js +253 -12
- package/dist/server/triggers/Approval.d.ts +3 -3
- package/dist/server/triggers/Approval.js +32 -22
- package/dist/server/utils.d.ts +2 -2
- package/dist/server/utils.js +4 -4
- package/package.json +9 -9
|
@@ -26,69 +26,48 @@ var import_constants = require("../../common/constants");
|
|
|
26
26
|
var import_status = require("../constants/status");
|
|
27
27
|
var import_tools = require("../tools");
|
|
28
28
|
const approvals = {
|
|
29
|
-
async create(
|
|
30
|
-
const { status, collectionName, data, workflowId, workflowKey } =
|
|
29
|
+
async create(ctx, next) {
|
|
30
|
+
const { status, collectionName, data, workflowId, workflowKey } = ctx.action.params.values ?? {};
|
|
31
31
|
const [dataSourceName, cName] = (0, import_server.parseCollectionName)(collectionName);
|
|
32
|
-
const dataSource =
|
|
32
|
+
const dataSource = ctx.tego.dataSourceManager.dataSources.get(dataSourceName);
|
|
33
33
|
if (!dataSource) {
|
|
34
|
-
return
|
|
34
|
+
return ctx.throw(400, `Data source "${dataSourceName}" not found`);
|
|
35
35
|
}
|
|
36
36
|
const collection = dataSource.collectionManager.getCollection(cName);
|
|
37
37
|
if (!collection) {
|
|
38
|
-
return
|
|
38
|
+
return ctx.throw(400, `Collection "${cName}" not found`);
|
|
39
39
|
}
|
|
40
40
|
let workflow;
|
|
41
41
|
if (workflowKey) {
|
|
42
|
-
workflow = await
|
|
42
|
+
workflow = await ctx.db.getRepository("workflows").findOne({
|
|
43
43
|
filter: {
|
|
44
44
|
key: workflowKey,
|
|
45
45
|
enabled: true
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
} else {
|
|
49
|
-
workflow = await
|
|
49
|
+
workflow = await ctx.db.getRepository("workflows").findOne({
|
|
50
50
|
filterByTk: workflowId
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
if (!workflow) {
|
|
54
|
-
return
|
|
54
|
+
return ctx.throw(400, "Current workflow not found or disabled, please refresh and try again");
|
|
55
55
|
}
|
|
56
56
|
if (status !== import_status.APPROVAL_STATUS.DRAFT) {
|
|
57
|
-
|
|
57
|
+
ctx.action.mergeParams({
|
|
58
58
|
values: {
|
|
59
59
|
status: import_status.APPROVAL_STATUS.SUBMITTED
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
const { repository, model } = collection;
|
|
64
|
-
let dataToCreate = (0, import_server.traverseJSON)(data, { collection });
|
|
65
|
-
if (workflowKey) {
|
|
66
|
-
Object.values(collection.model.associations || {}).forEach((assocUnknown) => {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
const assoc = assocUnknown;
|
|
69
|
-
if (assoc.foreignKey && Object.prototype.hasOwnProperty.call(dataToCreate, assoc.foreignKey)) {
|
|
70
|
-
delete dataToCreate[assoc.foreignKey];
|
|
71
|
-
}
|
|
72
|
-
if (assoc.associationType === "BelongsToMany" && assoc.as && Array.isArray(dataToCreate[assoc.as])) {
|
|
73
|
-
const targetKey = assoc.targetKey && typeof assoc.targetKey === "string" ? assoc.targetKey : (
|
|
74
|
-
// fallback: 一般为 target model 的主键
|
|
75
|
-
((_a = assoc.target) == null ? void 0 : _a.primaryKeyAttribute) || ((_b = assoc.target) == null ? void 0 : _b.primaryKey) || "id"
|
|
76
|
-
);
|
|
77
|
-
dataToCreate[assoc.as].forEach((item) => {
|
|
78
|
-
if (item && typeof item === "object" && Object.prototype.hasOwnProperty.call(item, targetKey)) {
|
|
79
|
-
delete item[targetKey];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
64
|
const values = await repository.create({
|
|
86
65
|
values: {
|
|
87
|
-
...
|
|
88
|
-
createdBy:
|
|
89
|
-
updatedBy:
|
|
66
|
+
...(0, import_server.traverseJSON)(data, { collection }),
|
|
67
|
+
createdBy: ctx.state.currentUser.id,
|
|
68
|
+
updatedBy: ctx.state.currentUser.id
|
|
90
69
|
},
|
|
91
|
-
context
|
|
70
|
+
context: ctx
|
|
92
71
|
});
|
|
93
72
|
const instance = values.get();
|
|
94
73
|
const summary = (0, import_tools.getSummary)({
|
|
@@ -96,28 +75,30 @@ const approvals = {
|
|
|
96
75
|
data: {
|
|
97
76
|
...instance,
|
|
98
77
|
...data
|
|
99
|
-
}
|
|
78
|
+
},
|
|
79
|
+
collection,
|
|
80
|
+
app: ctx.tego
|
|
100
81
|
});
|
|
101
82
|
Object.keys(model.associations).forEach((key) => {
|
|
102
83
|
delete instance[key];
|
|
103
84
|
});
|
|
104
|
-
|
|
85
|
+
ctx.action.mergeParams({
|
|
105
86
|
values: {
|
|
106
87
|
collectionName,
|
|
107
88
|
data: instance,
|
|
108
89
|
dataKey: values[collection.filterTargetKey],
|
|
109
90
|
workflowKey: workflow.key,
|
|
110
91
|
workflowId: workflow.id,
|
|
111
|
-
applicantRoleName:
|
|
92
|
+
applicantRoleName: ctx.state.currentRole,
|
|
112
93
|
summary
|
|
113
94
|
}
|
|
114
95
|
});
|
|
115
|
-
return import_server.actions.create(
|
|
96
|
+
return import_server.actions.create(ctx, next);
|
|
116
97
|
},
|
|
117
|
-
async update(
|
|
118
|
-
const { collectionName, data, status, updateAssociationValues, summaryConfig } =
|
|
98
|
+
async update(ctx, next) {
|
|
99
|
+
const { collectionName, data, status, updateAssociationValues, summaryConfig } = ctx.action.params.values ?? {};
|
|
119
100
|
const [dataSourceName, cName] = (0, import_server.parseCollectionName)(collectionName);
|
|
120
|
-
const dataSource =
|
|
101
|
+
const dataSource = ctx.tego.dataSourceManager.dataSources.get(dataSourceName);
|
|
121
102
|
const collection = dataSource.collectionManager.getCollection(cName);
|
|
122
103
|
const [target] = await collection.repository.update({
|
|
123
104
|
filterByTk: data[collection.filterTargetKey],
|
|
@@ -126,55 +107,57 @@ const approvals = {
|
|
|
126
107
|
});
|
|
127
108
|
const summary = (0, import_tools.getSummary)({
|
|
128
109
|
summaryConfig,
|
|
129
|
-
data
|
|
110
|
+
data,
|
|
111
|
+
collection,
|
|
112
|
+
app: ctx.tego
|
|
130
113
|
});
|
|
131
|
-
|
|
114
|
+
ctx.action.mergeParams({
|
|
132
115
|
values: {
|
|
133
116
|
status: status ?? import_status.APPROVAL_STATUS.SUBMITTED,
|
|
134
117
|
data,
|
|
135
|
-
applicantRoleName:
|
|
118
|
+
applicantRoleName: ctx.state.currentRole,
|
|
136
119
|
summary
|
|
137
120
|
}
|
|
138
121
|
});
|
|
139
|
-
return import_server.actions.update(
|
|
122
|
+
return import_server.actions.update(ctx, next);
|
|
140
123
|
},
|
|
141
|
-
async destroy(
|
|
124
|
+
async destroy(ctx, next) {
|
|
142
125
|
const {
|
|
143
126
|
filterByTk,
|
|
144
127
|
values: { status }
|
|
145
|
-
} =
|
|
128
|
+
} = ctx.action.params ?? {};
|
|
146
129
|
if (status !== import_status.APPROVAL_STATUS.DRAFT) {
|
|
147
|
-
return
|
|
130
|
+
return ctx.throw(400);
|
|
148
131
|
}
|
|
149
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
132
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
150
133
|
const approval = await repository.findOne({
|
|
151
134
|
filterByTk,
|
|
152
135
|
filter: {
|
|
153
|
-
createdById:
|
|
136
|
+
createdById: ctx.state.currentUser.id
|
|
154
137
|
}
|
|
155
138
|
});
|
|
156
139
|
if (!approval) {
|
|
157
|
-
return
|
|
140
|
+
return ctx.throw(404);
|
|
158
141
|
}
|
|
159
|
-
return import_server.actions.destroy(
|
|
142
|
+
return import_server.actions.destroy(ctx, next);
|
|
160
143
|
},
|
|
161
|
-
async withdraw(
|
|
144
|
+
async withdraw(ctx, next) {
|
|
162
145
|
var _a, _b;
|
|
163
|
-
const { filterByTk } =
|
|
164
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
146
|
+
const { filterByTk } = ctx.action.params;
|
|
147
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
165
148
|
const approval = await repository.findOne({
|
|
166
149
|
filterByTk,
|
|
167
150
|
appends: ["workflow"],
|
|
168
151
|
except: ["workflow.options"]
|
|
169
152
|
});
|
|
170
153
|
if (!approval) {
|
|
171
|
-
return
|
|
154
|
+
return ctx.throw(404);
|
|
172
155
|
}
|
|
173
|
-
if (approval.createdById !== ((_a =
|
|
174
|
-
return
|
|
156
|
+
if (approval.createdById !== ((_a = ctx.state.currentUser) == null ? void 0 : _a.id)) {
|
|
157
|
+
return ctx.throw(403);
|
|
175
158
|
}
|
|
176
159
|
if (approval.status !== import_status.APPROVAL_STATUS.SUBMITTED || !approval.workflow.config.withdrawable) {
|
|
177
|
-
return
|
|
160
|
+
return ctx.throw(400);
|
|
178
161
|
}
|
|
179
162
|
const [execution] = await approval.getExecutions({
|
|
180
163
|
where: {
|
|
@@ -183,10 +166,10 @@ const approvals = {
|
|
|
183
166
|
limit: 1
|
|
184
167
|
});
|
|
185
168
|
if (!execution) {
|
|
186
|
-
return
|
|
169
|
+
return ctx.throw(404, "Execution not found! Please contact the administrator.");
|
|
187
170
|
}
|
|
188
171
|
if (!approval.workflow.enabled && ((_b = approval.workflow) == null ? void 0 : _b.key)) {
|
|
189
|
-
const latestWorkflow = await
|
|
172
|
+
const latestWorkflow = await ctx.db.getRepository("workflows").findOne({
|
|
190
173
|
filter: {
|
|
191
174
|
key: approval.workflow.key,
|
|
192
175
|
enabled: true
|
|
@@ -200,13 +183,13 @@ const approvals = {
|
|
|
200
183
|
workflowId: latestWorkflow.id
|
|
201
184
|
},
|
|
202
185
|
{
|
|
203
|
-
transaction:
|
|
186
|
+
transaction: ctx.transaction
|
|
204
187
|
}
|
|
205
188
|
);
|
|
206
189
|
}
|
|
207
190
|
}
|
|
208
191
|
execution.workflow = approval.workflow;
|
|
209
|
-
await
|
|
192
|
+
await ctx.db.sequelize.transaction(async (transaction) => {
|
|
210
193
|
const records = await approval.getRecords({
|
|
211
194
|
where: {
|
|
212
195
|
executionId: execution.id
|
|
@@ -222,7 +205,7 @@ const approvals = {
|
|
|
222
205
|
],
|
|
223
206
|
transaction
|
|
224
207
|
});
|
|
225
|
-
await
|
|
208
|
+
await ctx.db.getRepository("approvalRecords").destroy({
|
|
226
209
|
filter: {
|
|
227
210
|
id: records.map((record) => record.id)
|
|
228
211
|
},
|
|
@@ -239,52 +222,52 @@ const approvals = {
|
|
|
239
222
|
}, /* @__PURE__ */ new Map());
|
|
240
223
|
return Array.from(jobsMap.values());
|
|
241
224
|
});
|
|
242
|
-
|
|
243
|
-
|
|
225
|
+
ctx.body = approval;
|
|
226
|
+
ctx.status = 202;
|
|
244
227
|
await next();
|
|
245
228
|
await execution.update({
|
|
246
229
|
status: import_module_workflow.EXECUTION_STATUS.CANCELED
|
|
247
230
|
});
|
|
248
231
|
},
|
|
249
|
-
async listCentralized(
|
|
250
|
-
const centralizedApprovalFlow = await
|
|
232
|
+
async listCentralized(ctx, next) {
|
|
233
|
+
const centralizedApprovalFlow = await ctx.db.getRepository("workflows").find({
|
|
251
234
|
filter: {
|
|
252
235
|
type: "approval",
|
|
253
236
|
"config.centralized": true
|
|
254
237
|
},
|
|
255
238
|
fields: ["id"]
|
|
256
239
|
});
|
|
257
|
-
|
|
240
|
+
ctx.action.mergeParams({
|
|
258
241
|
filter: {
|
|
259
242
|
workflowId: centralizedApprovalFlow.map((item) => item.id)
|
|
260
243
|
}
|
|
261
244
|
});
|
|
262
|
-
return await import_server.actions.list(
|
|
245
|
+
return await import_server.actions.list(ctx, next);
|
|
263
246
|
},
|
|
264
|
-
async reminder(
|
|
247
|
+
async reminder(ctx, next) {
|
|
265
248
|
var _a, _b, _c;
|
|
266
|
-
const { filterByTk } =
|
|
267
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
249
|
+
const { filterByTk } = ctx.action.params;
|
|
250
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
268
251
|
const approval = await repository.findOne({
|
|
269
252
|
filterByTk,
|
|
270
253
|
appends: ["records", "workflow", "createdBy.nickname"]
|
|
271
254
|
});
|
|
272
255
|
if (!approval) {
|
|
273
|
-
return
|
|
256
|
+
return ctx.throw(404);
|
|
274
257
|
}
|
|
275
|
-
if (approval.createdById !== ((_a =
|
|
276
|
-
return
|
|
258
|
+
if (approval.createdById !== ((_a = ctx.state.currentUser) == null ? void 0 : _a.id)) {
|
|
259
|
+
return ctx.throw(403);
|
|
277
260
|
}
|
|
278
261
|
if ([import_status.APPROVAL_STATUS.APPROVED, import_status.APPROVAL_STATUS.REJECTED, import_status.APPROVAL_STATUS.ERROR].includes(approval.status)) {
|
|
279
|
-
return
|
|
262
|
+
return ctx.throw(400);
|
|
280
263
|
}
|
|
281
264
|
if (((_b = approval.records) == null ? void 0 : _b.length) === 0) {
|
|
282
|
-
return
|
|
265
|
+
return ctx.throw(400);
|
|
283
266
|
}
|
|
284
267
|
const assignees = approval.records.map((record) => record.userId);
|
|
285
268
|
for (const userId of assignees) {
|
|
286
269
|
const [dataSourceName] = (0, import_server.parseCollectionName)(approval.collectionName);
|
|
287
|
-
const collection =
|
|
270
|
+
const collection = ctx.tego.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(approval.collectionName);
|
|
288
271
|
const message = {
|
|
289
272
|
userId,
|
|
290
273
|
title: `{{t("Approval", { ns: '${import_constants.NAMESPACE}' })}}`,
|
|
@@ -294,11 +277,11 @@ const approvals = {
|
|
|
294
277
|
schemaName: (_c = approval.workflow) == null ? void 0 : _c.config.applyDetail,
|
|
295
278
|
dataKey: approval.data[collection.filterTargetKey]
|
|
296
279
|
};
|
|
297
|
-
|
|
280
|
+
ctx.tego.messageManager.sendMessage(+userId, message);
|
|
298
281
|
}
|
|
299
282
|
await next();
|
|
300
|
-
|
|
301
|
-
|
|
283
|
+
ctx.status = 200;
|
|
284
|
+
ctx.body = {
|
|
302
285
|
message: "reminder sent",
|
|
303
286
|
success: true
|
|
304
287
|
};
|
|
@@ -35,7 +35,7 @@ function make(name, mod) {
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
function init({ app }) {
|
|
38
|
-
app.
|
|
38
|
+
app.resourcer.registerActions({
|
|
39
39
|
...make("workflows", import_workflows.workflows),
|
|
40
40
|
...make("approvals", import_approvals.approvals),
|
|
41
41
|
...make("approvalRecords", import_approvalRecords.approvalRecords),
|
|
@@ -22,15 +22,15 @@ __export(workflows_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(workflows_exports);
|
|
23
23
|
var import_server = require("@tego/server");
|
|
24
24
|
const workflows = {
|
|
25
|
-
async listApprovalFlows(
|
|
26
|
-
|
|
25
|
+
async listApprovalFlows(ctx, next) {
|
|
26
|
+
ctx.action.mergeParams({
|
|
27
27
|
filter: {
|
|
28
28
|
type: "approval",
|
|
29
29
|
enabled: true
|
|
30
30
|
// TODO: 仅显示当前用户有权限的流程
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
return import_server.actions.list(
|
|
33
|
+
return import_server.actions.list(ctx, next);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/server/plugin.js
CHANGED
|
@@ -62,9 +62,6 @@ class PluginWorkflowApproval extends import_server.Plugin {
|
|
|
62
62
|
plugin: this
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
await db.import({
|
|
66
|
-
directory: import_node_path.default.resolve(__dirname, "collections")
|
|
67
|
-
});
|
|
68
65
|
(0, import_actions.init)(this);
|
|
69
66
|
this.app.acl.allow("workflows", ["listApprovalFlows"], "loggedIn");
|
|
70
67
|
this.app.acl.allow("approvals", "*", "loggedIn");
|
package/dist/server/tools.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
data: object;
|
|
4
|
-
}
|
|
5
|
-
export declare function getSummary(params: ParamsType): object;
|
|
6
|
-
export declare function parsePerson({ node, processor, keyName }: {
|
|
1
|
+
import { type ParamsType } from '../common/interface';
|
|
2
|
+
declare function parsePerson({ node, processor, keyName }: {
|
|
7
3
|
node: any;
|
|
8
4
|
processor: any;
|
|
9
5
|
keyName: any;
|
|
10
6
|
}): Promise<unknown[]>;
|
|
11
|
-
|
|
7
|
+
declare function getSummary(params: ParamsType): object;
|
|
8
|
+
export { getSummary, parsePerson };
|
package/dist/server/tools.js
CHANGED
|
@@ -32,18 +32,8 @@ __export(tools_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(tools_exports);
|
|
34
34
|
var import_lodash = __toESM(require("lodash"));
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const result = summaryConfig.reduce((summary, key) => {
|
|
38
|
-
const value = import_lodash.default.get(data, key);
|
|
39
|
-
const realValue = Object.prototype.toString.call(value) === "[object Object]" ? value == null ? void 0 : value["name"] : value;
|
|
40
|
-
return {
|
|
41
|
-
...summary,
|
|
42
|
-
[key]: realValue
|
|
43
|
-
};
|
|
44
|
-
}, {});
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
35
|
+
var import_constants = require("../common/constants");
|
|
36
|
+
var import_utils = require("../common/utils");
|
|
47
37
|
async function parsePerson({ node, processor, keyName }) {
|
|
48
38
|
var _a;
|
|
49
39
|
const configPerson = processor.getParsedValue(((_a = node.config) == null ? void 0 : _a[keyName]) ?? [], node.id).flat().filter(Boolean);
|
|
@@ -63,6 +53,257 @@ async function parsePerson({ node, processor, keyName }) {
|
|
|
63
53
|
}
|
|
64
54
|
return [...targetPerson];
|
|
65
55
|
}
|
|
56
|
+
function getSummary(params) {
|
|
57
|
+
const { summaryConfig = [], data, collection, app } = params;
|
|
58
|
+
const summaryDataSource = getSummaryDataSource({ summaryConfig, data, collection, app });
|
|
59
|
+
return summaryDataSource;
|
|
60
|
+
}
|
|
61
|
+
function getAssociationTitleFieldValue(value, fieldName, collection, app) {
|
|
62
|
+
if (!collection && !app || typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
let field;
|
|
66
|
+
let dataSource;
|
|
67
|
+
let targetCollection;
|
|
68
|
+
if (collection) {
|
|
69
|
+
field = collection.getField(fieldName);
|
|
70
|
+
if (!field || !field.target) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
const db = collection.db;
|
|
74
|
+
if (db) {
|
|
75
|
+
targetCollection = db.getCollection(field.target);
|
|
76
|
+
} else if (app && app.dataSourceManager) {
|
|
77
|
+
const collectionDataSource = collection.dataSource;
|
|
78
|
+
if (collectionDataSource) {
|
|
79
|
+
dataSource = app.dataSourceManager.dataSources.get(collectionDataSource);
|
|
80
|
+
} else {
|
|
81
|
+
dataSource = app.dataSourceManager.dataSources.get("main");
|
|
82
|
+
}
|
|
83
|
+
if (dataSource) {
|
|
84
|
+
targetCollection = dataSource.collectionManager.getCollection(field.target);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
try {
|
|
88
|
+
const cm = collection.collectionManager;
|
|
89
|
+
if (cm) {
|
|
90
|
+
dataSource = cm.dataSource;
|
|
91
|
+
targetCollection = dataSource.collectionManager.getCollection(field.target);
|
|
92
|
+
}
|
|
93
|
+
} catch (e) {
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else if (app) {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
if (!targetCollection) {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
const titleField = targetCollection.titleField || targetCollection.getPrimaryKey() || "id";
|
|
103
|
+
const titleValue = value[titleField];
|
|
104
|
+
return titleValue !== void 0 && titleValue !== null ? String(titleValue) : void 0;
|
|
105
|
+
}
|
|
106
|
+
function getFieldLabel(key, collection) {
|
|
107
|
+
var _a;
|
|
108
|
+
if (!collection) {
|
|
109
|
+
return key;
|
|
110
|
+
}
|
|
111
|
+
const field = collection.getField(key);
|
|
112
|
+
if (field) {
|
|
113
|
+
const uiSchema = (_a = field.options) == null ? void 0 : _a.uiSchema;
|
|
114
|
+
if (uiSchema == null ? void 0 : uiSchema.title) {
|
|
115
|
+
return uiSchema.title;
|
|
116
|
+
}
|
|
117
|
+
if (field.title) {
|
|
118
|
+
return field.title;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return key;
|
|
122
|
+
}
|
|
123
|
+
function processValue(value, fieldName, collection, app) {
|
|
124
|
+
if (value === void 0 || value === null) {
|
|
125
|
+
return "";
|
|
126
|
+
}
|
|
127
|
+
if (value instanceof Date || typeof value.toDate === "function" && value.toDate() instanceof Date) {
|
|
128
|
+
const dateObj = value instanceof Date ? value : value.toDate();
|
|
129
|
+
return dateObj.toISOString();
|
|
130
|
+
}
|
|
131
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
132
|
+
const titleFieldValue = getAssociationTitleFieldValue(value, fieldName, collection, app);
|
|
133
|
+
if (titleFieldValue !== void 0) {
|
|
134
|
+
return titleFieldValue;
|
|
135
|
+
}
|
|
136
|
+
if (value.name !== void 0) {
|
|
137
|
+
return String(value.name);
|
|
138
|
+
}
|
|
139
|
+
return JSON.stringify(value);
|
|
140
|
+
}
|
|
141
|
+
if (typeof value === "number") {
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
return String(value);
|
|
145
|
+
}
|
|
146
|
+
function getSummaryItem(key, data, collection, app) {
|
|
147
|
+
const value = import_lodash.default.get(data, key);
|
|
148
|
+
const label = getFieldLabel(key, collection);
|
|
149
|
+
if (value === void 0 || value === null) {
|
|
150
|
+
return {
|
|
151
|
+
key,
|
|
152
|
+
label,
|
|
153
|
+
type: import_constants.SUMMARY_TYPE.LITERAL,
|
|
154
|
+
value: ""
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (Array.isArray(value)) {
|
|
158
|
+
const processedArray = [];
|
|
159
|
+
for (const item of value) {
|
|
160
|
+
const processedValue2 = processValue(item, key, collection, app);
|
|
161
|
+
processedArray.push(processedValue2);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
key,
|
|
165
|
+
label,
|
|
166
|
+
type: import_constants.SUMMARY_TYPE.ARRAY,
|
|
167
|
+
value: processedArray
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (value instanceof Date || typeof value.toDate === "function" && value.toDate() instanceof Date) {
|
|
171
|
+
const dateObj = value instanceof Date ? value : value.toDate();
|
|
172
|
+
return {
|
|
173
|
+
key,
|
|
174
|
+
label,
|
|
175
|
+
type: import_constants.SUMMARY_TYPE.DATE,
|
|
176
|
+
value: dateObj.toISOString()
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const processedValue = processValue(value, key, collection, app);
|
|
180
|
+
const valueStr = String(processedValue);
|
|
181
|
+
const finalType = (0, import_utils.isDateType)(valueStr) ? import_constants.SUMMARY_TYPE.DATE : import_constants.SUMMARY_TYPE.LITERAL;
|
|
182
|
+
return {
|
|
183
|
+
key,
|
|
184
|
+
label,
|
|
185
|
+
type: finalType,
|
|
186
|
+
value: processedValue
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function getTargetCollection(mainKey, collection, app) {
|
|
190
|
+
if (!collection) {
|
|
191
|
+
return void 0;
|
|
192
|
+
}
|
|
193
|
+
const field = collection.getField(mainKey);
|
|
194
|
+
if (!field || !field.target) {
|
|
195
|
+
return void 0;
|
|
196
|
+
}
|
|
197
|
+
let targetCollection;
|
|
198
|
+
const db = collection.db;
|
|
199
|
+
if (db) {
|
|
200
|
+
targetCollection = db.getCollection(field.target);
|
|
201
|
+
} else if (app && app.dataSourceManager) {
|
|
202
|
+
const collectionDataSource = collection.dataSource;
|
|
203
|
+
let dataSource;
|
|
204
|
+
if (collectionDataSource) {
|
|
205
|
+
dataSource = app.dataSourceManager.dataSources.get(collectionDataSource);
|
|
206
|
+
} else {
|
|
207
|
+
dataSource = app.dataSourceManager.dataSources.get("main");
|
|
208
|
+
}
|
|
209
|
+
if (dataSource) {
|
|
210
|
+
targetCollection = dataSource.collectionManager.getCollection(field.target);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return targetCollection;
|
|
214
|
+
}
|
|
215
|
+
function isManyToManyField(mainKey, collection) {
|
|
216
|
+
if (!collection) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
const field = collection.getField(mainKey);
|
|
220
|
+
if (!field) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return field.type === "belongsToMany" || field.type === "hasMany";
|
|
224
|
+
}
|
|
225
|
+
function getSummaryDataSource({ summaryConfig = [], data, collection, app }) {
|
|
226
|
+
const mainPathKeys = [];
|
|
227
|
+
const subPathKeys = [];
|
|
228
|
+
for (const key of summaryConfig) {
|
|
229
|
+
if (key.includes(".")) {
|
|
230
|
+
subPathKeys.push(key);
|
|
231
|
+
} else {
|
|
232
|
+
mainPathKeys.push(key);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const summaryDataSource = [];
|
|
236
|
+
for (const mainKey of mainPathKeys) {
|
|
237
|
+
const parentValue = import_lodash.default.get(data, mainKey);
|
|
238
|
+
const label = getFieldLabel(mainKey, collection);
|
|
239
|
+
const isManyToMany = isManyToManyField(mainKey, collection);
|
|
240
|
+
if (isManyToMany && Array.isArray(parentValue) && parentValue.length > 0) {
|
|
241
|
+
const mainKeyPrefix = `${mainKey}.`;
|
|
242
|
+
const relevantSubKeys = subPathKeys.filter((subKey) => subKey.startsWith(mainKeyPrefix));
|
|
243
|
+
if (relevantSubKeys.length === 0) {
|
|
244
|
+
summaryDataSource.push(getSummaryItem(mainKey, data, collection, app));
|
|
245
|
+
} else {
|
|
246
|
+
const fieldPathMap = /* @__PURE__ */ new Map();
|
|
247
|
+
for (const subKey of relevantSubKeys) {
|
|
248
|
+
const relativePath = subKey.slice(mainKeyPrefix.length);
|
|
249
|
+
const fieldName = relativePath.split(".")[0];
|
|
250
|
+
if (!fieldPathMap.has(fieldName)) {
|
|
251
|
+
fieldPathMap.set(fieldName, relativePath);
|
|
252
|
+
} else {
|
|
253
|
+
const existingPath = fieldPathMap.get(fieldName);
|
|
254
|
+
if (relativePath.length > existingPath.length) {
|
|
255
|
+
fieldPathMap.set(fieldName, relativePath);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const targetFields = Array.from(fieldPathMap.keys());
|
|
260
|
+
const childValues = [];
|
|
261
|
+
let isValidTable = true;
|
|
262
|
+
let rowCount = 0;
|
|
263
|
+
for (const fieldName of targetFields) {
|
|
264
|
+
const relativePath = fieldPathMap.get(fieldName);
|
|
265
|
+
const fullSubKey = `${mainKey}.${fieldName}`;
|
|
266
|
+
const childArray = [];
|
|
267
|
+
for (let i = 0; i < parentValue.length; i++) {
|
|
268
|
+
const item = parentValue[i];
|
|
269
|
+
const childValue = import_lodash.default.get(item, relativePath);
|
|
270
|
+
const processedValue = processValue(childValue, fullSubKey, collection, app);
|
|
271
|
+
childArray.push(processedValue);
|
|
272
|
+
}
|
|
273
|
+
childValues.push(childArray);
|
|
274
|
+
if (rowCount === 0) {
|
|
275
|
+
rowCount = childArray.length;
|
|
276
|
+
} else if (rowCount !== childArray.length) {
|
|
277
|
+
isValidTable = false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (isValidTable && rowCount > 0) {
|
|
281
|
+
const targetCollection = getTargetCollection(mainKey, collection, app);
|
|
282
|
+
const tableFields = targetFields.map((fieldName, idx) => {
|
|
283
|
+
const childLabel = targetCollection ? getFieldLabel(fieldName, targetCollection) : fieldName;
|
|
284
|
+
return {
|
|
285
|
+
key: fieldName,
|
|
286
|
+
label: childLabel,
|
|
287
|
+
type: import_constants.SUMMARY_TYPE.ARRAY,
|
|
288
|
+
value: childValues[idx]
|
|
289
|
+
};
|
|
290
|
+
});
|
|
291
|
+
summaryDataSource.push({
|
|
292
|
+
key: mainKey,
|
|
293
|
+
label,
|
|
294
|
+
type: import_constants.SUMMARY_TYPE.TABLE,
|
|
295
|
+
value: tableFields
|
|
296
|
+
});
|
|
297
|
+
} else {
|
|
298
|
+
summaryDataSource.push(getSummaryItem(mainKey, data, collection, app));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
summaryDataSource.push(getSummaryItem(mainKey, data, collection, app));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return summaryDataSource;
|
|
306
|
+
}
|
|
66
307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
308
|
0 && (module.exports = {
|
|
68
309
|
getSummary,
|
|
@@ -11,10 +11,10 @@ export default class ApprovalTrigger extends Trigger {
|
|
|
11
11
|
onExecutionUpdate: (execution: any, { transaction }: {
|
|
12
12
|
transaction: any;
|
|
13
13
|
}) => Promise<void>;
|
|
14
|
-
middleware: (
|
|
14
|
+
middleware: (ctx: any, next: any) => Promise<any>;
|
|
15
15
|
constructor(workflow: any);
|
|
16
|
-
workflowTriggerAction(
|
|
17
|
-
collectionTriggerAction(
|
|
16
|
+
workflowTriggerAction(ctx: any, next: any): Promise<any>;
|
|
17
|
+
collectionTriggerAction(ctx: any, workflowList: any): Promise<void>;
|
|
18
18
|
on(workflow: any): void;
|
|
19
19
|
off(workflow: any): void;
|
|
20
20
|
duplicateConfig(workflow: any, { transaction }: {
|