@steedos/standard-object-database 2.6.2-beta.3 → 2.6.2-beta.30

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.
@@ -37,6 +37,8 @@ fields:
37
37
  value: markdown
38
38
  - label: Select
39
39
  value: select
40
+ - label: Color
41
+ value: color
40
42
  - label: Checkbox
41
43
  value: boolean
42
44
  - label: Toggle
@@ -38,6 +38,8 @@ fields:
38
38
  value: markdown
39
39
  - label: 选择框
40
40
  value: select
41
+ - label: 颜色
42
+ value: color
41
43
  - label: 复选框
42
44
  value: boolean
43
45
  - label: 开关
@@ -35,8 +35,8 @@ fields:
35
35
  defaultValue: true
36
36
  visible:
37
37
  type: boolean
38
- omit: true
39
- hidden: true
38
+ # omit: true
39
+ # hidden: true
40
40
  label: Visible
41
41
  sort_no: 150
42
42
  'on':
@@ -66,6 +66,8 @@ fields:
66
66
  value: markdown
67
67
  - label: Select
68
68
  value: select
69
+ - label: Color
70
+ value: color
69
71
  - label: Boolean
70
72
  value: boolean
71
73
  - label: Toggle
@@ -431,7 +433,7 @@ fields:
431
433
  # group: Advanced
432
434
  sort_no: 270
433
435
  options:
434
- type: grid
436
+ type: table
435
437
  label: Options
436
438
  is_wide: true
437
439
  inlineHelpText: The label and value of each option cannot be empty. Set the background color to FFFFFF in hexadecimal format.
@@ -454,7 +456,7 @@ fields:
454
456
  required: true
455
457
  options.$.color:
456
458
  label: Color
457
- type: text
459
+ type: color
458
460
  required: false
459
461
  options.$.description:
460
462
  label: Description
@@ -64,7 +64,7 @@ fields:
64
64
  }
65
65
  group: general_information
66
66
  buttons:
67
- type: grid
67
+ type: table
68
68
  blackbox: true
69
69
  is_wide: true
70
70
  depend_on:
@@ -76,6 +76,31 @@ fields:
76
76
  reference_to_field: name
77
77
  depend_on:
78
78
  - object_name
79
+ amis:
80
+ {
81
+ "autoComplete":
82
+ {
83
+ "method": "get",
84
+ "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/actions/options",
85
+ "sendOn": "!!this.object_name",
86
+ "headers":
87
+ {
88
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}",
89
+ },
90
+ "cache": 120000,
91
+ },
92
+ "source":
93
+ {
94
+ "method": "get",
95
+ "url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/actions/options",
96
+ "sendOn": "!!this.object_name",
97
+ "headers":
98
+ {
99
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}",
100
+ },
101
+ "cache": 120000,
102
+ },
103
+ }
79
104
  buttons.$.visible_on:
80
105
  label: Visible on
81
106
  type: textarea
@@ -85,10 +110,13 @@ fields:
85
110
  blackbox: true
86
111
  is_wide: true
87
112
  hidden: false
113
+ label: 字段分组
88
114
  field_groups.$.group_name:
89
115
  type: text
116
+ label: 名称
90
117
  field_groups.$.visible_on:
91
118
  type: text
119
+ label: 显示条件
92
120
  fields:
93
121
  type: grid
94
122
  is_wide: true
@@ -220,7 +220,7 @@ fields:
220
220
  visible_on: "{{global.mode ==='read' ? true : false}}"
221
221
  mobile_columns:
222
222
  label: Mobile Columns
223
- type: grid
223
+ type: table
224
224
  is_wide: true
225
225
  depend_on:
226
226
  - object_name
@@ -234,8 +234,16 @@ fields:
234
234
  type: lookup
235
235
  multiple: false
236
236
  is_wide: false
237
+ required: true
238
+ depend_on:
239
+ - object_name
237
240
  reference_to: object_fields
238
241
  reference_to_field: name
242
+ enable_enhanced_lookup: false
243
+ filtersFunction: !<tag:yaml.org,2002:js/function> |-
244
+ function(filters, values){
245
+ return ['object', '=', values.object_name]
246
+ }
239
247
  searchable_fields:
240
248
  label: Searchable Fields
241
249
  type: grid
@@ -34,29 +34,36 @@
34
34
  "size": "lg",
35
35
  "body": [
36
36
  {
37
- "type": "steedos-input-table",
38
- "fields": [
37
+ "type": "form",
38
+ "mode": "normal",
39
+ "body": [
39
40
  {
40
- "name": "group_name",
41
- "label": "名称",
42
- "type": "text",
43
- "id": "u:31952daa443c"
44
- },
45
- {
46
- "name": "visible_on",
47
- "label": "显示条件",
48
- "type": "text",
49
- "id": "u:8d7551abcd28",
50
- "value": null
41
+ "type": "steedos-input-table",
42
+ "fields": [
43
+ {
44
+ "name": "group_name",
45
+ "label": "名称",
46
+ "type": "text",
47
+ "id": "u:31952daa443c"
48
+ },
49
+ {
50
+ "name": "visible_on",
51
+ "label": "显示条件",
52
+ "type": "text",
53
+ "id": "u:8d7551abcd28",
54
+ "value": null
55
+ }
56
+ ],
57
+ "name": "groups",
58
+ "addable": true,
59
+ "editable": true,
60
+ "removable": true,
61
+ "draggable": false,
62
+ "showIndex": false,
63
+ "id": "u:776ec89804c0",
64
+ "label": ""
51
65
  }
52
- ],
53
- "name": "groups",
54
- "addable": true,
55
- "editable": true,
56
- "removable": true,
57
- "draggable": false,
58
- "showIndex": false,
59
- "id": "u:776ec89804c0"
66
+ ]
60
67
  }
61
68
  ],
62
69
  "onEvent": {
@@ -182,86 +189,90 @@
182
189
  {
183
190
  "type": "tpl",
184
191
  "tpl": "<p><strong>${label}</strong> ${designObjectLabel}<span style=\"color: rgb(149, 165, 166);\">${_name}</span></p>",
185
- "className": "w-4/5 field-amplify",
186
- "inline": true,
187
- "onEvent": {
188
- "click": {
189
- "actions": [
190
- {
191
- "actionType": "dialog",
192
- "dialog": {
193
- "type": "dialog",
194
- "title": "编辑字段",
195
- "data": {
196
- "appId": "${appId}",
197
- "global": "${global}",
198
- "context": "${context}",
199
- "designObjectName": "${designObjectName}",
200
- "_master": "${_master}",
201
- "_id": "${_id}"
202
- },
203
- "body": [
192
+ "className": "w-4/5",
193
+ "inline": true
194
+ },
195
+ {
196
+ "type": "action",
197
+ "className": "w-4/5 mr-7",
198
+ "label": "",
199
+ "id": "steedos-field-edit-button",
200
+ "icon": "fa fa-pencil",
201
+ "level": "link",
202
+ "actionType": "dialog",
203
+ "dialog": {
204
+ "title": "编辑字段",
205
+ "body": [
206
+ {
207
+ "type": "steedos-object-form",
208
+ "label": "对象表单",
209
+ "objectApiName": "object_fields",
210
+ "recordId": "${_id}",
211
+ "mode": "edit",
212
+ "defaultData": {
213
+ "name": "",
214
+ "shared": false,
215
+ "object": "${designObjectName}"
216
+ },
217
+ "fields": [
218
+ "label",
219
+ "readonly",
220
+ "is_wide",
221
+ "visible_on"
222
+ ],
223
+ "fieldsExtend": {
224
+ "label": {
225
+ "is_wide": true,
226
+ "group": ""
227
+ },
228
+ "readonly": {
229
+ "group": ""
230
+ },
231
+ "is_wide": {
232
+ "group": ""
233
+ },
234
+ "visible_on": {
235
+ "group": ""
236
+ }
237
+ },
238
+ "id": "u:b71796d3cb8c",
239
+ "className": "mb-4",
240
+ "apiRequestAdaptor": "api.data.query = api.data.query.replace('object_fields__update', 'object_fields__upsert')",
241
+ "onEvent": {
242
+ "submitSucc": {
243
+ "weight": 0,
244
+ "actions": [
204
245
  {
205
- "type": "steedos-object-form",
206
- "label": "对象表单",
207
- "objectApiName": "object_fields",
208
- "recordId": "${_id}",
209
- "mode": "edit",
210
- "defaultData": {
211
- "name": "",
212
- "shared": false,
213
- "object": "${designObjectName}"
214
- },
215
- "fields": [
216
- "label",
217
- "readonly",
218
- "is_wide"
219
- ],
220
- "fieldsExtend": {
221
- "label": {
222
- "is_wide": true,
223
- "group": ""
224
- },
225
- "readonly": {
226
- "group": ""
227
- },
228
- "is_wide": {
229
- "group": ""
230
- }
231
- },
232
- "id": "u:b71796d3cb8c",
233
- "className": "mb-4",
234
- "apiRequestAdaptor": "api.data.query = api.data.query.replace('object_fields__update', 'object_fields__upsert')",
235
- "onEvent": {
236
- "submitSucc": {
237
- "weight": 0,
238
- "actions": [
239
- {
240
- "actionType": "custom",
241
- "script": "setTimeout(() => {\n doAction({\n \"actionType\": \"broadcast\",\n \"args\": {\n \"eventName\": \"@data.changed.object_fields\"\n }\n });\n}, 500);\n\n\n"
242
- }
243
- ]
244
- }
245
- }
246
+ "actionType": "custom",
247
+ "script": "setTimeout(() => {\n doAction({\n \"actionType\": \"broadcast\",\n \"args\": {\n \"eventName\": \"@data.changed.object_fields\"\n }\n });\n}, 500);\n\n\n"
246
248
  }
247
- ],
248
- "showCloseButton": true,
249
- "showErrorMsg": true,
250
- "showLoading": true,
251
- "closeOnEsc": false,
252
- "dataMapSwitch": false,
253
- "size": "md",
254
- "id": "u:066b3884bdd8"
249
+ ]
255
250
  }
256
251
  }
257
- ]
258
- }
259
- }
252
+ }
253
+ ],
254
+ "type": "dialog",
255
+ "data": {
256
+ "appId": "${appId}",
257
+ "global": "${global}",
258
+ "context": "${context}",
259
+ "designObjectName": "${designObjectName}",
260
+ "_master": "${_master}",
261
+ "_id": "${_id}"
262
+ },
263
+ "showCloseButton": true,
264
+ "showErrorMsg": true,
265
+ "showLoading": true,
266
+ "closeOnEsc": false,
267
+ "dataMapSwitch": false,
268
+ "size": "md",
269
+ "id": "u:066b3884bdd8"
270
+ },
271
+ "size": "xs"
260
272
  }
261
273
  ],
262
274
  "bodyClassName": "h-7 flex justify-between items-center p-0 pl-10 my-2",
263
- "toolbar": [
264
- ],
275
+ "toolbar": [],
265
276
  "className": "mb-0 border-0 bg-none card",
266
277
  "id": "u:296298da1bef"
267
278
  },
@@ -290,8 +301,7 @@
290
301
  },
291
302
  "requestAdaptor": "var graphqlOrder = \"\";\n//先修改字段,使系统对象自行自定义\n//根据design_field,修改对象字段的sort_no与groups\nvar index = 1;\n_.forEach(api.data.design_field, function (items, key) {\n let group = key;\n if (key == \"未分组\" || key == \"隐藏\") {\n group = null;\n }\n _.forEach(items, function (item) {\n const field = _.find(api.data.fields, { 'id': item });\n //如果是在隐藏分组里的字段,就给visible_on属性赋予{{false}};如果不在隐藏分组里,就判断来自数据库内的visible_on属性是不是{{false}},是就清除,不是就保持不变\n const visible_on = key == \"隐藏\" ? \"{{false}}\" : (field.attr_visible_on == \"{{false}}\" ? \"{{true}}\" : field.attr_visible_on);\n let docJson = {\n sort_no: index * 10,\n group, visible_on\n }\n if (field.id == field._id && field.is_system) {\n docJson = {\n object: api.data.$self.designObjectName,\n type: field.type,\n _name: field._name,\n label: field.label,\n sort_no: index * 10,\n group,\n visible_on,\n is_system: field.is_system\n }\n }\n if (key != \"隐藏\") {\n docJson.hidden = false;\n }\n let itemOrder = 'upsert' + index + ':object_fields__upsert(id:\"' + item + '\" , doc:' + JSON.stringify(JSON.stringify(docJson)) + '){_id}\\n';\n graphqlOrder += itemOrder;\n index++;\n })\n})\n\n//根据groups,修改对象的字段分组field_groups\nvar field_groups = _.cloneDeep(api.data.groups);\n_.remove(field_groups, { is_default: true });\n_.remove(field_groups, { is_hidden: true });\nfield_groups = field_groups.map(function (group) {\n return _.omit(group, 'id');\n})\nconst keys = _.keys(api.data.design_field);\nfield_groups = _.sortBy(field_groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\nconst groupOrder = 'upsert0:objects__upsert(id:\"' + api.data.$self.designObjectId + '\" , doc:' + JSON.stringify(JSON.stringify({ field_groups, name: api.data.$self.designObjectName })) + ') {_id}';\ngraphqlOrder += groupOrder;\n\n\ngraphqlOrder = 'mutation {' + graphqlOrder + '}';\nreturn {\n ...api,\n data: {\n query: graphqlOrder\n }\n}",
292
303
  "adaptor": "if (payload.errors) {\n payload.status = 2;\n payload.msg = window.t ? window.t(payload.errors[\n 0\n ].message) : payload.errors[\n 0\n ].message;\n}\nreturn payload;",
293
- "messages": {
294
- },
304
+ "messages": {},
295
305
  "data": {
296
306
  "design_field": "${design_field}",
297
307
  "groups": "${groups}",
@@ -333,14 +343,12 @@
333
343
  "headers": {
334
344
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
335
345
  },
336
- "messages": {
337
- },
346
+ "messages": {},
338
347
  "requestAdaptor": "",
339
348
  "adaptor": "//筛选出可编辑的字段\r\nvar oldFields = _.filter(payload.data.fields, function (obj) { return obj.recordPermissions.allowEdit; });\r\n//将group为空的字段分为未分组的组中,将系统字段的_id改为对象名.字段名\r\noldFields = _.map(oldFields, function (obj) {\r\n obj.originId = obj._id;\r\n if (obj.hidden || obj.visible_on == \"{{false}}\") {\r\n obj.group = \"隐藏\";\r\n }else if (obj.group === null) {\r\n obj.group = \"未分组\";\r\n }\r\n if (obj.is_system) {\r\n obj._id = api.data.designObjectName + \".\" + obj._name;\r\n }\r\n return obj;\r\n});\r\n\r\n//整合出字段的属性集合\r\nconst fields = oldFields.map((field) => {\r\n return {\r\n \"id\": field._id,//用与steedos-board组件的关系分辨\r\n \"_name\": field._name,\r\n \"label\": field.label,\r\n \"_id\": field.originId,//用于打开steedos-objectform\r\n \"columnSpan\": field.is_wide ? 2 : 1,\r\n \"is_system\": field.is_system,\r\n \"type\": field.type,\r\n \"attr_visible_on\": field.visible_on\r\n }\r\n})\r\n\r\n//从字段的group属性中,整合出字段分组的属性集合\r\nlet field_groups = _.map(_.uniqBy(oldFields, \"group\"), function (obj) {\r\n return {\r\n \"id\": obj.group,\r\n \"group_name\": obj.group,\r\n \"visible_on\": \"\"\r\n };\r\n});\r\n\r\n//合并对象上的field_groups与字段上的group\r\nlet groups = _.unionBy(api.data.field_groups, field_groups, 'id');\r\n\r\n//判断是否第一次调用接口,不是的话(说明是触发了datachange事件),返回fields与fieldUpdateData\r\nif (api.data.dataInitialed) {\r\n const eventData = api.data.eventData;\r\n let fieldUpdateData = \"\";\r\n const fieldForGroup = api.data.fieldForGroup;\r\n let fieldForGroupLength = 0;\r\n _.forIn(fieldForGroup, function (value, key) {\r\n fieldForGroupLength += value.length;\r\n });\r\n if (fieldForGroupLength < fields.length) {\r\n fieldUpdateData = {\r\n type: \"insert\",\r\n id: eventData.result.data.recordId\r\n }\r\n } else if (fieldForGroupLength > fields.length) {\r\n fieldUpdateData = {\r\n type: \"delete\",\r\n id: eventData._id\r\n }\r\n }\r\n return payload = {\r\n data: {\r\n fields,\r\n fieldUpdateData\r\n }\r\n }\r\n}\r\n\r\n//整合字段与分组的关系\r\nconst oldFieldsInGroups = _.groupBy(oldFields, \"group\");\r\nlet fieldForGroup = _.mapValues(_.groupBy(groups, \"id\"), function (group,key) {\r\n if (oldFieldsInGroups[key]) {\r\n return _.map(oldFieldsInGroups[key], function (obj) {\r\n return obj._id;\r\n });\r\n } else {\r\n return [];\r\n }\r\n});\r\n\r\n//未分组 放在所有分组开头,隐藏 放在所有分组最后\r\nconst defaultGroup = fieldForGroup[\"未分组\"];\r\nconst hiddenGroup = fieldForGroup[\"隐藏\"];\r\ndelete fieldForGroup[\"未分组\"];\r\ndelete fieldForGroup[\"隐藏\"];\r\nfieldForGroup = _.merge({ \"未分组\": defaultGroup }, fieldForGroup, { \"隐藏\": hiddenGroup });\r\n\r\n//根据fieldForGroup调整groups顺序,设置分组与保存时需要groups按照顺序\r\nconst keys = _.keys(fieldForGroup);\r\ngroups = _.sortBy(groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\r\n\r\nreturn payload = {\r\n data: {\r\n fields,\r\n groups,\r\n fieldForGroup,\r\n dataInitialed: true\r\n }\r\n};",
340
349
  "sendOn": "!!this.designObjectId"
341
350
  },
342
- "messages": {
343
- },
351
+ "messages": {},
344
352
  "onEvent": {
345
353
  "fetchInited": {
346
354
  "actions": [
@@ -368,13 +376,11 @@
368
376
  "headers": {
369
377
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
370
378
  },
371
- "messages": {
372
- },
379
+ "messages": {},
373
380
  "requestAdaptor": "",
374
381
  "adaptor": "const field_groups = payload.data.objects[0] && _.map(payload.data.objects[0].field_groups, function (obj) {\r\n return {\r\n \"id\": obj.group_name,\r\n \"group_name\": obj.group_name,\r\n \"visible_on\": obj.visible_on\r\n }\r\n});\r\nfield_groups.unshift({\r\n id: \"隐藏\",\r\n group_name: \"隐藏\",\r\n visible_on: \"\",\r\n is_hidden: true\r\n});\r\nfield_groups.unshift({\r\n id: \"未分组\",\r\n group_name: \"未分组\",\r\n visible_on: \"\",\r\n is_default: true\r\n});\r\n\r\n\r\n\r\nconst designObjectId = payload.data.objects[0] && payload.data.objects[0]._id;\r\nreturn payload = {\r\n data: {\r\n field_groups,\r\n designObjectId,\r\n designObjectLabel: payload.data.objects[0] && payload.data.objects[0].label,\r\n _master: {\r\n recordId: designObjectId\r\n }\r\n }\r\n}"
375
382
  },
376
- "messages": {
377
- },
383
+ "messages": {},
378
384
  "onEvent": {
379
385
  "@data.changed.object_fields": {
380
386
  "actions": [
@@ -394,8 +400,7 @@
394
400
  "body"
395
401
  ],
396
402
  "data": {
397
- "initialValues": {
398
- },
403
+ "initialValues": {},
399
404
  "appId": "builder",
400
405
  "title": "",
401
406
  "context": "${context}",
@@ -405,9 +410,6 @@
405
410
  "css": {
406
411
  ".antd-TplField p": {
407
412
  "margin": "0.625rem 0.625rem"
408
- },
409
- ".steedos-design-field li.p-1 .field-amplify:hover": {
410
- "font-size": "17px"
411
413
  }
412
414
  },
413
415
  "className": "steedos-design-field",
@@ -35,7 +35,7 @@ const validateOptionsValue = (value)=>{
35
35
 
36
36
  const validateOptionColorValue = (value)=>{
37
37
  if(value){
38
- const reg = /^[\da-f]{6}$/i;
38
+ const reg = /^(#)?[\da-f]{6}$/i;
39
39
  if(!reg.test(value)){
40
40
  throw new Error("object_fields_error_option_color_not_valid");
41
41
  }
@@ -369,7 +369,7 @@ module.exports = {
369
369
  if( doc.data_type === 'number' && !(_.isNumber(numberValue) && !_.isNaN(numberValue)) ){
370
370
  throw new Meteor.Error(500, "选择项中的选项值类型应该与数据类型值一致, 请输入合法的数值。");
371
371
  }
372
- console.log('doc==>',doc.data_type , value)
372
+ // console.log('doc==>',doc.data_type , value)
373
373
  if( doc.data_type === 'boolean' && ['true','false'].indexOf(value) < 0){
374
374
  throw new Meteor.Error(500, "选择项中的选项值类型应该与数据类型值一致, 请输入 true 或 false。");
375
375
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/standard-object-database",
3
- "version": "2.6.2-beta.3",
3
+ "version": "2.6.2-beta.30",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -11,9 +11,10 @@
11
11
  ],
12
12
  "description": "steedos package",
13
13
  "dependencies": {
14
- "@steedos-widgets/amis-lib": "^1.0.22"
14
+ "@steedos-widgets/amis-lib": "^1.0.22",
15
+ "@steedos/standard-objects": "2.6.2-beta.30"
15
16
  },
16
17
  "repository": {},
17
18
  "license": "MIT",
18
- "gitHead": "7842aa5d3023622c0e140009cfdd081180563bdd"
19
+ "gitHead": "d31db8c7862a211f37fd27d076f01f41cddc58a5"
19
20
  }
@@ -12,6 +12,7 @@ const packageLoader = require('@steedos/service-meteor-package-loader');
12
12
  const serviceObjectMixin = require('@steedos/service-object-mixin');
13
13
  const validator = require('validator');
14
14
  const triggers = require('./src/triggers');
15
+ const { checkAPIName } = require('@steedos/standard-objects').util
15
16
 
16
17
  /**
17
18
  * @typedef {import('moleculer').Context} Context Moleculer's Context
@@ -120,6 +121,19 @@ module.exports = {
120
121
  return object.update(id, data, userSession)
121
122
  },
122
123
  },
124
+ checkAPIName: {
125
+ params: {
126
+ objectName: { type: 'string' },
127
+ fieldName: { type: 'string' },
128
+ fieldValue: { type: 'string' },
129
+ recordId: { type: 'string', optional: true },
130
+ filters: { type: 'array', optional: true, },
131
+ },
132
+ async handler (ctx) {
133
+ const { objectName, fieldName, fieldValue, recordId, filters } = ctx.params;
134
+ await checkAPIName(objectName, fieldName, fieldValue, recordId, filters)
135
+ }
136
+ },
123
137
  },
124
138
 
125
139
  /**