@steedos-labs/plugin-workflow 3.0.0-beta.26 → 3.0.0-beta.28
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.
|
@@ -16,6 +16,7 @@ const pushManager = require('./push_manager');
|
|
|
16
16
|
const { t } = require('@steedos/i18n')
|
|
17
17
|
const moment = require('moment')
|
|
18
18
|
const { getObject } = require('@steedos/objectql');
|
|
19
|
+
const { evaluate } = require('amis-formula');
|
|
19
20
|
|
|
20
21
|
const UUFlowManager = {};
|
|
21
22
|
|
|
@@ -556,6 +557,47 @@ UUFlowManager.isFlowSpaceMatched = function (flow, space_id) {
|
|
|
556
557
|
}
|
|
557
558
|
};
|
|
558
559
|
|
|
560
|
+
const isAmisFormula = (formula) => {
|
|
561
|
+
// 有${}包裹的表达式就识别为amis公式
|
|
562
|
+
return /\$\{.+\}/.test(formula);
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
const runAmisFormula = function (formula, data) {
|
|
566
|
+
try {
|
|
567
|
+
const amisFormulaValue = evaluate(
|
|
568
|
+
formula,
|
|
569
|
+
Object.assign({}, data),
|
|
570
|
+
{},
|
|
571
|
+
);
|
|
572
|
+
if (formula === amisFormulaValue) {
|
|
573
|
+
throw new Error(
|
|
574
|
+
`Workflow Condition Step Amis formula "${formula}" evaluate failed "Function is not defined".`,
|
|
575
|
+
);
|
|
576
|
+
} else {
|
|
577
|
+
return amisFormulaValue;
|
|
578
|
+
}
|
|
579
|
+
} catch (e) {
|
|
580
|
+
throw new Error(
|
|
581
|
+
`Catch an error "${e.message}" while evaluate condition step amis formula "${formula}".`,
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Calculate condition for conditional step
|
|
588
|
+
* @param {Object} values - Form values
|
|
589
|
+
* @param {String} condition_str - Condition string
|
|
590
|
+
* @returns {Boolean} Condition result
|
|
591
|
+
*/
|
|
592
|
+
UUFlowManager.calculateConditionWithAmis = function (values, condition_str) {
|
|
593
|
+
try {
|
|
594
|
+
return runAmisFormula(condition_str, values);
|
|
595
|
+
} catch (error) {
|
|
596
|
+
console.error(error.stack);
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
559
601
|
/**
|
|
560
602
|
* Calculate condition for conditional step
|
|
561
603
|
* @param {Object} values - Form values
|
|
@@ -829,10 +871,17 @@ UUFlowManager.getNextSteps = async function (instance, flow, step, judge, values
|
|
|
829
871
|
|
|
830
872
|
for (const step_line of step.lines) {
|
|
831
873
|
if (step_line.state === "submitted") {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
874
|
+
let step_line_condition = step_line.condition;
|
|
875
|
+
let allow = false;
|
|
876
|
+
if (isAmisFormula(step_line_condition)) {
|
|
877
|
+
allow = UUFlowManager.calculateConditionWithAmis(__values, step_line_condition);
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
step_line_condition = step_line.condition.replace(reg, (vowel) => {
|
|
881
|
+
return prefix + vowel.replace(/\{\s*/, "[\"").replace(/\s*\}/, "\"]").replace(/\s*\.\s*/g, "\"][\"");
|
|
882
|
+
});
|
|
883
|
+
allow = UUFlowManager.calculateCondition(__values, step_line_condition);
|
|
884
|
+
}
|
|
836
885
|
if (allow) {
|
|
837
886
|
nextSteps.push(step_line.to_step);
|
|
838
887
|
}
|
|
@@ -246,7 +246,7 @@ WorkflowManager.getUser = async function (spaceId, userId, notNeedDetails) {
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
if (typeof userId !== 'string') {
|
|
249
|
-
return WorkflowManager.getUsers(spaceId, userId, notNeedDetails);
|
|
249
|
+
return await WorkflowManager.getUsers(spaceId, userId, notNeedDetails);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
const spaceUsersCollection = await getCollection('space_users');
|
|
@@ -83,11 +83,16 @@ router.post('/api/workflow/v2/nextStepUsers', requireAuthentication, async funct
|
|
|
83
83
|
var
|
|
84
84
|
userField = nextStep.approver_user_field,
|
|
85
85
|
userFieldValue = values[userField];
|
|
86
|
-
if
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
if(userFieldValue){
|
|
87
|
+
if (_.isArray(userFieldValue)) { //如果多选,以userFieldValue值为Array
|
|
88
|
+
nextStepUsers = await WorkflowManager.getUsers(spaceId, userFieldValue);
|
|
89
|
+
} else {
|
|
90
|
+
nextStepUsers.push(await WorkflowManager.getUser(spaceId, userFieldValue));
|
|
91
|
+
}
|
|
92
|
+
}else {
|
|
93
|
+
error = "FIELD_VALUE_EMPTY";
|
|
90
94
|
}
|
|
95
|
+
|
|
91
96
|
break;
|
|
92
97
|
case 'orgField':
|
|
93
98
|
var
|
|
@@ -96,7 +101,7 @@ router.post('/api/workflow/v2/nextStepUsers', requireAuthentication, async funct
|
|
|
96
101
|
orgField = nextStep.approver_org_field,
|
|
97
102
|
orgFieldValue = values[orgField];
|
|
98
103
|
if (orgFieldValue) {
|
|
99
|
-
if (
|
|
104
|
+
if (_.isArray(orgFieldValue)) { //如果多选,以orgFieldValue值为Array
|
|
100
105
|
orgs = await WorkflowManager.getOrganizations(orgFieldValue);
|
|
101
106
|
orgChildrens = await WorkflowManager.getOrganizationsChildrens(spaceId, orgFieldValue);
|
|
102
107
|
} else {
|
|
@@ -105,7 +110,7 @@ router.post('/api/workflow/v2/nextStepUsers', requireAuthentication, async funct
|
|
|
105
110
|
}
|
|
106
111
|
nextStepUsers = await WorkflowManager.getOrganizationsUsers(spaceId, orgChildrens);
|
|
107
112
|
|
|
108
|
-
orgFieldUsers = await WorkflowManager.getOrganizationsUsers(spaceId, orgs);
|
|
113
|
+
const orgFieldUsers = await WorkflowManager.getOrganizationsUsers(spaceId, orgs);
|
|
109
114
|
|
|
110
115
|
nextStepUsers = nextStepUsers.concat(orgFieldUsers);
|
|
111
116
|
|
|
@@ -131,7 +136,7 @@ router.post('/api/workflow/v2/nextStepUsers', requireAuthentication, async funct
|
|
|
131
136
|
userFieldValue = values[userField],
|
|
132
137
|
approverRoleIds = nextStep.approver_roles;
|
|
133
138
|
if (userFieldValue) {
|
|
134
|
-
if (
|
|
139
|
+
if (_.isArray(userFieldValue)) { //如果多选,以userFieldValue值为Array
|
|
135
140
|
nextStepUsers = await WorkflowManager.getRoleUsersByUsersAndRoles(spaceId, userFieldValue, approverRoleIds);
|
|
136
141
|
} else {
|
|
137
142
|
nextStepUsers = await WorkflowManager.getRoleUsersByUsersAndRoles(spaceId, [userFieldValue], approverRoleIds);
|
|
@@ -153,7 +158,7 @@ router.post('/api/workflow/v2/nextStepUsers', requireAuthentication, async funct
|
|
|
153
158
|
approverRoleIds = nextStep.approver_roles;
|
|
154
159
|
|
|
155
160
|
if (orgFieldValue) {
|
|
156
|
-
if (
|
|
161
|
+
if (_.isArray(orgFieldValue)) { //如果多选,以orgFieldValue值为Array
|
|
157
162
|
nextStepUsers = await WorkflowManager.getRoleUsersByOrgsAndRoles(spaceId, orgFieldValue, approverRoleIds);
|
|
158
163
|
} else {
|
|
159
164
|
nextStepUsers = await WorkflowManager.getRoleUsersByOrgsAndRoles(spaceId, [orgFieldValue], approverRoleIds);
|
|
@@ -160,8 +160,8 @@ function transformFormFields(amisField) {
|
|
|
160
160
|
|
|
161
161
|
|
|
162
162
|
if(amisField.type === 'steedos-field'){
|
|
163
|
-
|
|
164
|
-
_id:
|
|
163
|
+
const sfield = {
|
|
164
|
+
_id: amisField.config.name,
|
|
165
165
|
code: amisField.config.name,
|
|
166
166
|
name: amisField.config.label,
|
|
167
167
|
is_wide: amisField.config.is_wide,
|
|
@@ -173,6 +173,17 @@ function transformFormFields(amisField) {
|
|
|
173
173
|
type: 'steedos-field',
|
|
174
174
|
config: amisField.config
|
|
175
175
|
}
|
|
176
|
+
|
|
177
|
+
let tempConfig = amisField.config;
|
|
178
|
+
|
|
179
|
+
if (tempConfig.reference_to === "organizations") {
|
|
180
|
+
sfield.type = 'group'
|
|
181
|
+
sfield._type = 'steedos-field'
|
|
182
|
+
}else if(tempConfig.reference_to === "space_users" || tempConfig.reference_to === "users"){
|
|
183
|
+
sfield.type = 'user'
|
|
184
|
+
sfield._type = 'steedos-field'
|
|
185
|
+
}
|
|
186
|
+
return sfield;
|
|
176
187
|
};
|
|
177
188
|
|
|
178
189
|
let formFieldsItem = {
|
|
@@ -454,7 +465,7 @@ function transformFormFields(amisField) {
|
|
|
454
465
|
|
|
455
466
|
if (tempConfig.reference_to === "organizations") {
|
|
456
467
|
steedosField.type = 'group'
|
|
457
|
-
}else if(tempConfig.reference_to === "space_users"){
|
|
468
|
+
}else if(tempConfig.reference_to === "space_users" || tempConfig.reference_to === "user"){
|
|
458
469
|
// && tempConfig.reference_to_field === 'user'
|
|
459
470
|
steedosField.type = 'user'
|
|
460
471
|
}else{
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos-labs/plugin-workflow",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.28",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc && webpack --config webpack.config.js",
|
|
8
8
|
"build:watch": "tsc --watch",
|
|
9
|
-
"release": "npm publish --registry https://registry.npmjs.org && open https://npmmirror.com/sync/@steedos-labs/plugin-workflow && cnpm sync @steedos-labs/plugin-workflow"
|
|
9
|
+
"release": "yarn build && npm publish --registry https://registry.npmjs.org && open https://npmmirror.com/sync/@steedos-labs/plugin-workflow && cnpm sync @steedos-labs/plugin-workflow"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"graphql-parse-resolve-info": "^4.12.3",
|