@steedos/standard-object-database 2.6.7 → 2.6.8-beta.10

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.
@@ -209,4 +209,43 @@ Steedos.ObjectFieldManager.getSummaryFiltersOperation = function(field_type) {
209
209
  operations.push(optionals.equal, optionals.unequal);
210
210
  }
211
211
  return operations;
212
- };
212
+ };
213
+
214
+ (function () {
215
+ try {
216
+ var styleCss = $(`<style>
217
+ .defaultValue_field div:first-child{
218
+ flex-grow: 1;
219
+ }
220
+ .defaultValue_field .defaultValue_field_formula{
221
+ // margin: 4px;
222
+ }
223
+ .defaultValue_field .defaultValue_field_formula .antd-Form-label{
224
+ visibility: visible;
225
+ }
226
+
227
+ .defaultValue_field .defaultValue_field_formula_visible{
228
+ flex-grow: 1;
229
+ }
230
+ .defaultValue_field .defaultValue_field_formula_visible .antd-Form-label .antd-TplField{
231
+ visibility: visible;
232
+ }
233
+ .defaultValue_field .defaultValue_field_hidden{
234
+ display: none;
235
+ }
236
+ .defaultValue_field .defaultValue_field_formula_hidden{
237
+ flex-grow: 0;
238
+ }
239
+ .defaultValue_field .defaultValue_field_formula_hidden .antd-Form-label{
240
+ display: none;
241
+ }
242
+ .defaultValue_field .defaultValue_field_formula_hidden .antd-FormulaPicker-input{
243
+ display: none;
244
+ }
245
+
246
+ </style>`);
247
+ $("head").append(styleCss);
248
+ } catch (error) {
249
+ console.log(error);
250
+ }
251
+ })();
@@ -29,7 +29,7 @@ fields:
29
29
  value: text
30
30
  - label: Textarea
31
31
  value: textarea
32
- - label: Html
32
+ - label: Rich text
33
33
  value: html
34
34
  - label: Code
35
35
  value: code
@@ -163,6 +163,22 @@ fields:
163
163
  label: Description
164
164
  help:
165
165
  description:
166
+ auto_fill_mapping:
167
+ label: Auto Fill Mapping
168
+ help: When the data is selected, the field values in the reference object are automatically filled into the current form field according to the following mapping.
169
+ description:
170
+ auto_fill_mapping.$:
171
+ label: Auto Fill Mapping
172
+ help:
173
+ description:
174
+ auto_fill_mapping.$.from:
175
+ label: From:Fields in object that reference to
176
+ help:
177
+ description:
178
+ auto_fill_mapping.$.to:
179
+ label: To:Fields in the current form
180
+ help:
181
+ description:
166
182
  autonumber_enable_modify:
167
183
  label: Allow modification of numbers
168
184
  help:
@@ -297,7 +313,11 @@ fields:
297
313
  description:
298
314
  readonly:
299
315
  label: Readonly
300
- help:
316
+ help: It is read-only and does not appear on the form when you create or edit records.
317
+ description:
318
+ static:
319
+ label: Readonly and displayed while editing
320
+ help: Displays as read-only, but the field value can be set by default, autofill, or custom scripts when creating and editing records.
301
321
  description:
302
322
  hidden:
303
323
  label: Hidden
@@ -30,7 +30,7 @@ fields:
30
30
  value: text
31
31
  - label: 长文本
32
32
  value: textarea
33
- - label: Html文本
33
+ - label: 富文本
34
34
  value: html
35
35
  - label: 代码
36
36
  value: code
@@ -155,6 +155,22 @@ fields:
155
155
  label: 描述
156
156
  help:
157
157
  description:
158
+ auto_fill_mapping:
159
+ label: 自动填充规则
160
+ help: 选择数据后,将按以下映射关系将引用对象中的字段值自动填充到当前表单字段中。
161
+ description:
162
+ auto_fill_mapping.$:
163
+ label: 自动填充规则
164
+ help:
165
+ description:
166
+ auto_fill_mapping.$.from:
167
+ label: 从:引用对象中的字段
168
+ help:
169
+ description:
170
+ auto_fill_mapping.$.to:
171
+ label: 填充到:当前表单字段
172
+ help:
173
+ description:
158
174
  autonumber_enable_modify:
159
175
  label: 允许修改编号
160
176
  help:
@@ -281,7 +297,11 @@ fields:
281
297
  description:
282
298
  readonly:
283
299
  label: 只读
284
- help:
300
+ help: 只读,且新建和编辑记录时不显示在表单上
301
+ description:
302
+ static:
303
+ label: 只读且编辑时显示
304
+ help: 显示为只读,但是在新建和编辑记录时可以通过默认值,自动填充或自定义脚本设置该字段值
285
305
  description:
286
306
  hidden:
287
307
  label: 隐藏
@@ -1,55 +1,55 @@
1
1
  /*
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-08-05 14:17:44
4
- * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2023-05-12 09:33:27
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-02-27 15:41:42
6
6
  * @Description:
7
7
  */
8
- const objectql = require("@steedos/objectql");
9
- const objectName = "object_fields";
10
- Meteor.startup(function () {
11
- var _change, _remove, inited = false;
12
- _change = function (document) {
13
- // 重置字段权限延迟10秒,防止对象服务未上线
14
- setTimeout(()=>{
15
- try {
16
- // console.log("====resetAllPermissionSetFieldPermissions====")
17
- objectql.getSteedosSchema().broker.call(`permission_fields.resetAllPermissionSetFieldPermissions`, {
18
- objectName: document.object
19
- }, {
20
- meta: {
21
- user: {
22
- userId: document.owner,
23
- spaceId: document.space,
24
- company_id: document.company_id,
25
- company_ids: document.company_ids,
26
- }
27
- }
28
- });
29
- } catch (error) {
30
- console.error(`resetAllPermissionSetFieldPermissions`, error)
31
- }
32
- }, 1000 * 10)
33
- };
34
- Creator.getCollection(objectName).find({}, {
35
- fields: {
36
- created: 0,
37
- created_by: 0,
38
- modified: 0,
39
- modified_by: 0
40
- }
41
- }).observe({
42
- added: function (newDocument) {
43
- if (inited) {
44
- return _change(newDocument);
45
- }
46
- },
47
- changed: function (newDocument, oldDocument) {
48
- return _change(newDocument);
49
- },
50
- removed: function (oldDocument) {
51
- return _change(oldDocument);
52
- }
53
- });
54
- inited = true;
55
- });
8
+ // const objectql = require("@steedos/objectql");
9
+ // const objectName = "object_fields";
10
+ // Meteor.startup(function () {
11
+ // var _change, _remove, inited = false;
12
+ // _change = function (document) {
13
+ // // 重置字段权限延迟10秒,防止对象服务未上线
14
+ // setTimeout(()=>{
15
+ // try {
16
+ // // console.log("====resetAllPermissionSetFieldPermissions====")
17
+ // objectql.getSteedosSchema().broker.call(`permission_fields.resetAllPermissionSetFieldPermissions`, {
18
+ // objectName: document.object
19
+ // }, {
20
+ // meta: {
21
+ // user: {
22
+ // userId: document.owner,
23
+ // spaceId: document.space,
24
+ // company_id: document.company_id,
25
+ // company_ids: document.company_ids,
26
+ // }
27
+ // }
28
+ // });
29
+ // } catch (error) {
30
+ // console.error(`resetAllPermissionSetFieldPermissions`, error)
31
+ // }
32
+ // }, 1000 * 10)
33
+ // };
34
+ // Creator.getCollection(objectName).find({}, {
35
+ // fields: {
36
+ // created: 0,
37
+ // created_by: 0,
38
+ // modified: 0,
39
+ // modified_by: 0
40
+ // }
41
+ // }).observe({
42
+ // added: function (newDocument) {
43
+ // if (inited) {
44
+ // return _change(newDocument);
45
+ // }
46
+ // },
47
+ // changed: function (newDocument, oldDocument) {
48
+ // return _change(newDocument);
49
+ // },
50
+ // removed: function (oldDocument) {
51
+ // return _change(oldDocument);
52
+ // }
53
+ // });
54
+ // inited = true;
55
+ // });
@@ -1,56 +1,56 @@
1
1
  /*
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-08-05 14:17:44
4
- * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2023-05-13 17:09:31
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-02-27 15:48:50
6
6
  * @Description:
7
7
  */
8
- const objectql = require("@steedos/objectql");
9
- const objectName = "permission_objects";
10
- Meteor.startup(function () {
11
- var _change, _remove, inited = false;
12
- _change = function (document) {
13
- setTimeout(()=>{
14
- try {
15
- objectql.getSteedosSchema().broker.call(`permission_fields.resetFieldPermissions`, {
16
- permissionObjectId: document._id
17
- }, {
18
- meta: {
19
- user: {
20
- userId: document.owner,
21
- spaceId: document.space,
22
- company_id: document.company_id,
23
- company_ids: document.company_ids,
24
- }
25
- }
26
- });
27
- } catch (error) {
28
- console.error(`resetFieldPermissions`, error)
29
- }
30
- }, 1000 * 10)
31
- };
32
- Creator.getCollection(objectName).find({}, {
33
- fields: {
34
- created: 0,
35
- created_by: 0,
36
- modified: 0,
37
- modified_by: 0
38
- }
39
- }).observe({
40
- added: function (newDocument) {
41
- if (newDocument.copy_from) { // 通过复制简档创建的对象权限,不需要重置字段权限
42
- return;
43
- }
44
- if (inited) {
45
- return _change(newDocument);
46
- }
47
- },
48
- changed: function (newDocument, oldDocument) {
49
- return _change(newDocument);
50
- },
51
- // removed: function (oldDocument) {
52
- // return _change(oldDocument);
53
- // }
54
- });
55
- inited = true;
56
- });
8
+ // const objectql = require("@steedos/objectql");
9
+ // const objectName = "permission_objects";
10
+ // Meteor.startup(function () {
11
+ // var _change, _remove, inited = false;
12
+ // _change = function (document) {
13
+ // setTimeout(()=>{
14
+ // try {
15
+ // objectql.getSteedosSchema().broker.call(`permission_fields.resetFieldPermissions`, {
16
+ // permissionObjectId: document._id
17
+ // }, {
18
+ // meta: {
19
+ // user: {
20
+ // userId: document.owner,
21
+ // spaceId: document.space,
22
+ // company_id: document.company_id,
23
+ // company_ids: document.company_ids,
24
+ // }
25
+ // }
26
+ // });
27
+ // } catch (error) {
28
+ // console.error(`resetFieldPermissions`, error)
29
+ // }
30
+ // }, 1000 * 10)
31
+ // };
32
+ // Creator.getCollection(objectName).find({}, {
33
+ // fields: {
34
+ // created: 0,
35
+ // created_by: 0,
36
+ // modified: 0,
37
+ // modified_by: 0
38
+ // }
39
+ // }).observe({
40
+ // added: function (newDocument) {
41
+ // if (newDocument.copy_from) { // 通过复制简档创建的对象权限,不需要重置字段权限
42
+ // return;
43
+ // }
44
+ // if (inited) {
45
+ // return _change(newDocument);
46
+ // }
47
+ // },
48
+ // changed: function (newDocument, oldDocument) {
49
+ // return _change(newDocument);
50
+ // },
51
+ // // removed: function (oldDocument) {
52
+ // // return _change(oldDocument);
53
+ // // }
54
+ // });
55
+ // inited = true;
56
+ // });
@@ -199,9 +199,49 @@ fields:
199
199
  amis:
200
200
  disabledOn: "${is_system == true}"
201
201
  defaultValue:
202
- type: text
202
+ type: object
203
+ blackbox: true
203
204
  label: Default Value
204
205
  sort_no: 160
206
+ visible_on: "{{['autonumber','formula','summary','image','file'].indexOf(formData.type) > -1 ? false: true}}"
207
+ amis:
208
+ type: service
209
+ className:
210
+ antd-Form-item: true
211
+ antd-Form-item--normal: true
212
+ m-0: true
213
+ "md:border-b": global.mode === "read"
214
+ defaultValue_field: true
215
+ flex: true
216
+ schemaApi:
217
+ url: "${context.rootUrl}/service/api/object_fields/defaultValue/schema"
218
+ method: post
219
+ data:
220
+ object: ${object}
221
+ name: ${name}
222
+ options: ${options}
223
+ type: ${type}
224
+ reference_to: ${reference_to}
225
+ multiple: ${multiple}
226
+ filtersFunction: ${filtersFunction}
227
+ reference_to_field: ${reference_to_field}
228
+ mode: ${global.mode}
229
+ scale: ${scale}
230
+ _id: ${_id}
231
+ trackExpression: "${object},${options},${type},${reference_to},${reference_to_field},${multiple},${filtersFunction},${_id},${scale}"
232
+ headers:
233
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
234
+ # sendOn: "!!this.type"
235
+ onEvent:
236
+ fetchSchemaInited:
237
+ weight: 0
238
+ actions:
239
+ - actionType: "setValue"
240
+ componentId: "service_detail_page"
241
+ args:
242
+ value:
243
+ defaultValue: "${event.data.body[0].value}"
244
+ expression: "global.mode ==='read' && event.data.body[0].value"
205
245
  group:
206
246
  type: text
207
247
  label: Group
@@ -448,6 +488,14 @@ fields:
448
488
  amis:
449
489
  showIndex: true
450
490
  disabledOn: "${is_system == true}"
491
+ enableDialog: false
492
+ columns:
493
+ - label
494
+ - value
495
+ - name: color
496
+ width: 170
497
+ - name: description
498
+ width: 300
451
499
  options.$:
452
500
  label: Options
453
501
  blackbox: true
@@ -468,6 +516,52 @@ fields:
468
516
  label: Description
469
517
  type: text
470
518
  required: false
519
+ auto_fill_mapping:
520
+ type: table
521
+ label: Auto Fill Mapping
522
+ is_wide: true
523
+ inlineHelpText: When the data is selected, the field values in the reference object are automatically filled into the current form field according to the following mapping.
524
+ visible_on: "{{(formData.type === 'lookup' || formData.type === 'master_detail') && formData.reference_to && !!!formData.multiple}}"
525
+ sort_no: 280
526
+ amis:
527
+ enableDialog: false
528
+ disabledOn: "${is_system == true}"
529
+ auto_fill_mapping.$:
530
+ label: Auto Fill Mapping
531
+ blackbox: true
532
+ type: object
533
+ auto_fill_mapping.$.from:
534
+ label: From:Fields in object that reference to
535
+ type: lookup
536
+ reference_to: object_fields
537
+ reference_to_field: name
538
+ required: true
539
+ depend_on:
540
+ - reference_to
541
+ filtersFunction: !<tag:yaml.org,2002:js/function> |-
542
+ function (filters, values) {
543
+ if(values && values.reference_to){
544
+ return ['object', '=', values.reference_to]
545
+ }else{
546
+ return ['_id', '=', 'no']
547
+ }
548
+ }
549
+ auto_fill_mapping.$.to:
550
+ label: To:Fields in the current form
551
+ type: lookup
552
+ reference_to: object_fields
553
+ reference_to_field: name
554
+ required: true
555
+ depend_on:
556
+ - object
557
+ filtersFunction: !<tag:yaml.org,2002:js/function> |-
558
+ function (filters, values) {
559
+ if(values && values.object){
560
+ return ['object', '=', values.object]
561
+ }else{
562
+ return ['_id', '=', 'no']
563
+ }
564
+ }
471
565
  formula_blank_value:
472
566
  type: select
473
567
  label: Blank Field Handling
@@ -586,7 +680,7 @@ fields:
586
680
  sort_no: 320
587
681
  summary_filters:
588
682
  label: Filter Criteria
589
- type: 'grid'
683
+ type: 'table'
590
684
  inlineHelpText: Only records meeting certain criteria should be included in the calculation, all records should be included in the calculation while the criteria is empty.
591
685
  is_wide: true
592
686
  depend_on:
@@ -595,6 +689,8 @@ fields:
595
689
  sort_no: 330
596
690
  amis:
597
691
  disabledOn: "${is_system == true}"
692
+ inlineEditMode: true
693
+ showIndex: true
598
694
  summary_filters.$:
599
695
  label: Filter Criteria
600
696
  blackbox: true
@@ -724,7 +820,13 @@ fields:
724
820
  readonly:
725
821
  type: boolean
726
822
  label: Readonly
823
+ inlineHelpText: It is read-only and does not appear on the form when you create or edit records.
824
+ group: ui
825
+ static:
826
+ type: boolean
827
+ label: Readonly and displayed while editing
727
828
  group: ui
829
+ inlineHelpText: Displays as read-only, but the field value can be set by default, autofill, or custom scripts when creating and editing records.
728
830
  hidden:
729
831
  type: boolean
730
832
  label: Hidden
@@ -62,11 +62,11 @@ module.exports = {
62
62
  var data = newRecord || { _filters_type_controller: 'conditions' };
63
63
  //数据格式转换
64
64
  if (data) {
65
- data.columns = lodash.map(data.columns, 'field');
66
65
  data.sort = lodash.map(data.sort, (item) => {
67
66
  return `${item.field_name}:${item.order || 'asc'}`
68
67
  });
69
- data.mobile_columns = lodash.map(data.mobile_columns, 'field');
68
+
69
+ data.searchable_fields = lodash.map(data.searchable_fields, 'field');
70
70
 
71
71
  if (data.filters && lodash.isString(data.filters)) {
72
72
  try {
@@ -2,7 +2,7 @@
2
2
  * @Author: baozhoutaon@hotoa.com
3
3
  * @Date: 2022-03-29 20:33:44
4
4
  * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-11-19 17:06:18
5
+ * @LastEditTime: 2024-02-23 13:37:49
6
6
  * @Description:
7
7
  */
8
8
  module.exports = {
@@ -23,7 +23,6 @@ module.exports = {
23
23
  query: `mutation{objects__upsert(id: "${obj.name}", doc: ${JSON.stringify(JSON.stringify(obj))}){_id,name}}`
24
24
  }),
25
25
  success: function (data) {
26
- console.log(`data====>`, data)
27
26
  SteedosUI.notification.success({
28
27
  message: '对象已自定义。'
29
28
  });
@@ -42,6 +41,9 @@ module.exports = {
42
41
  Steedos.authRequest(url, options);
43
42
  },
44
43
  customVisible: function (object_name, record_id, permission, data) {
44
+ if(Meteor.settings.public.enable_saas){
45
+ return false;
46
+ }
45
47
  var record = data && data.record;
46
48
  return record && record.is_system && !record.created;
47
49
  }
@@ -177,6 +177,9 @@ module.exports = {
177
177
  if(!record){
178
178
  record = Creator.odata.get("objects", record_id, "is_deleted");
179
179
  }
180
+ if(record.is_system){
181
+ return false;
182
+ }
180
183
  if(record && !record.is_deleted){
181
184
  return Creator.baseObject.actions.standard_delete.visible.apply(this, arguments);
182
185
  }
@@ -9,8 +9,24 @@
9
9
  "className": "",
10
10
  "enableTabs": true,
11
11
  "mode": "edit",
12
- "layout": "normal",
13
- "apiRequestAdaptor": "api.data.query = api.data.query.replace('object_fields__update', 'object_fields__upsert')",
12
+ "layout": "horizontal",
13
+ "onEvent": {
14
+ "change": {
15
+ "actions": [
16
+ {
17
+ "actionType": "setValue",
18
+ "args": {
19
+ "value": {
20
+ "defaultValue": ""
21
+ }
22
+ },
23
+ "expression": "${!!event.data.defaultValue_formula}"
24
+ }
25
+ ]
26
+ }
27
+ },
28
+ "initApiAdaptor": "const defaultValue_field_value = payload.data.defaultValue; if(defaultValue_field_value && _.isString(defaultValue_field_value) && defaultValue_field_value.indexOf('{')>-1 ){ payload.data.defaultValue_formula = defaultValue_field_value; delete payload.data.defaultValue; } return payload;",
29
+ "apiRequestAdaptor": "if(formData.defaultValue_formula){ formData.defaultValue = formData.defaultValue_formula } __saveData = JSON.stringify(JSON.stringify(formData)); api.data = {query: query.replace('{__saveData}', __saveData)}; api.data.query = api.data.query.replace('object_fields__update', 'object_fields__upsert')",
14
30
  "submitSuccActions": [
15
31
  {
16
32
  "actionType": "custom",
@@ -19,12 +35,101 @@
19
35
  {
20
36
  "actionType": "toast",
21
37
  "args": {
22
- "msgType": "success",
23
- "msg": "操作成功, 请刷新浏览器后查看效果",
24
- "position": "top-right"
38
+ "msgType": "success",
39
+ "msg": "操作成功, 请刷新浏览器后查看效果",
40
+ "position": "top-right"
41
+ }
42
+ }
43
+ ],
44
+ "fieldsExtend": {
45
+ "readonly": {
46
+ "amis": {
47
+ "onEvent": {
48
+ "change": {
49
+ "actions": [
50
+ {
51
+ "actionType": "setValue",
52
+ "componentId": "steedos_object_fields_form",
53
+ "args": {
54
+ "value": {
55
+ "static": false
56
+ }
57
+ },
58
+ "expression": "!!readonly"
59
+ }
60
+ ]
61
+ }
62
+ },
63
+ "id": "u:a32a4c461450"
64
+ }
65
+ },
66
+ "static": {
67
+ "amis": {
68
+ "onEvent": {
69
+ "change": {
70
+ "actions": [
71
+ {
72
+ "actionType": "setValue",
73
+ "componentId": "steedos_object_fields_form",
74
+ "args": {
75
+ "value": {
76
+ "readonly": false
77
+ }
78
+ },
79
+ "expression": "!!static"
80
+ }
81
+ ]
82
+ }
83
+ },
84
+ "id": "u:7affdbb0ef6d"
85
+ }
86
+ },
87
+ "required": {
88
+ "amis": {
89
+ "onEvent": {
90
+ "change": {
91
+ "actions": [
92
+ {
93
+ "actionType": "setValue",
94
+ "args": {
95
+ "value": {
96
+ "hidden": false
97
+ }
98
+ },
99
+ "componentId": "steedos_object_fields_form",
100
+ "expression": "${event.data.value}"
101
+ }
102
+ ]
103
+ }
104
+ },
105
+ "id": "u:adf4200a2170"
106
+ }
107
+ },
108
+ "hidden": {
109
+ "amis": {
110
+ "onEvent": {
111
+ "change": {
112
+ "actions": [
113
+ {
114
+ "actionType": "setValue",
115
+ "args": {
116
+ "value": {
117
+ "required": false
118
+ }
119
+ },
120
+ "componentId": "steedos_object_fields_form",
121
+ "expression": "${event.data.value}"
122
+ }
123
+ ]
124
+ }
125
+ },
126
+ "id": "u:adf4200a2170"
25
127
  }
26
128
  }
27
- ]
129
+ },
130
+ "form": {
131
+ "id": "steedos_object_fields_form"
132
+ }
28
133
  }
29
134
  ],
30
135
  "data": {
@@ -10,7 +10,7 @@
10
10
  "className": "",
11
11
  "enableTabs": true,
12
12
  "mode": "edit",
13
- "layout": "normal",
13
+ "layout": "horizontal",
14
14
  "apiRequestAdaptor": "console.log('api.data.query===', api.data.query);api.data.query = api.data.query.replace('objects__update', 'objects__upsert')",
15
15
  "submitSuccActions": [
16
16
  {
@@ -21,7 +21,12 @@
21
21
  "position": "top-right"
22
22
  }
23
23
  }
24
- ]
24
+ ],
25
+ "fieldsExtend": {
26
+ "compactLayouts": {
27
+ "label": ""
28
+ }
29
+ }
25
30
  }
26
31
  ],
27
32
  "data": {
@@ -0,0 +1,248 @@
1
+ /*
2
+ * @Description: 提供action_field_updates(字段更新对象)需要的数据接口
3
+ */
4
+
5
+ const register = require("@steedos/metadata-registrar");
6
+ const steedosI18n = require("@steedos/i18n");
7
+ const _ = require("lodash");
8
+ const clone = require("clone");
9
+
10
+ // 默认值字段代码:services/standard-object-database/main/default/services/object_fields.service.js
11
+
12
+ module.exports = {
13
+ name: "object_fields",
14
+ mixins: [],
15
+ /**
16
+ * Settings
17
+ */
18
+ settings: {
19
+
20
+ },
21
+
22
+ /**
23
+ * Dependencies
24
+ */
25
+ dependencies: [],
26
+
27
+ /**
28
+ * Actions
29
+ */
30
+ actions: {
31
+ getDefaultValueSchema: {
32
+ // 需要传 objectName, targetObject(非必填), field_name 参数进来。
33
+ rest: {
34
+ method: "POST",
35
+ path: "/defaultValue/schema"
36
+ },
37
+ async handler(ctx) {
38
+ const data = await this.getDefaultValueSchema(ctx);
39
+ return { status: 0, msg: "", data: data }
40
+ }
41
+ }
42
+ },
43
+
44
+ /**
45
+ * Events
46
+ */
47
+ events: {
48
+
49
+ },
50
+
51
+ /**
52
+ * Methods
53
+ */
54
+ methods: {
55
+ /* defaultValue 字段使用*/
56
+ getDefaultValueSchema: {
57
+ async handler(ctx) {
58
+ // console.log('ctx==>', ctx);
59
+ const userSession = ctx.meta.user;
60
+ const lng = userSession.language || 'zh-CN';
61
+ const type = ctx.params.type || 'text';
62
+ const objectName = ctx.params.object;
63
+ const fieldName = ctx.params.name;
64
+ const reference_to = ctx.params.reference_to;
65
+ const options = ctx.params.options;
66
+ const multiple = ctx.params.multiple;
67
+ const filtersFunction = ctx.params.filtersFunction;
68
+ const reference_to_field = ctx.params.reference_to_field || '_id';
69
+ const _id = ctx.params._id;
70
+ const mode = ctx.params.mode;
71
+ const scale = ctx.params.scale;
72
+ // const mode = global.mode;
73
+
74
+ const partialType = ['text','textarea','html','code','markdown','boolean','toggle','date','datetime','time','password','url','email','color','location'];
75
+ // const fieldType = partialType.indexOf(type) > -1 ? type : 'text';
76
+
77
+ let targetField = null;
78
+ let NAME_FIELD_KEY = null;
79
+ if (mode === 'read') {
80
+ const objectConfig = await register.getObjectConfig(objectName);
81
+ NAME_FIELD_KEY = objectConfig.NAME_FIELD_KEY || 'name';
82
+ targetField = objectConfig.fields[fieldName];
83
+ }
84
+ // console.log('targetField==>', targetField);
85
+ const value = (targetField && targetField.defaultValue) || '';
86
+ const translatedLabel = lng === 'zh-CN' ? "默认值" : 'DefaultValue';
87
+ let defaultValue_schema = {
88
+ "type": "text",
89
+ "name": "defaultValue",
90
+ "label": translatedLabel,
91
+ "labelClassName": "text-left"
92
+ }
93
+
94
+ if(partialType.indexOf(type) > -1){
95
+ defaultValue_schema.type = type;
96
+ }else if(type === 'select' && options){
97
+ defaultValue_schema.type = type;
98
+ defaultValue_schema.options = options;
99
+ defaultValue_schema.multiple = multiple;
100
+ }else if(['lookup','master_detail'].includes(type) && reference_to){
101
+ defaultValue_schema.type = type;
102
+ defaultValue_schema.reference_to = reference_to;
103
+ defaultValue_schema.multiple = multiple;
104
+ defaultValue_schema.filtersFunction = filtersFunction;
105
+ defaultValue_schema.reference_to_field = reference_to_field;
106
+ } else if(['number','currency','percent'].includes(type)){
107
+ defaultValue_schema.type = type;
108
+ defaultValue_schema.scale = scale;
109
+ }
110
+ let body = [];
111
+ let steedos_field = {
112
+ type:'steedos-field',
113
+ name:'defaultValue',
114
+ clearValueOnHidden: true,
115
+ fieldName: 'defaultValue',
116
+ field: defaultValue_schema,
117
+ value: value,
118
+ readonly: mode === 'read' ? true : false
119
+ };
120
+ if(mode === 'read'){
121
+ const baseFieldConfig = {
122
+ "name": "defaultValue",
123
+ "label": translatedLabel,
124
+ "labelClassName": "text-left",
125
+ "clearValueOnHidden": true,
126
+ "fieldName": "defaultValue"
127
+ }
128
+ if(_.isString(value) && value.indexOf('{')>-1){
129
+ // 只读时值是公式就显示公式
130
+ steedos_field = {
131
+ "type": "control",
132
+ "label": translatedLabel,
133
+ "body": {
134
+ "name": "defaultValue",
135
+ "label": translatedLabel,
136
+ "labelClassName": "text-left",
137
+ "type": "tpl",
138
+ "tpl": value.indexOf('$') > -1 ? "\\"+value : value
139
+ }
140
+ }
141
+ }else if(['number','currency','percent'].includes(type)){
142
+ steedos_field = {
143
+ ...baseFieldConfig,
144
+ "type": "static-tpl",
145
+ "tpl": `<div>${value}</div>`,
146
+ "className": "m-1 md:border-b steedos-static-tpl-readonly",
147
+ "quickEdit": false,
148
+ }
149
+ }else if(['date','datetime','time'].includes(type)){
150
+ let fieldTypeConfig ={};
151
+ if(type==='date'){
152
+ fieldTypeConfig = {
153
+ "type": "input-date",
154
+ "inputFormat": "YYYY-MM-DD",
155
+ "format": "YYYY-MM-DDT00:00:00.000[Z]",
156
+ "className": "m-1 steedos-input-date-edit",
157
+ }
158
+ }else if(type==='datetime'){
159
+ fieldTypeConfig = {
160
+ "type": "input-datetime",
161
+ "inputFormat": "YYYY-MM-DD HH:mm",
162
+ "format": "YYYY-MM-DDTHH:mm:ss.SSSZ",
163
+ "className": "m-1 steedos-input-datetime-edit",
164
+ }
165
+ }else if(type==='time'){
166
+ fieldTypeConfig = {
167
+ "type": "input-time",
168
+ "inputFormat": "HH:mm",
169
+ "format": "1970-01-01THH:mm:00.000[Z]",
170
+ "className": "m-1 steedos-input-time-edit",
171
+ }
172
+ }
173
+ steedos_field = {
174
+ ...baseFieldConfig,
175
+ ...fieldTypeConfig,
176
+ value: value,
177
+ static: true
178
+ }
179
+ }else if(['boolean'].includes(type)){
180
+ steedos_field = {
181
+ ...baseFieldConfig,
182
+ value: value,
183
+ "type": "static",
184
+ "tpl": `${value}`,
185
+ "className": "m-1 md:border-b steedos-static-readonly"
186
+ }
187
+ }else if(['lookup','master_detail'].includes(type)){
188
+ // console.log('t==>', type, reference_to, NAME_FIELD_KEY, targetField)
189
+ if(value && value.length && _.isString(reference_to)){
190
+ const query = {
191
+ fields: [NAME_FIELD_KEY],
192
+ filters: [reference_to_field, '=', value]
193
+ }
194
+ const res = await this.broker.call(
195
+ 'objectql.find',
196
+ {
197
+ objectName: reference_to,
198
+ query
199
+ }
200
+ );
201
+ // console.log('res==>', res, reference_to, NAME_FIELD_KEY, targetField);
202
+ const tpl = _.map(res, NAME_FIELD_KEY).join('、')
203
+ steedos_field = {
204
+ "type": "control",
205
+ "label": translatedLabel,
206
+ "body": {
207
+ "name": "defaultValue",
208
+ "label": translatedLabel,
209
+ "labelClassName": "text-left",
210
+ "type": "tpl",
211
+ "tpl": tpl
212
+ },
213
+ value: value
214
+ }
215
+ }
216
+ }
217
+ body = [steedos_field];
218
+ }else{
219
+ body = [steedos_field];
220
+ body[0].field.amis = {
221
+ // disabledOn: "!!this.defaultValue_formula",
222
+ "clearable": true,
223
+ "className": {
224
+ "defaultValue_field_hidden": "!this.defaultValue && (!this.defaultValue || '').toString() && !!this.defaultValue_formula"
225
+ }
226
+ }
227
+ body.push({
228
+ "name": "defaultValue_formula",
229
+ "label": translatedLabel,
230
+ "evalMode": false,
231
+ "type": "input-formula",
232
+ "placeholder": "公式",
233
+ // "disabledOn": "!!this.defaultValue && !!this.defaultValue.toString()",
234
+ "className": {
235
+ "defaultValue_field_formula": true,
236
+ "defaultValue_field_formula_visible": "!!this.defaultValue_formula",
237
+ "defaultValue_field_formula_hidden": "(!!this.defaultValue && !!this.defaultValue.toString()) || (!this.defaultValue && !this.defaultValue_formula)"
238
+ }
239
+ })
240
+ }
241
+ // console.log('body==>', body);
242
+ return {
243
+ body
244
+ }
245
+ }
246
+ }
247
+ }
248
+ };
@@ -125,14 +125,14 @@ async function checkMasterDetailTypeField(doc, oldReferenceTo) {
125
125
 
126
126
  const mastersCount = currentMasters.length;
127
127
  const detailsCount = currentDetails.length;
128
- if (mastersCount > 1) {
129
- throw new Meteor.Error(doc.name, "您无法创建此类型的字段,因为此对象已有两种主表子表关系。");
130
- }
131
- else if (mastersCount > 0) {
132
- if (detailsCount > 0) {
133
- throw new Meteor.Error(doc.name, "由于此对象上已经存在主表子表关系,同时是另一个主表子表关系的主对象,无法创建此类字段。");
134
- }
135
- }
128
+ if (mastersCount > 5) {
129
+ throw new Meteor.Error(doc.name, "您无法创建此类型的字段,因为此对象已有5种主表子表关系。");
130
+ }
131
+ // else if (mastersCount > 0) { // 当前对象已经有1个主子表字段
132
+ // if (detailsCount > 0) { // 当前对象已经作为了其他对象的主子表字段的关联对象
133
+ // throw new Meteor.Error(doc.name, "由于此对象上已经存在主表子表关系,同时是另一个主表子表关系的主对象,无法创建此类字段。");
134
+ // }
135
+ // }
136
136
 
137
137
  const detailPaths = await obj.getDetailPaths();
138
138
  const masterPaths = await refObj.getMasterPaths();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/standard-object-database",
3
- "version": "2.6.7",
3
+ "version": "2.6.8-beta.10",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -12,10 +12,10 @@
12
12
  "description": "steedos package",
13
13
  "dependencies": {
14
14
  "@steedos-widgets/amis-lib": "^1.0.22",
15
- "@steedos/metadata-core": "2.6.7",
16
- "@steedos/standard-objects": "2.6.7"
15
+ "@steedos/metadata-core": "2.6.8-beta.10",
16
+ "@steedos/standard-objects": "2.6.8-beta.10"
17
17
  },
18
18
  "repository": {},
19
19
  "license": "MIT",
20
- "gitHead": "7852282dc4524d9669457debd787bcd6c8614a3d"
20
+ "gitHead": "ab5c21a2ebc83ecff03d350f8a0b28760053cd33"
21
21
  }