@steedos-labs/plugin-workflow 3.0.1-beta.4 → 3.0.1-beta.5

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.
@@ -4161,6 +4161,7 @@ UUFlowManager.draft_save_instance = async function (ins, userId) {
4161
4161
  flows: await getCollection('flows'),
4162
4162
  forms: await getCollection('forms'),
4163
4163
  users: await getCollection('users'),
4164
+ space_users: await getCollection('space_users'),
4164
4165
  organizations: await getCollection('organizations'),
4165
4166
  };
4166
4167
 
@@ -77,7 +77,7 @@ amis_schema: |-
77
77
  "&": "$$",
78
78
  "record": "${record}"
79
79
  },
80
- "requestAdaptor": "const record = api.data.record;\napi.data = {\n reason: api.data.reason,\n approve: {\n instance: record._id,\n type: record.approve.type,\n trace: record.approve.trace,\n values: record.approve.values\n }\n}\nreturn api;"
80
+ "requestAdaptor": "const record = api.data.record;\napi.data = {\n reason: api.data.reason,\n approve: {\n _id: record.approve._id,\n instance: record._id,\n type: record.approve.type,\n trace: record.approve.trace,\n values: record.approve.values\n }\n}\nreturn api;"
81
81
  },
82
82
  "messages": {}
83
83
  },
@@ -26,6 +26,7 @@
26
26
  "hideRoot": true,
27
27
  "showIcon": true,
28
28
  "initiallyOpen": false,
29
+ "virtualThreshold": 100000,
29
30
  "value": "/app/${appId}/${objectName}/grid/${listName}",
30
31
  "size": "md",
31
32
  "onEvent": {
@@ -31,6 +31,7 @@
31
31
  "hideRoot": true,
32
32
  "showIcon": true,
33
33
  "initiallyOpen": false,
34
+ "virtualThreshold": 100000,
34
35
  "value":"/app/${appId}/${objectName}/grid/${listName}",
35
36
  "size": "md",
36
37
  "onEvent": {
@@ -36,6 +36,7 @@
36
36
  "stacked": true,
37
37
  "multiple": false,
38
38
  "enableNodePath": false,
39
+ "virtualThreshold": 100000,
39
40
  "hideRoot": true,
40
41
  "showIcon": true,
41
42
  "initiallyOpen": false,
@@ -41,6 +41,7 @@
41
41
  "hideRoot": true,
42
42
  "showIcon": true,
43
43
  "initiallyOpen": false,
44
+ "virtualThreshold": 100000,
44
45
  "value": "${value}",
45
46
  "size": "md",
46
47
  "onEvent": {
@@ -238,15 +238,15 @@
238
238
  case "user":
239
239
  const useTpl = {
240
240
  "type": "steedos-field",
241
- "id": "u:9f4486c22f52",
242
- "field": JSON.stringify({
241
+ "id": `u:${field.code}`,
242
+ "config": {
243
243
  name: field.code,
244
244
  label: field.name,
245
245
  reference_to: "space_users",
246
246
  reference_to_field: 'user',
247
247
  multiple: field.is_multiselect,
248
248
  type: "lookup"
249
- }),
249
+ },
250
250
  }
251
251
  // const useTpl = await lookupToAmis(
252
252
  // {
@@ -265,14 +265,14 @@
265
265
  case "group":
266
266
  const orgTpl = {
267
267
  "type": "steedos-field",
268
- "id": "u:9f4486c22f52",
269
- "field": JSON.stringify({
268
+ "id": `u:${field.code}`,
269
+ "config": {
270
270
  name: field.code,
271
271
  label: field.name,
272
272
  reference_to: "organizations",
273
273
  multiple: field.is_multiselect,
274
274
  type: "lookup"
275
- })
275
+ }
276
276
  }
277
277
 
278
278
  // const orgTpl = await lookupToAmis(
@@ -11,59 +11,16 @@ const express = require('express');
11
11
  const router = express.Router();
12
12
  const { requireAuthentication } = require("@steedos/auth");
13
13
  const WorkflowManager = require('../manager/workflow_manager');
14
- const Fiber = function(fun){console.log('TODO Fiber...')}
15
- /**
16
- @api {post} /api/formula/users 获取用户
17
- @apiVersion 0.0.0
18
- @apiName /api/formula/users
19
- @apiGroup service-workflow
20
- @apiBody {String[]} userIds 用户ID
21
- @apiBody {String} spaceId 工作区ID
22
- @apiSuccessExample {json} Success-Response:
23
- HTTP/1.1 200 OK
24
- {
25
- 'spaceUsers': [],
26
- }
27
- @apiErrorExample {json} Error-Response:
28
- HTTP/1.1 200 OK
29
- {
30
- errors: ''
31
- }
32
- */
33
- router.post('/api/formula/users', requireAuthentication, async function (req, res) {
14
+
15
+ router.get('/api/formula/user/:userId', requireAuthentication, async function (req, res) {
34
16
  try {
35
17
  let userSession = req.user;
36
- const userId = userSession.userId;
37
- Fiber(async function () {
38
- try {
39
- var spaceId, spaceUsers, space_user, userIds;
40
- userIds = req.body.userIds;
41
- spaceId = req.body.spaceId;
42
- spaceUsers = [];
43
- space_user = db.space_users.findOne({
44
- user: userId,
45
- space: spaceId
46
- }, {
47
- fields: {
48
- _id: 1
49
- }
50
- });
51
- if (!space_user) {
52
- return res.status(200).send({ 'errors': '无权限' });
53
- }
54
- if (!userIds || !spaceId) {
55
- return res.status(200).send({ 'errors': '缺少参数' });
56
- }
57
- spaceUsers = WorkflowManager.getFormulaUserObjects(spaceId, userIds);
58
18
 
59
- res.status(200).send({ 'spaceUsers': spaceUsers });
60
- } catch (e) {
61
- console.error(e);
62
- res.status(200).send({
63
- errors: [{ errorMessage: e.message }]
64
- });
65
- }
66
- }).run()
19
+ const { userId } = req.params;
20
+
21
+ const result = await WorkflowManager.getFormulaUserObject(userSession.spaceId, userId);
22
+
23
+ res.status(200).send(result);
67
24
  } catch (e) {
68
25
  res.status(200).send({
69
26
  errors: [{ errorMessage: e.message }]
@@ -119,116 +119,126 @@ const getCategoriesMonitor = async (userSession, req, currentUrl) => {
119
119
  let hasFlowsPer = userSession.is_space_admin;
120
120
  const { appId } = req.params;
121
121
  let output = [];
122
- let data = {};
123
122
  let monitorIsUnfolded = false;
124
- let categoriesData = await objectql.broker.call('api.graphql', {
125
- query: `
126
- query {
127
- categories(filters:[["space", "=", "${userSession.spaceId}"]],sort:"sort_no desc"){
128
- _id,
129
- app__expand{
130
- code
131
- }
132
- }
123
+
124
+ try {
125
+ // const sa = new Date().getTime();
126
+ const apps = await objectql.getObject('apps').find({filters: ['space', '=', userSession.spaceId], fields: ['_id', 'code']});
127
+ // console.log(`find apps`, new Date().getTime() - sa)
128
+ const appsMap = new Map(Object.entries(lodash.keyBy(apps, '_id')));
129
+ // const sc = new Date().getTime();
130
+ const categories = await objectql.getObject('categories').find({filters: ["space", "=", `${userSession.spaceId}`], sort: "sort_no desc"})
131
+ // console.log(`find categories`, new Date().getTime() - sc)
132
+ for (const item of categories) {
133
+ if(item.app){
134
+ item.app__expand = appsMap.get(item.app)
135
+ }else{
136
+ item.app__expand = {}
133
137
  }
134
- `}
135
- )
136
- let currentAppCategories = [];
137
- if(appId == "approve_workflow"){
138
- currentAppCategories = categoriesData.data.categories;
139
- }else{
140
- currentAppCategories = lodash.filter(categoriesData.data.categories, (category) => {
141
- if(category.app__expand?.code == appId) return true;
142
- else return false;
143
- })
144
- if(currentAppCategories.length == 0) {
145
- //如果没有任何分类绑定该app,则该app显示所有分类(该规则为审批王规则)
146
- currentAppCategories = categoriesData.data.categories;
147
138
  }
148
- }
149
- let categoriesIds = lodash.map(currentAppCategories, '_id');
150
- if (!hasFlowsPer) {
151
- const flowIds = await WorkflowManager.getMyAdminOrMonitorFlows(userSession.spaceId, userSession.userId);
152
- hasFlowsPer = flowIds && flowIds.length > 0;
153
- if (hasFlowsPer) {
154
- let query = `
155
- query {
156
- flows(filters:[["_id","in",${JSON.stringify(flowIds)}],"and",["category","in",${JSON.stringify(categoriesIds)}], "and", ["state", "=", "enabled"]],sort:"sort_no desc,name"){
157
- _id,
158
- name,
159
- category__expand{_id,name}
160
- }
161
- }
162
- `
163
- data = await objectql.broker.call('api.graphql', {
164
- query }
165
- )
139
+
140
+ let currentAppCategories = [];
141
+ if(appId == "approve_workflow"){
142
+ currentAppCategories = categories;
143
+ }else{
144
+ currentAppCategories = lodash.filter(categories, (category) => {
145
+ if(category.app__expand?.code == appId) return true;
146
+ else return false;
147
+ })
148
+ if(currentAppCategories.length == 0) {
149
+ //如果没有任何分类绑定该app,则该app显示所有分类(该规则为审批王规则)
150
+ currentAppCategories = categories;
151
+ }
166
152
  }
167
- } else {
168
- data = await objectql.broker.call('api.graphql', {
169
- query: `
170
- query {
171
- flows(filters:[["space", "=", "${userSession.spaceId}"],["category","in",${JSON.stringify(categoriesIds)}],["state", "=", "enabled"]],sort:"sort_no desc"){
172
- _id,
173
- name,
174
- category__expand{_id,name}
175
- }
153
+ let categoriesIds = lodash.map(currentAppCategories, '_id');
154
+ // console.log(`getCategoriesMonitor categoriesIds`, categoriesIds)
155
+ // console.log(`getCategoriesMonitor hasFlowsPer`, hasFlowsPer)
156
+ let flows = [];
157
+ if (!hasFlowsPer) {
158
+ const flowIds = await WorkflowManager.getMyAdminOrMonitorFlows(userSession.spaceId, userSession.userId);
159
+ hasFlowsPer = flowIds && flowIds.length > 0;
160
+ if (hasFlowsPer) {
161
+ flows = await objectql.getObject('flows').find({
162
+ filters: [["_id","in", flowIds],"and",["category","in", categoriesIds], "and", ["state", "=", "enabled"]],
163
+ fields: ['_id', 'name', 'category', 'sort_no'],
164
+ sort:"sort_no desc"
165
+ });
166
+ }
167
+ } else {
168
+ // const s1 = new Date().getTime();
169
+ flows = await objectql.getObject('flows').find({
170
+ filters:[["space", "=", userSession.spaceId],["category","in", categoriesIds],["state", "=", "enabled"]],
171
+ fields: ['_id', 'name', 'category', 'sort_no'],
172
+ sort:"sort_no desc"
173
+ })
174
+ // console.log(`find flows`, new Date().getTime() - s1)
175
+ }
176
+ if (flows.length > 0) {
177
+ const categoriesMap = new Map(Object.entries(lodash.keyBy(categories, '_id')));
178
+
179
+ for (const item of flows) {
180
+ if(item.category){
181
+ item.category__expand = categoriesMap.get(item.category)
182
+ }else{
183
+ item.category__expand = {}
176
184
  }
177
- `}
178
- )
179
- }
180
- if (data.data && data.data.flows && data.data.flows.length > 0) {
181
- const categoryGroups = lodash.groupBy(data.data.flows, 'category__expand.name');
182
- lodash.each(categoryGroups, (v, k) => {
183
- const flowGroups = lodash.groupBy(v, 'name');
184
- const flows = [];
185
- const categoryValue = `/app/${appId}/instances/view/none?side_object=instances&side_listview_id=monitor&additionalFilters=['category','=',${v[0].category__expand?"'" + v[0].category__expand._id + "'":null}]&flowId=&categoryId=${v[0].category__expand && v[0].category__expand._id}`;
186
- let categoryIsUnfolded = false;
187
- lodash.each(flowGroups, (v2, k2) => {
188
- const flowValue = `/app/${appId}/instances/view/none?side_object=instances&side_listview_id=monitor&additionalFilters=['flow','=','${v2[0]._id}']&flowId=${v2[0]._id}&categoryId=${v[0].category__expand && v[0].category__expand._id}`;
189
- let flowIsUnfolded = false;
190
- if(currentUrl == flowValue){
191
- flowIsUnfolded = true;
185
+ }
186
+
187
+ const categoryGroups = lodash.groupBy(flows, 'category__expand.name');
188
+ lodash.each(categoryGroups, (v, k) => {
189
+ const flowGroups = lodash.groupBy(v, 'name');
190
+ const flows = [];
191
+ const categoryValue = `/app/${appId}/instances/view/none?side_object=instances&side_listview_id=monitor&additionalFilters=['category','=',${v[0].category__expand?"'" + v[0].category__expand._id + "'":null}]&flowId=&categoryId=${v[0].category__expand && v[0].category__expand._id}`;
192
+ let categoryIsUnfolded = false;
193
+ lodash.each(flowGroups, (v2, k2) => {
194
+ const flowValue = `/app/${appId}/instances/view/none?side_object=instances&side_listview_id=monitor&additionalFilters=['flow','=','${v2[0]._id}']&flowId=${v2[0]._id}&categoryId=${v[0].category__expand && v[0].category__expand._id}`;
195
+ let flowIsUnfolded = false;
196
+ if(currentUrl == flowValue){
197
+ flowIsUnfolded = true;
198
+ categoryIsUnfolded = true;
199
+ monitorIsUnfolded = true;
200
+ }
201
+ flows.push({
202
+ label: k2,
203
+ flow_name: k2,
204
+ options: {
205
+ level: 3,
206
+ value: v2[0]._id,
207
+ name: 'flow',
208
+ to: flowValue,
209
+ },
210
+ value: flowValue,
211
+ unfolded: flowIsUnfolded
212
+ })
213
+ })
214
+ if(currentUrl == categoryValue){
192
215
  categoryIsUnfolded = true;
193
216
  monitorIsUnfolded = true;
194
217
  }
195
- flows.push({
196
- label: k2,
197
- flow_name: k2,
218
+ output.push({
219
+ label: k == 'null' || k == 'undefined' || !k? "未分类" : k,
220
+ children: flows,
221
+ category_name: k == 'null' || k == 'undefined' || !k ? "未分类" : k,
198
222
  options: {
199
- level: 3,
200
- value: v2[0]._id,
201
- name: 'flow',
202
- to: flowValue,
223
+ level: 2,
224
+ value: v[0].category__expand && v[0].category__expand._id,
225
+ name: 'category',
226
+ to: categoryValue,
203
227
  },
204
- value: flowValue,
205
- unfolded: flowIsUnfolded
228
+ value: categoryValue,
229
+ unfolded: categoryIsUnfolded
206
230
  })
207
231
  })
208
- if(currentUrl == categoryValue){
209
- categoryIsUnfolded = true;
210
- monitorIsUnfolded = true;
211
- }
212
- output.push({
213
- label: k == 'null' || k == 'undefined' || !k? "未分类" : k,
214
- children: flows,
215
- category_name: k == 'null' || k == 'undefined' || !k ? "未分类" : k,
216
- options: {
217
- level: 2,
218
- value: v[0].category__expand && v[0].category__expand._id,
219
- name: 'category',
220
- to: categoryValue,
221
- },
222
- value: categoryValue,
223
- unfolded: categoryIsUnfolded
224
- })
225
- })
226
- output = lodash.sortBy(output, [function (o) {
227
- return lodash.findIndex(categoriesData.data.categories, (e) => {
228
- return e._id == o.options.value;
229
- });
230
- }]);
232
+ output = lodash.sortBy(output, [function (o) {
233
+ return lodash.findIndex(categories, (e) => {
234
+ return e._id == o.options.value;
235
+ });
236
+ }]);
237
+ }
238
+ } catch (error) {
239
+ console.log(error)
231
240
  }
241
+
232
242
  return {
233
243
  schema: output,
234
244
  hasFlowsPer: hasFlowsPer,
@@ -242,9 +252,15 @@ router.get('/api/:appId/workflow/nav', requireAuthentication, async function (re
242
252
  currentUrl = currentUrl.substring(currentUrl.indexOf("/app"));
243
253
  let userSession = req.user;
244
254
  const { appId } = req.params;
255
+ // const s1 = new Date().getTime();
245
256
  let inboxResult = await getCategoriesInbox(userSession, req, currentUrl);
257
+ // console.log(`inboxResult time`, new Date().getTime() - s1);
258
+ // const s2 = new Date().getTime();
246
259
  let monitorResult = await getCategoriesMonitor(userSession, req, currentUrl)
260
+ // console.log(`monitorResult time`, new Date().getTime() - s2);
261
+ // const s3 = new Date().getTime();
247
262
  let draftCount = await getDraftCount(userSession,req);
263
+ // console.log(`getDraftCount time`, new Date().getTime() - s3);
248
264
 
249
265
  var options = [
250
266
  {
@@ -289,6 +289,11 @@
289
289
  (field.is_list_display ? ' is_list_display' : '') +
290
290
  (field.is_searchable ? ' is_searchable' : '')
291
291
  };
292
+
293
+ if(field.formula){
294
+ tpl.value = `$${field.formula}`;
295
+ }
296
+
292
297
  switch (field.type) {
293
298
  case "input":
294
299
  if (field.is_textarea) {
@@ -339,15 +344,15 @@
339
344
  case "user":
340
345
  const useTpl = {
341
346
  "type": "steedos-field",
342
- "id": "u:9f4486c22f52",
343
- "field": JSON.stringify({
347
+ "id": `u:${field.code}`,
348
+ "config": {
344
349
  name: field.code,
345
350
  label: field.name,
346
351
  reference_to: "space_users",
347
352
  reference_to_field: 'user',
348
353
  multiple: field.is_multiselect,
349
354
  type: "lookup"
350
- }),
355
+ },
351
356
  }
352
357
  // const useTpl = await lookupToAmis(
353
358
  // {
@@ -366,14 +371,14 @@
366
371
  case "group":
367
372
  const orgTpl = {
368
373
  "type": "steedos-field",
369
- "id": "u:9f4486c22f52",
370
- "field": JSON.stringify({
374
+ "id": `u:${field.code}`,
375
+ "config": {
371
376
  name: field.code,
372
377
  label: field.name,
373
378
  reference_to: "organizations",
374
379
  multiple: field.is_multiselect,
375
380
  type: "lookup"
376
- })
381
+ }
377
382
  }
378
383
 
379
384
  // const orgTpl = await lookupToAmis(
@@ -158,7 +158,6 @@ function transformFormFields(amisField) {
158
158
  amisField = transformFormSField(amisField);
159
159
  };
160
160
 
161
-
162
161
  if(amisField.type === 'steedos-field'){
163
162
  const sfield = {
164
163
  _id: amisField.config.name,
@@ -171,7 +170,9 @@ function transformFormFields(amisField) {
171
170
  is_list_display: amisField.config.is_list_display,
172
171
  is_searchable: amisField.config.is_searchable,
173
172
  type: 'steedos-field',
174
- config: amisField.config
173
+ config: amisField.config,
174
+ visibleOn: amisField.visibleOn,
175
+ requiredOn: amisField.requiredOn
175
176
  }
176
177
 
177
178
  let tempConfig = amisField.config;
@@ -195,7 +196,9 @@ function transformFormFields(amisField) {
195
196
  is_required: amisField.required == true ? true : false,
196
197
  is_multiselect: amisField.multiple == true ? true : false,
197
198
  is_list_display: _.includes(amisField.className, "is_list_display"),
198
- is_searchable: _.includes(amisField.className, "is_searchable")
199
+ is_searchable: _.includes(amisField.className, "is_searchable"),
200
+ visibleOn: amisField.visibleOn,
201
+ requiredOn: amisField.requiredOn
199
202
  }
200
203
 
201
204
  switch (amisField.type) {
@@ -461,6 +464,8 @@ function transformFormFields(amisField) {
461
464
  is_wide: _.includes(amisField.className, "is_wide"),
462
465
  is_list_display: _.includes(amisField.className, "is_list_display"),
463
466
  is_searchable: _.includes(amisField.className, "is_searchable"),
467
+ visibleOn: amisField.visibleOn,
468
+ requiredOn: amisField.requiredOn
464
469
  }
465
470
 
466
471
  if (tempConfig.reference_to === "organizations") {
@@ -489,6 +494,8 @@ function transformFormFields(amisField) {
489
494
  is_wide: _.includes(amisField.className, "is_wide"),
490
495
  is_list_display: _.includes(amisField.className, "is_list_display"),
491
496
  is_searchable: _.includes(amisField.className, "is_searchable"),
497
+ visibleOn: amisField.visibleOn,
498
+ requiredOn: amisField.requiredOn
492
499
  }
493
500
 
494
501
  if (tempField.reference_to === "organizations") {
@@ -503,6 +510,7 @@ function transformFormFields(amisField) {
503
510
 
504
511
  }
505
512
 
513
+
506
514
  return formFieldsItem
507
515
  }
508
516
 
@@ -531,7 +539,6 @@ module.exports = {
531
539
  const form = await objectql.getObject('forms').findOne(this.id);
532
540
  delete form.historys;
533
541
 
534
-
535
542
  // 数据库更新操作:将forms表current的fields字段更新为最终数组
536
543
  form.current.fields = getFinalFormFields(inputFields);
537
544
  form.current.amis_schema = this.doc.amis_schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos-labs/plugin-workflow",
3
- "version": "3.0.1-beta.4",
3
+ "version": "3.0.1-beta.5",
4
4
  "main": "package.service.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -370,4 +370,9 @@ tbody .color-priority-muted *{
370
370
 
371
371
  .steedos-amis-instance-view-body .approve-button{
372
372
  z-index: 900;
373
+ }
374
+
375
+ .instances-sidebar-wrapper{
376
+ overflow-y: auto;
377
+ height: calc(100vh - 82px);
373
378
  }