@steedos/standard-object-database 2.2.55-beta.16

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.
Files changed (90) hide show
  1. package/main/default/applications/.gitkeep +0 -0
  2. package/main/default/client/datasources.client.js +7 -0
  3. package/main/default/client/object_fields.client.js +212 -0
  4. package/main/default/client/object_layouts.client.js +86 -0
  5. package/main/default/objectTranslations/_object_reload_logs.en/_object_reload_logs.en.objectTranslation.yml +16 -0
  6. package/main/default/objectTranslations/_object_reload_logs.zh-CN/_object_reload_logs.zh-CN.objectTranslation.yml +16 -0
  7. package/main/default/objectTranslations/datasources.en/datasources.en.objectTranslation.yml +121 -0
  8. package/main/default/objectTranslations/datasources.zh-CN/datasources.zh-CN.objectTranslation.yml +105 -0
  9. package/main/default/objectTranslations/object_actions.en/object_actions.en.objectTranslation.yml +55 -0
  10. package/main/default/objectTranslations/object_actions.zh-CN/object_actions.zh-CN.objectTranslation.yml +50 -0
  11. package/main/default/objectTranslations/object_fields.en/object_fields.en.objectTranslation.yml +335 -0
  12. package/main/default/objectTranslations/object_fields.zh-CN/object_fields.zh-CN.objectTranslation.yml +312 -0
  13. package/main/default/objectTranslations/object_layouts.en/object_layouts.en.objectTranslation.yml +72 -0
  14. package/main/default/objectTranslations/object_layouts.zh-CN/object_layouts.zh-CN.objectTranslation.yml +116 -0
  15. package/main/default/objectTranslations/object_listviews.en/object_listviews.en.objectTranslation.yml +153 -0
  16. package/main/default/objectTranslations/object_listviews.zh-CN/object_listviews.zh-CN.objectTranslation.yml +146 -0
  17. package/main/default/objectTranslations/object_related_list.en/object_related_list.en.objectTranslation.yml +82 -0
  18. package/main/default/objectTranslations/object_related_list.zh-CN/object_related_list.zh-CN.objectTranslation.yml +82 -0
  19. package/main/default/objectTranslations/object_triggers.en/object_triggers.en.objectTranslation.yml +30 -0
  20. package/main/default/objectTranslations/object_triggers.zh-CN/object_triggers.zh-CN.objectTranslation.yml +29 -0
  21. package/main/default/objectTranslations/object_validation_rules.en/object_validation_rules.en.objectTranslation.yml +40 -0
  22. package/main/default/objectTranslations/object_validation_rules.zh-CN/object_validation_rules.zh-CN.objectTranslation.yml +38 -0
  23. package/main/default/objectTranslations/objects.en/objects.en.objectTranslation.yml +219 -0
  24. package/main/default/objectTranslations/objects.zh-CN/objects.zh-CN.objectTranslation.yml +218 -0
  25. package/main/default/objects/0.datasources.observe.object.js +83 -0
  26. package/main/default/objects/0.objects_reload.object.js +26 -0
  27. package/main/default/objects/1.objects.observe.object.js +61 -0
  28. package/main/default/objects/10.tabs.observe.object.js +36 -0
  29. package/main/default/objects/11.restriction_rules.observe.object.js +37 -0
  30. package/main/default/objects/12.share_rules.observe.object.js +37 -0
  31. package/main/default/objects/13.permission_fields.observe.object.js +37 -0
  32. package/main/default/objects/14.object_fields.observe.object.js +44 -0
  33. package/main/default/objects/15.permission_objects.observe.object.js +44 -0
  34. package/main/default/objects/2.object_triggers.observe.object.js +35 -0
  35. package/main/default/objects/3.permission_objects.observe.object.js +29 -0
  36. package/main/default/objects/4.permission_set.observe.object.js +39 -0
  37. package/main/default/objects/5.holidays.observe.object.js +30 -0
  38. package/main/default/objects/6.business_hours.observe.object.js +33 -0
  39. package/main/default/objects/7.object_actions.observe.object.js +43 -0
  40. package/main/default/objects/7.object_layouts.observe.object.js +33 -0
  41. package/main/default/objects/9.apps.observe.object.js +33 -0
  42. package/main/default/objects/_object_reload_logs.object.yml +10 -0
  43. package/main/default/objects/datasources.action.js +51 -0
  44. package/main/default/objects/datasources.core.js +34 -0
  45. package/main/default/objects/datasources.object.js +168 -0
  46. package/main/default/objects/datasources.object.yml +113 -0
  47. package/main/default/objects/object_actions.object.js +152 -0
  48. package/main/default/objects/object_actions.object.yml +142 -0
  49. package/main/default/objects/object_fields.action.js +128 -0
  50. package/main/default/objects/object_fields.function.js +104 -0
  51. package/main/default/objects/object_fields.object.js +501 -0
  52. package/main/default/objects/object_fields.object.yml +690 -0
  53. package/main/default/objects/object_layouts.action.js +31 -0
  54. package/main/default/objects/object_layouts.layouts.action.js +19 -0
  55. package/main/default/objects/object_layouts.object.yml +356 -0
  56. package/main/default/objects/object_listviews.action.js +93 -0
  57. package/main/default/objects/object_listviews.object.js +100 -0
  58. package/main/default/objects/object_listviews.object.yml +309 -0
  59. package/main/default/objects/object_manager.app.todo.yml +11 -0
  60. package/main/default/objects/object_related_list.object.js +110 -0
  61. package/main/default/objects/object_related_list.object.yml +208 -0
  62. package/main/default/objects/object_triggers.core.js +58 -0
  63. package/main/default/objects/object_triggers.object.js +65 -0
  64. package/main/default/objects/object_triggers.object.yml +124 -0
  65. package/main/default/objects/object_validation_rules.action.js +33 -0
  66. package/main/default/objects/object_validation_rules.object.yml +100 -0
  67. package/main/default/objects/objects.action.js +157 -0
  68. package/main/default/objects/objects.core.js +398 -0
  69. package/main/default/objects/objects.erd.data.function.js +85 -0
  70. package/main/default/objects/objects.lib.js +42 -0
  71. package/main/default/objects/objects.object.js +543 -0
  72. package/main/default/objects/objects.object.yml +512 -0
  73. package/main/default/objects/objects.tree.js +58 -0
  74. package/main/default/objects/permission_objects.core.js +75 -0
  75. package/main/default/permissionsets/.gitkeep +0 -0
  76. package/main/default/profiles/.gitkeep +0 -0
  77. package/main/default/tabs/.gitkeep +0 -0
  78. package/main/default/triggers/datasources.trigger.js +93 -0
  79. package/main/default/triggers/object_actions.trigger.js +98 -0
  80. package/main/default/triggers/object_fields.trigger.js +376 -0
  81. package/main/default/triggers/object_layouts.trigger.js +153 -0
  82. package/main/default/triggers/object_listviews.trigger.js +139 -0
  83. package/main/default/triggers/object_triggers.trigger.js +50 -0
  84. package/main/default/triggers/object_validation_rules.trigger.js +80 -0
  85. package/main/default/triggers/objects.trigger.js +136 -0
  86. package/package.json +16 -0
  87. package/package.service.js +75 -0
  88. package/public/.md +3 -0
  89. package/src/.md +3 -0
  90. package/webapp/.md +1 -0
@@ -0,0 +1,113 @@
1
+ name: datasources
2
+ label: DataSource
3
+ icon: entity
4
+ hidden: true
5
+ version: 2
6
+ fields:
7
+ driver:
8
+ type: select
9
+ label: Driver
10
+ options: MongoDB:mongo,SQL Server:sqlserver,PostgreSQL:postgres,Oracle:oracle,MySQL:mysql,Sqlite:sqlite
11
+ required: true
12
+ sort_no: 30
13
+ label:
14
+ type: text
15
+ label: Label
16
+ required: true
17
+ is_name: true
18
+ sort_no: 10
19
+ name:
20
+ type: text
21
+ label: Name
22
+ searchable: true
23
+ index: true
24
+ required: true
25
+ inlineHelpText: Can only contain lowercase letters and numbers, must start with a letter, cannot end with an underscore character or contain two consecutive underscore characters
26
+ sort_no: 20
27
+ # url:
28
+ # type: text
29
+ # label: Url
30
+ host:
31
+ type: text
32
+ label: Database host
33
+ group: Other connection options
34
+ port:
35
+ type: number
36
+ scale: 0
37
+ label: Database host port
38
+ group: Other connection options
39
+ database:
40
+ type: text
41
+ label: Database name
42
+ group: Other connection options
43
+ username:
44
+ type: text
45
+ label: Database username
46
+ group: Other connection options
47
+ password:
48
+ type: password
49
+ label: Database password
50
+ group: Other connection options
51
+ mssql_options:
52
+ type: textarea
53
+ label: Mssql connection options
54
+ is_wide: true
55
+ group: Mssql
56
+ connectString:
57
+ type: textarea
58
+ label: connectString
59
+ is_wide: true
60
+ group: Oracle
61
+ timezone:
62
+ type: text
63
+ label: Timezone
64
+ group: advanced
65
+ options:
66
+ type: object
67
+ label: Options
68
+ hidden: true
69
+ enable_space:
70
+ type: boolean
71
+ omit: true
72
+ hidden: true
73
+ label: Enable Space
74
+ locale:
75
+ type: text
76
+ label: Locale
77
+ group: advanced
78
+ logging:
79
+ type: boolean
80
+ label: Debug
81
+ group: advanced
82
+ is_enable:
83
+ type: boolean
84
+ label: Enable
85
+ list_views:
86
+ all:
87
+ columns:
88
+ - label
89
+ - name
90
+ - is_enable
91
+ - driver
92
+ label: All
93
+ filter_scope: space
94
+ actions:
95
+ testConnection:
96
+ label: Test connection
97
+ on: record
98
+ visible: true
99
+ permission_set:
100
+ user:
101
+ allowCreate: false
102
+ allowDelete: false
103
+ allowEdit: false
104
+ allowRead: false
105
+ modifyAllRecords: false
106
+ viewAllRecords: false
107
+ admin:
108
+ allowCreate: true
109
+ allowDelete: true
110
+ allowEdit: true
111
+ allowRead: true
112
+ modifyAllRecords: true
113
+ viewAllRecords: true
@@ -0,0 +1,152 @@
1
+ var objectql = require('@steedos/objectql');
2
+ var objectCore = require('./objects.core.js');
3
+ function _syncToObject(doc, event) {
4
+ objectCore.triggerReloadObject(doc.object, 'action', doc, event);
5
+ // var actions, object_actions;
6
+ // object_actions = Creator.getCollection("object_actions").find({
7
+ // object: doc.object,
8
+ // space: doc.space,
9
+ // is_enable: true
10
+ // }, {
11
+ // fields: {
12
+ // created: 0,
13
+ // modified: 0,
14
+ // owner: 0,
15
+ // created_by: 0,
16
+ // modified_by: 0
17
+ // }
18
+ // }).fetch();
19
+ // actions = {};
20
+ // _.forEach(object_actions, function (f) {
21
+ // return actions[f.name] = f;
22
+ // });
23
+ // return Creator.getCollection("objects").update({
24
+ // space: doc.space,
25
+ // name: doc.object
26
+ // }, {
27
+ // $set: {
28
+ // actions: actions
29
+ // }
30
+ // });
31
+ };
32
+
33
+ function isRepeatedName(doc, name) {
34
+ var other;
35
+ other = Creator.getCollection("object_actions").find({
36
+ object: doc.object,
37
+ space: doc.space,
38
+ _id: {
39
+ $ne: doc._id
40
+ },
41
+ name: name || doc.name
42
+ }, {
43
+ fields: {
44
+ _id: 1
45
+ }
46
+ });
47
+ if (other.count() > 0) {
48
+ return true;
49
+ }
50
+ return false;
51
+ };
52
+
53
+ function checkName(name){
54
+ var reg = new RegExp('^[a-z]([a-z0-9]|_(?!_))*[a-z0-9]$');
55
+ if(!reg.test(name)){
56
+ throw new Error("object_actions__error_name_invalid_format");
57
+ }
58
+ if(name.length > 50){
59
+ throw new Error("API 名称长度不能大于50个字符");
60
+ }
61
+ return true
62
+ }
63
+
64
+ function checkScript(script){
65
+ if(script && !script.startsWith("function")){
66
+ throw new Error("执行的脚本必须是以function包裹的函数,比如:function(object_name, record_id){// 在这里补充按钮点击事件业务需求脚本。}");
67
+ }
68
+ }
69
+
70
+ function allowChangeObject(){
71
+ var config = objectql.getSteedosConfig();
72
+ if(config.tenant && config.tenant.saas){
73
+ return false
74
+ }else{
75
+ return true;
76
+ }
77
+ }
78
+
79
+ Creator.Objects.object_actions.triggers = {
80
+ // "after.insert.server.object_actions": {
81
+ // on: "server",
82
+ // when: "after.insert",
83
+ // todo: function (userId, doc) {
84
+ // return _syncToObject(doc, 'insert');
85
+ // }
86
+ // },
87
+ // "after.update.server.object_actions": {
88
+ // on: "server",
89
+ // when: "after.update",
90
+ // todo: function (userId, doc) {
91
+ // doc._previousName = this.previous.name
92
+ // return _syncToObject(doc, 'update');
93
+ // }
94
+ // },
95
+ // "after.remove.server.object_actions": {
96
+ // on: "server",
97
+ // when: "after.remove",
98
+ // todo: function (userId, doc) {
99
+ // return _syncToObject(doc, 'remove');
100
+ // }
101
+ // },
102
+ "before.update.server.object_actions": {
103
+ on: "server",
104
+ when: "before.update",
105
+ todo: function (userId, doc, fieldNames, modifier, options) {
106
+
107
+ if(!allowChangeObject()){
108
+ throw new Meteor.Error(500, "华炎云服务不包含自定义业务对象的功能,请部署私有云版本");
109
+ }
110
+
111
+ modifier.$set = modifier.$set || {}
112
+
113
+ // if(_.has(modifier.$set, "object") && modifier.$set.object != doc.object){
114
+ // throw new Error("不能修改所属对象");
115
+ // }
116
+ if(_.has(modifier.$set, "name") && modifier.$set.name != doc.name){
117
+ checkName(modifier.$set.name);
118
+ }
119
+
120
+ checkScript(modifier.$set.todo);
121
+
122
+ var ref;
123
+ if ((modifier != null ? (ref = modifier.$set) != null ? ref.name : void 0 : void 0) && isRepeatedName(doc, modifier.$set.name)) {
124
+ throw new Meteor.Error(500, "名称不能重复");
125
+ }
126
+ }
127
+ },
128
+ "before.insert.server.object_actions": {
129
+ on: "server",
130
+ when: "before.insert",
131
+ todo: function (userId, doc) {
132
+ if(!allowChangeObject()){
133
+ throw new Meteor.Error(500, "华炎云服务不包含自定义业务对象的功能,请部署私有云版本");
134
+ }
135
+ doc.visible = true;
136
+ checkName(doc.name);
137
+ checkScript(doc.todo);
138
+ if (isRepeatedName(doc)) {
139
+ throw new Meteor.Error(500, `名称不能重复${doc.name}`);
140
+ }
141
+ }
142
+ },
143
+ "before.remove.server.object_actions": {
144
+ on: "server",
145
+ when: "before.remove",
146
+ todo: function (userId, doc) {
147
+ if(!allowChangeObject()){
148
+ throw new Meteor.Error(500, "华炎云服务不包含自定义业务对象的功能,请部署私有云版本");
149
+ }
150
+ }
151
+ }
152
+ }
@@ -0,0 +1,142 @@
1
+ name: object_actions
2
+ label: Object Action
3
+ icon: actions_and_buttons
4
+ hidden: true
5
+ version: 2
6
+ fields:
7
+ object:
8
+ type: master_detail
9
+ reference_to: objects
10
+ reference_to_field: name
11
+ write_requires_master_read: true
12
+ required: true
13
+ label: Object
14
+ create: false
15
+ sort_no: 110
16
+ optionsFunction: !<tag:yaml.org,2002:js/function> |-
17
+ function () {
18
+ var _options;
19
+
20
+ _options = [];
21
+
22
+ _.forEach(Creator.objectsByName, function (o, k) {
23
+ return _options.push({
24
+ label: o.label,
25
+ value: k,
26
+ icon: o.icon
27
+ });
28
+ });
29
+
30
+ return _options;
31
+ }
32
+ label:
33
+ type: text
34
+ label: Label
35
+ required: true
36
+ is_name: true
37
+ sort_no: 120
38
+ name:
39
+ type: text
40
+ sort_no: 130
41
+ label: API Name
42
+ searchable: true
43
+ index: true
44
+ required: true
45
+ inlineHelpText: Can only contain lowercase letters and numbers, must start with a letter, cannot end with an underscore character or contain two consecutive underscore characters
46
+ is_enable:
47
+ type: boolean
48
+ label: Enable
49
+ sort_no: 140
50
+ visible:
51
+ type: boolean
52
+ omit: true
53
+ hidden: true
54
+ label: Visible
55
+ sort_no: 150
56
+ 'on':
57
+ type: lookup
58
+ label: 'On'
59
+ is_wide: true
60
+ required: true
61
+ showIcon: false
62
+ sort_no: 160
63
+ optionsFunction: !<tag:yaml.org,2002:js/function> |-
64
+ function () {
65
+ return [{
66
+ label: "显示在列表右上角",
67
+ value: "list",
68
+ icon: "contact_list"
69
+ }, {
70
+ label: "显示在记录查看页右上角,以及列表视图中每项的下拉菜单中",
71
+ value: "record",
72
+ icon: "contact_list"
73
+ }, {
74
+ label: "显示在记录查看页右上角的“更多”下拉菜单中,以及列表视图中每项的下拉菜单中",
75
+ value: "record_more",
76
+ icon: "action.more"
77
+ }, {
78
+ label: "显示在列表视图中每项的下拉菜单中",
79
+ value: "list_item",
80
+ icon: "action_list_component"
81
+ }, {
82
+ label: "显示在记录查看页右上角",
83
+ value: "record_only",
84
+ icon: "contract"
85
+ }, {
86
+ label: "显示在记录查看页右上角的“更多”下拉菜单中",
87
+ value: "record_only_more",
88
+ icon: "action.more"
89
+ }];
90
+ }
91
+ type:
92
+ type: select
93
+ sort_no: 170
94
+ options:
95
+ - label: Custom JavaScript
96
+ value: script
97
+ # - label: 打印模板(word)
98
+ # value: word-print
99
+ defaultValue: script
100
+ # word_template:
101
+ # type: lookup
102
+ # reference_to: word_templates
103
+ # visible_on: "{{formData.type === 'word-print' ? true: false}}"
104
+ # create: false
105
+ todo:
106
+ label: Execute Script
107
+ sort_no: 180
108
+ type: code
109
+ language: javascript
110
+ required: true
111
+ # omit: true
112
+ # hidden: true
113
+ is_wide: true
114
+ visible_on: "{{formData.type != 'word-print' ? true: false}}"
115
+ paging:
116
+ enabled: false
117
+ list_views:
118
+ all:
119
+ columns:
120
+ - label
121
+ - name
122
+ - object
123
+ - 'on'
124
+ - is_enable
125
+ - modified
126
+ label: All
127
+ filter_scope: space
128
+ permission_set:
129
+ user:
130
+ allowCreate: false
131
+ allowDelete: false
132
+ allowEdit: false
133
+ allowRead: false
134
+ modifyAllRecords: false
135
+ viewAllRecords: false
136
+ admin:
137
+ allowCreate: true
138
+ allowDelete: true
139
+ allowEdit: true
140
+ allowRead: true
141
+ modifyAllRecords: true
142
+ viewAllRecords: true
@@ -0,0 +1,128 @@
1
+ module.exports = {
2
+ recomputeFormulaValues: function (object_name, record_id, item_element) {
3
+ $("body").addClass("loading");
4
+ var userSession = Creator.USER_CONTEXT;
5
+ var authorization = "Bearer " + userSession.spaceId + "," + userSession.user.authToken;
6
+ $.ajax({
7
+ type: "POST",
8
+ url: Steedos.absoluteUrl("/api/v4/" + object_name + "/" + record_id + "/recomputeFormulaValues"),
9
+ data: JSON.stringify({}),
10
+ dataType: "json",
11
+ contentType: 'application/json',
12
+ beforeSend: function (XHR) {
13
+ XHR.setRequestHeader('Content-Type', 'application/json');
14
+ XHR.setRequestHeader('Authorization', authorization);
15
+ },
16
+ success: function (data) {
17
+ $("body").removeClass("loading");
18
+ if(data){
19
+ if(data.error){
20
+ toastr.error(t("object_fields_function_recomputeFormulaValues_error", t(data.error.reason)));
21
+ }
22
+ else{
23
+ toastr.success(t("object_fields_function_recomputeFormulaValues_success"));
24
+ }
25
+ }
26
+ },
27
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
28
+ $("body").removeClass("loading");
29
+ var errorMsg = errorThrown;
30
+ var error = XMLHttpRequest.responseJSON.error;
31
+ if(error){
32
+ console.error("Recompute Formula Values Faild:", error);
33
+ if(error.reason){
34
+ errorMsg = error.reason;
35
+ }
36
+ else if(error.message){
37
+ errorMsg = error.message;
38
+ }
39
+ else{
40
+ errorMsg = error;
41
+ }
42
+ }
43
+ errorMsg = t(errorMsg);
44
+ if(error.details){
45
+ if(_.isObject(error.details)){
46
+ errorMsg += JSON.stringify(error.details);
47
+ }
48
+ else{
49
+ errorMsg += t(error.details);
50
+ }
51
+ }
52
+ toastr.error(t("object_fields_function_recomputeFormulaValues_error", errorMsg));
53
+ }
54
+ });
55
+ },
56
+ recomputeFormulaValuesVisible: function(object_name, record_id, record_permissions){
57
+ if(!Creator.isSpaceAdmin()){
58
+ return false
59
+ }
60
+ var record = Creator.odata.get(object_name, record_id, "type");
61
+ if(record && record.type === "formula"){
62
+ return true;
63
+ }
64
+ },
65
+ recomputeSummaryValues: function (object_name, record_id, item_element) {
66
+ $("body").addClass("loading");
67
+ var userSession = Creator.USER_CONTEXT;
68
+ var authorization = "Bearer " + userSession.spaceId + "," + userSession.user.authToken;
69
+ $.ajax({
70
+ type: "POST",
71
+ url: Steedos.absoluteUrl("/api/v4/" + object_name + "/" + record_id + "/recomputeSummaryValues"),
72
+ data: JSON.stringify({}),
73
+ dataType: "json",
74
+ contentType: 'application/json',
75
+ beforeSend: function (XHR) {
76
+ XHR.setRequestHeader('Content-Type', 'application/json');
77
+ XHR.setRequestHeader('Authorization', authorization);
78
+ },
79
+ success: function (data) {
80
+ $("body").removeClass("loading");
81
+ if(data){
82
+ if(data.error){
83
+ toastr.error(t("object_fields_function_recomputeSummaryValues_error", t(data.error.reason)));
84
+ }
85
+ else{
86
+ toastr.success(t("object_fields_function_recomputeSummaryValues_success"));
87
+ }
88
+ }
89
+ },
90
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
91
+ $("body").removeClass("loading");
92
+ var errorMsg = errorThrown;
93
+ var error = XMLHttpRequest.responseJSON.error;
94
+ if(error){
95
+ console.error("Recompute Summary Values Faild:", error);
96
+ if(error.reason){
97
+ errorMsg = error.reason;
98
+ }
99
+ else if(error.message){
100
+ errorMsg = error.message;
101
+ }
102
+ else{
103
+ errorMsg = error;
104
+ }
105
+ }
106
+ errorMsg = t(errorMsg);
107
+ if(error.details){
108
+ if(_.isObject(error.details)){
109
+ errorMsg += JSON.stringify(error.details);
110
+ }
111
+ else{
112
+ errorMsg += t(error.details);
113
+ }
114
+ }
115
+ toastr.error(t("object_fields_function_recomputeSummaryValues_error", errorMsg));
116
+ }
117
+ });
118
+ },
119
+ recomputeSummaryValuesVisible: function(object_name, record_id, record_permissions){
120
+ if(!Creator.isSpaceAdmin()){
121
+ return false
122
+ }
123
+ var record = Creator.odata.get(object_name, record_id, "type");
124
+ if(record && record.type === "summary"){
125
+ return true;
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,104 @@
1
+ const Fiber = require('fibers');
2
+ const objectql = require('@steedos/objectql');
3
+ const getSteedosSchema = objectql.getSteedosSchema;
4
+
5
+ module.exports = {
6
+ recomputeFormulaValues: async function(req, res){
7
+ try {
8
+ const params = req.params;
9
+ const userId = req.user && req.user.userId;
10
+ let fieldId = params._id;
11
+ const fieldDoc = await getSteedosSchema().getObject("object_fields").findOne(fieldId, { fields: ["object", "name"] });
12
+ if (!fieldDoc) {
13
+ throw new Error(`recomputeFormulaValues:${fieldId} not found.`);
14
+ }
15
+ fieldId = `${fieldDoc.object}.${fieldDoc.name}`;
16
+ const result = await objectql.recomputeFormulaValues(fieldId, req.user);
17
+ if(result){
18
+ res.status(200).send({ success: true });
19
+ }
20
+ else{
21
+ res.status(400).send({
22
+ success: false,
23
+ error: {
24
+ reason: `The recomputeFormulaValues function return ${result}.`
25
+ }
26
+ });
27
+ }
28
+ } catch (error) {
29
+ console.error("recomputeFormulaValues error:", error);
30
+ res.status(400).send({
31
+ success: false,
32
+ error: {
33
+ reason: error.reason,
34
+ message: error.message,
35
+ details: error.details,
36
+ stack: error.stack
37
+ }
38
+ });
39
+ }
40
+ },
41
+ recomputeSummaryValues: async function(req, res){
42
+ try {
43
+ const params = req.params;
44
+ let fieldId = params._id;
45
+ const fieldDoc = await getSteedosSchema().getObject("object_fields").findOne(fieldId, { fields: ["object", "name"] });
46
+ if (!fieldDoc) {
47
+ throw new Error(`recomputeFormulaValues:${fieldId} not found.`);
48
+ }
49
+ fieldId = `${fieldDoc.object}.${fieldDoc.name}`;
50
+ const result = await objectql.recomputeSummaryValues(fieldId, req.user);
51
+ if(result){
52
+ res.status(200).send({ success: true });
53
+ }
54
+ else{
55
+ res.status(400).send({
56
+ success: false,
57
+ error: {
58
+ reason: `The recomputeSummaryValues function return ${result}.`
59
+ }
60
+ });
61
+ }
62
+ } catch (error) {
63
+ console.error("recomputeSummaryValues error:", error);
64
+ res.status(400).send({
65
+ success: false,
66
+ error: {
67
+ reason: error.reason,
68
+ message: error.message,
69
+ details: error.details,
70
+ stack: error.stack
71
+ }
72
+ });
73
+ }
74
+ },
75
+ append_to_layouts: async function (req, res) {
76
+ try {
77
+ const body = req.body;
78
+ const userSession = req.user;
79
+ const fieldAPIName = body.field
80
+ const is_readonly = body.is_readonly
81
+ const is_required = body.is_required
82
+ const group = body.group
83
+ const visible_on = body.visible_on
84
+ const allowEdit = (await objectql.getObject('object_layouts').getUserObjectPermission(userSession)).allowEdit;
85
+ if (!allowEdit) {
86
+ throw new Error('无权限');
87
+ }
88
+ Fiber(function () {
89
+ Creator.getCollection("object_layouts").direct.update({ space: userSession.spaceId, _id: { $in: body.layouts } }, { $push: { fields: { field_name: fieldAPIName, is_readonly: is_readonly, is_required: is_required, group: group, visible_on: visible_on} } }, {
90
+ multi: true
91
+ })
92
+ }).run();
93
+
94
+ res.status(200).send({state: 'SUCCESS'});
95
+ } catch (error) {
96
+ res.status(400).send({
97
+ error: {
98
+ details: error.stack,
99
+ message: error.message,
100
+ },
101
+ });
102
+ }
103
+ }
104
+ }