@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,31 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-03-28 09:35:34
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2022-06-08 11:12:24
6
+ * @Description:
7
+ */
8
+ module.exports = {
9
+ listenTo: 'objects',
10
+
11
+ createDefaultRecordView: function (object_name, record_id, item_element) {
12
+ if(object_name === 'objects' && this.record){
13
+ const objectApiName = this.record.name;
14
+ $("body").addClass("loading");
15
+ const res = Steedos.authRequest(`/service/api/@${objectApiName}/defUiSchema`, { type: 'post', async: false});
16
+ $("body").removeClass("loading");
17
+ if(res.error){
18
+ toastr.error(res.error);
19
+ }else{
20
+ toastr.success(t("Added successfully"));
21
+ }
22
+ FlowRouter.reload();
23
+ }
24
+ },
25
+ createDefaultRecordViewVisible: function(object_name, record_id, record_permissions){
26
+ if(!Creator.isSpaceAdmin()){
27
+ return false
28
+ }
29
+ return true;
30
+ }
31
+ }
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ listenTo: 'object_layouts',
3
+
4
+ customize: function (object_name, record_id, fields) {
5
+ let doc = Creator.odata.get(object_name, record_id);
6
+ var newRecord = _.pick(doc, Creator.getObjectFieldsName(object_name));
7
+ delete newRecord.is_system;
8
+ delete newRecord._id;
9
+ newRecord.from_code_id = record_id;
10
+ Creator.odata.insert(object_name, newRecord, function(result, error){
11
+ if(result){
12
+ FlowRouter.go(`/app/-/${object_name}/view/${result._id}`)
13
+ }
14
+ });
15
+ },
16
+ customizeVisible: function(object_name, record_id, record_permissions, record){
17
+ return Creator.baseObject.actions.standard_new.visible() && record.is_system;
18
+ }
19
+ }
@@ -0,0 +1,356 @@
1
+ name: object_layouts
2
+ label: Object Layouts
3
+ icon: dashboard_ea
4
+ hidden: false
5
+ version: 2
6
+ fields:
7
+ name:
8
+ type: text
9
+ required: true
10
+ label: Api Name
11
+ is_wide: true
12
+ label:
13
+ type: text
14
+ required: true
15
+ label: Label
16
+ is_wide: true
17
+ is_name: true
18
+ object_name:
19
+ label: Object
20
+ type: master_detail
21
+ required: true
22
+ reference_to: objects
23
+ reference_to_field: name
24
+ write_requires_master_read: true
25
+ optionsFunction: !<tag:yaml.org,2002:js/function> |-
26
+ function () {
27
+ var _options = [];
28
+ _.forEach(Creator.objectsByName, function (o, k) {
29
+ return _options.push({
30
+ label: o.label,
31
+ value: k,
32
+ icon: o.icon
33
+ });
34
+ });
35
+ return _options;
36
+ }
37
+ type:
38
+ type: select
39
+ options:
40
+ - label: Record
41
+ value: record
42
+ - label: Page
43
+ value: page
44
+ defaultValue: '"record"'
45
+ hidden: true
46
+ # required: true
47
+ profiles:
48
+ type: lookup
49
+ label: Profile
50
+ showIcon: false
51
+ multiple: true
52
+ required: true
53
+ create: false
54
+ optionsFunction: !<tag:yaml.org,2002:js/function> |-
55
+ function () {
56
+ var profiles = Creator.odata.query('permission_set', {$filter: "(type eq 'profile')"}, true);
57
+ var result = [];
58
+ profiles.forEach(function (item) {
59
+ result.push({
60
+ label: item.label,
61
+ value: item.name
62
+ });
63
+ });
64
+ return result;
65
+ }
66
+ buttons:
67
+ type: grid
68
+ blackbox: true
69
+ is_wide: true
70
+ depend_on:
71
+ - object_name
72
+ buttons.$.button_name:
73
+ type: lookup
74
+ optionsFunction: !<tag:yaml.org,2002:js/function> |-
75
+ function (values) {
76
+ if (!(values != null ? values.object_name : void 0)) {
77
+ values.object_name = Session.get("object_name");
78
+ }
79
+ if(values.object_name && !_.isString(values.object_name)){
80
+ values.object_name = values.object_name.name
81
+ }
82
+ const options = [];
83
+ if(values){
84
+ var actions = Creator.getObject(values.object_name).actions;
85
+ _.each(actions, function(action){
86
+ options.push({label: action.label, value: action.name})
87
+ })
88
+ }
89
+ return options;
90
+ }
91
+ buttons.$.visible_on:
92
+ label: Visible on
93
+ type: textarea
94
+ rows: 1
95
+ fields:
96
+ type: grid
97
+ is_wide: true
98
+ required: true
99
+ depend_on:
100
+ - object_name
101
+ fields.$:
102
+ label: Field
103
+ blackbox: true
104
+ type: object
105
+ fields.$.field_name:
106
+ label: Field
107
+ type: lookup
108
+ multiple: false
109
+ is_wide: false
110
+ required: true
111
+ reference_to: object_fields
112
+ reference_to_field: name
113
+ depend_on:
114
+ - object_name
115
+ filtersFunction: !<tag:yaml.org,2002:js/function> |-
116
+ function (filters, values) {
117
+ if(values && values.object_name){
118
+ if(values._grid_row_id){
119
+ var selected = _.find(values.fields, function(item){return item._id==values._grid_row_id});
120
+ var selectedAll = _.pluck(values.fields, 'field_name');
121
+ if(selected){
122
+ selectedAll = _.difference(selectedAll, [selected.field_name]);
123
+ }
124
+ if(selectedAll && selectedAll.length > 0){
125
+ return [['object', '=', values.object_name], ['name', '!=', selectedAll]]
126
+ }
127
+ }
128
+ return ['object', '=', values.object_name]
129
+ }else{
130
+ return ['_id', '=', 'no']
131
+ }
132
+ }
133
+ fields.$.is_readonly:
134
+ label: Readonly
135
+ type: boolean
136
+ fields.$.is_required:
137
+ label: Required
138
+ type: boolean
139
+ fields.$.group:
140
+ label: Group
141
+ type: text
142
+ fields.$.visible_on:
143
+ label: Visible on
144
+ type: textarea
145
+ rows: 1
146
+ related_lists:
147
+ type: grid
148
+ blackbox: true
149
+ is_wide: true
150
+ depend_on:
151
+ - object_name
152
+ related_lists.$.related_field_fullname:
153
+ type: lookup
154
+ optionsFunction: !!js/function |
155
+ function(values) {
156
+ if (!(values != null ? values.object_name : void 0)) {
157
+ values.object_name = Session.get("object_name");
158
+ }
159
+ if(values.object_name && !_.isString(values.object_name)){
160
+ values.object_name = values.object_name.name
161
+ }
162
+ const options = [];
163
+ const object = Creator.getObject(values.object_name);
164
+
165
+ let relatedLists = []
166
+ if(object.enable_files){
167
+ relatedLists.push("cms_files.parent")
168
+ }
169
+ /*
170
+ object.details是一个字符串,形如:testb__c.testa__c
171
+ object.lookup_details是一个对象,格式如下:
172
+ {
173
+ key: "testd__c.testa__c",
174
+ objectName: "testa__c",
175
+ type: "detail",
176
+ }
177
+ */
178
+ relatedLists = relatedLists.concat(_.union(object.details, object.lookup_details));
179
+
180
+ if(object.enable_tasks){
181
+ relatedLists.push("tasks.related_to")
182
+ }
183
+ if(object.enable_notes){
184
+ relatedLists.push("notes.related_to")
185
+ }
186
+ if(object.enable_events){
187
+ relatedLists.push("events.related_to")
188
+ }
189
+ if(object.enable_instances){
190
+ relatedLists.push("instances.record_ids")
191
+ }
192
+ if(object.enable_approvals){
193
+ relatedLists.push("approvals.related_to")
194
+ }
195
+ if(object.enable_process){
196
+ relatedLists.push("process_instance_history.target_object")
197
+ }
198
+ if(object.enable_audit){
199
+ relatedLists.push("audit_records.related_to")
200
+ }
201
+
202
+ _.each(relatedLists, function(related){
203
+ if (!related) return;
204
+ /*related可能是一个lookup_details,它是对象而不是字符串,从中取出key值*/
205
+ if(typeof related !== "string"){
206
+ related = related.key;
207
+ }
208
+ if (!related) return;
209
+ let foo = related.split('.');
210
+ let rObjectName = foo[0];
211
+ let rFieldName = foo[1];
212
+ let rObjectLable = Creator.getObject(rObjectName).label;
213
+ let rObjectFieldLable = (_.find(Creator.getObject(rObjectName).fields, function(field){return field.name === rFieldName}) || {}).label;
214
+ options.push({label: `${rObjectLable}.${rObjectFieldLable}`, value: related})
215
+ })
216
+ return options;
217
+ }
218
+ related_lists.$.label:
219
+ label: Label
220
+ type: text
221
+ inlineHelpText: default is the object name
222
+ related_lists.$.field_names:
223
+ type: lookup
224
+ create: false
225
+ multiple: true
226
+ reference_to: object_fields
227
+ reference_to_field: name
228
+ depend_on:
229
+ - object_name
230
+ - related_lists
231
+ filtersFunction: !<tag:yaml.org,2002:js/function> |-
232
+ function (filters, values) {
233
+ let relatedFieldFullname = null;
234
+ const rowValue = _.find(values.related_lists, function(item){
235
+ return item._id === values._grid_row_id
236
+ })
237
+ if(rowValue){
238
+ relatedFieldFullname = rowValue.related_field_fullname
239
+ }
240
+ if(relatedFieldFullname){
241
+ const objectName = relatedFieldFullname.substring(0, relatedFieldFullname.indexOf("."))
242
+ return ['object', '=', objectName]
243
+ }else{
244
+ return ['_id', '=', 'no']
245
+ }
246
+ }
247
+ related_lists.$.sort_field_name:
248
+ label: Sort field
249
+ type: lookup
250
+ create: false
251
+ multiple: true
252
+ reference_to: object_fields
253
+ reference_to_field: name
254
+ depend_on:
255
+ - object_name
256
+ - related_lists
257
+ filtersFunction: !<tag:yaml.org,2002:js/function> |-
258
+ function (filters, values) {
259
+ let relatedFieldFullname = null;
260
+ const rowValue = _.find(values.related_lists, function(item){
261
+ return item._id === values._grid_row_id
262
+ })
263
+ if(rowValue){
264
+ relatedFieldFullname = rowValue.related_field_fullname
265
+ }
266
+ if(relatedFieldFullname){
267
+ const objectName = relatedFieldFullname.substring(0, relatedFieldFullname.indexOf("."))
268
+ return ['object', '=', objectName]
269
+ }else{
270
+ return ['_id', '=', 'no']
271
+ }
272
+ }
273
+ related_lists.$.sort_order:
274
+ label: Sort Order
275
+ type: select
276
+ defaultValue: '"asc"'
277
+ options:
278
+ - label: ASC
279
+ value: asc
280
+ - label: DESC
281
+ value: desc
282
+ # related_lists.$.buttons:
283
+ # label: Buttons
284
+ # type: lookup
285
+ # is_wide: true
286
+ # optionsFunction: !<tag:yaml.org,2002:js/function> |-
287
+ # function (values) {
288
+ # let relatedFieldFullname = null;
289
+ # const rowValue = _.find(values.related_lists, function(item){
290
+ # return item._id === values._grid_row_id
291
+ # })
292
+ # if(rowValue){
293
+ # relatedFieldFullname = rowValue.related_field_fullname
294
+ # }
295
+ # const options = [];
296
+ # if(relatedFieldFullname){
297
+ # const objectName = relatedFieldFullname.substring(0, relatedFieldFullname.indexOf("."))
298
+ # var actions = Creator.getObject(objectName).actions;
299
+ # _.each(actions, function(action){
300
+ # options.push({label: action.label, value: action.name})
301
+ # })
302
+ # }
303
+ # return options
304
+ # }
305
+ related_lists.$.filters:
306
+ label: Filters
307
+ type: textarea
308
+ rows: 1
309
+ is_wide: true
310
+ related_lists.$.visible_on:
311
+ label: Visible on
312
+ type: textarea
313
+ rows: 1
314
+ related_lists.$.page_size:
315
+ label: Page Size
316
+ type: number
317
+ scale: 0
318
+ defaultValue: 5
319
+ list_views:
320
+ all:
321
+ columns:
322
+ - label
323
+ - object_name
324
+ - profiles
325
+ label: All
326
+ filter_scope: space
327
+ actions:
328
+ createDefaultRecordView:
329
+ on: list
330
+ label: 创建默认页面布局
331
+ visible: false
332
+ customize:
333
+ label: Customize
334
+ on: record_only
335
+ permission_set:
336
+ user:
337
+ allowCreate: false
338
+ allowDelete: false
339
+ allowEdit: false
340
+ allowRead: false
341
+ modifyAllRecords: false
342
+ viewAllRecords: false
343
+ admin:
344
+ allowCreate: true
345
+ allowDelete: true
346
+ allowEdit: true
347
+ allowRead: true
348
+ modifyAllRecords: true
349
+ viewAllRecords: true
350
+ form:
351
+ initialValues: !<tag:yaml.org,2002:js/function> |-
352
+ function () {
353
+ const objectApiName = this.doc.object_name;
354
+ const res = Steedos.authRequest(`/service/api/@${objectApiName}/uiSchemaTemplate`, { type: 'get', async: false});
355
+ return res || {}
356
+ }
@@ -0,0 +1,93 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-03-28 09:35:34
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2022-07-26 17:21:35
6
+ * @Description:
7
+ */
8
+ module.exports = {
9
+ customize: function (object_name, record_id, fields) {
10
+ let doc = Creator.odata.get(object_name, record_id);
11
+ if(!doc.columns || !doc.columns.length){
12
+ const objectName_label = record_id.split('.');
13
+ let columns = Creator.getListView(objectName_label[0], objectName_label[1], true).columns;
14
+ doc.columns = columns || [];
15
+ }
16
+ doc.columns = doc.columns.map((item)=>{
17
+ if(typeof item === 'string'){
18
+ return { field: item }
19
+ }
20
+ return item;
21
+ })
22
+ var newRecord = _.pick(doc, Creator.getObjectFieldsName(object_name));
23
+ delete newRecord.is_system;
24
+ delete newRecord._id;
25
+ newRecord.from_code_id = record_id;
26
+ Creator.odata.insert(object_name, newRecord, function(result, error){
27
+ if(result){
28
+ FlowRouter.go(`/app/-/${object_name}/view/${result._id}`)
29
+ }
30
+ });
31
+
32
+ },
33
+ customizeVisible: function(object_name, record_id, record_permissions, record){
34
+ return Creator.baseObject.actions.standard_new.visible() && record.is_system;
35
+ },
36
+ copy: function(object_name, record_id){
37
+ let newRecord = _.clone(Creator.getListView(Session.get("object_name"), record_id));
38
+ if(!newRecord){
39
+ let doc = Creator.odata.get(object_name, record_id);
40
+ if(!doc.columns || !doc.columns.length){
41
+ const objectName_label = record_id.split('.');
42
+ let columns = Creator.getListView(objectName_label[0], objectName_label[1], true).columns;
43
+ doc.columns = columns || [];
44
+ }
45
+ doc.columns = doc.columns.map((item)=>{
46
+ if(typeof item === 'string'){
47
+ return { field: item }
48
+ }
49
+ return item;
50
+ })
51
+ newRecord = _.pick(doc, Creator.getObjectFieldsName(object_name));
52
+ }
53
+ delete newRecord.is_system;
54
+ delete newRecord._id;
55
+ delete newRecord.name;
56
+ delete newRecord.from_code_id;
57
+ delete newRecord.label;
58
+ delete newRecord.owner;
59
+
60
+ var data = newRecord || { _filters_type_controller: 'conditions' };
61
+ //数据格式转换
62
+ if (data) {
63
+ data.columns = lodash.map(data.columns, 'field');
64
+ data.sort = lodash.map(data.sort, (item) => {
65
+ return `${item.field_name}:${item.order || 'asc'}`
66
+ });
67
+ data.mobile_columns = lodash.map(data.mobile_columns, 'field');
68
+
69
+ if (data.filters && lodash.isString(data.filters)) {
70
+ try {
71
+ data.filters = JSON.parse(data.filters);
72
+ }catch(e){}
73
+ }
74
+
75
+ if (data.filters && lodash.isString(data.filters)) {
76
+ data._filters_type_controller = 'function';
77
+ } else {
78
+ data._filters_type_controller = 'conditions'
79
+ }
80
+
81
+ if (data._filters_type_controller === 'conditions') {
82
+ data._filters_conditions = window.amisConvert.filtersToConditions(data.filters || []);
83
+ } else {
84
+ data._filters_function = data.filters;
85
+ }
86
+ }
87
+
88
+ Steedos.Page.Form.StandardNew.render(Session.get("app_id"), 'object_listviews', t("creator_list_copy_list_view"), data, {});
89
+ },
90
+ copyVisible: function(object_name, record_id, record_permissions, record){
91
+ return true;
92
+ }
93
+ }
@@ -0,0 +1,100 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-03-28 09:35:34
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2022-05-30 18:38:47
6
+ * @Description:
7
+ */
8
+ const _ = require("underscore");
9
+
10
+ function transformFilters(filters){
11
+ if(_.isString(filters)){
12
+ return filters;
13
+ }
14
+ let _filters = [];
15
+ _.each(filters, function(filter){
16
+ if(_.isObject(filter)){
17
+ if(filter.operation && filter.operation.startsWith("between_time_")){
18
+ filter.value = filter.operation.split("between_time_")[1];
19
+ filter.operation = 'between';
20
+ }
21
+ }
22
+ _filters.push(filter);
23
+ })
24
+ return _filters;
25
+ }
26
+
27
+ function checkName(name){
28
+ var reg = new RegExp('^[a-z]([a-z0-9]|_(?!_))*[a-z0-9]$');
29
+ if(!reg.test(name)){
30
+ throw new Error("object_listviews__error_name_invalid_format");
31
+ }
32
+ if(name.length > 50){
33
+ throw new Error("API 名称长度不能大于50个字符");
34
+ }
35
+ return true
36
+ }
37
+
38
+ Creator.Objects['object_listviews'].triggers = Object.assign(Creator.Objects['object_listviews'].triggers || {}, {
39
+ "before.insert.cilent.object_listviews": {
40
+ on: "client",
41
+ when: "before.insert",
42
+ todo: function (userId, doc) {
43
+ var columns, filter_scope, list_view, object_name, ref;
44
+ object_name = Session.get("object_name");
45
+ list_view = Creator.getObjectDefaultView(object_name);
46
+ filter_scope = (list_view != null ? list_view.filter_scope : void 0) || "space";
47
+ columns = list_view != null ? list_view.columns : void 0;
48
+ if (filter_scope === "spacex") {
49
+ filter_scope = "space";
50
+ }
51
+ if (!doc.object_name) {
52
+ doc.object_name = object_name;
53
+ }
54
+ doc.filter_scope = filter_scope;
55
+ if (!doc.columns) {
56
+ doc.columns = columns;
57
+ }
58
+ // doc.filters = ((ref = Session.get("cmDoc")) != null ? ref.filters : void 0) || [];
59
+ }
60
+ },
61
+ "before.insert.server.object_listviews": {
62
+ on: "server",
63
+ when: "before.insert",
64
+ todo: function (userId, doc) {
65
+ checkName(doc.name);
66
+ if (!Steedos.isSpaceAdmin(doc.space, userId)) {
67
+ doc.shared = false;
68
+ }
69
+ doc.filters = transformFilters(doc.filters);
70
+ }
71
+ },
72
+ "before.update.server.object_listviews": {
73
+ on: "server",
74
+ when: "before.update",
75
+ todo: function (userId, doc, fieldNames, modifier, options) {
76
+ modifier.$set = modifier.$set || {}
77
+
78
+ if(_.has(modifier.$set, "name") && modifier.$set.name != doc.name){
79
+ checkName(modifier.$set.name);
80
+ }
81
+
82
+ if (modifier.$set.shared && !Steedos.isSpaceAdmin(doc.space, userId)) {
83
+ modifier.$set.shared = false;
84
+ }
85
+ if(modifier.$set.filters){
86
+ modifier.$set.filters = transformFilters(modifier.$set.filters);
87
+ }
88
+ }
89
+ },
90
+ "before.remove.server.object_listviews": {
91
+ on: "server",
92
+ when: "before.remove",
93
+ todo: function (userId, doc) {
94
+ console.log("before.remove");
95
+ if (doc.owner !== userId) {
96
+ throw new Meteor.Error(403, "can only remove own list view");
97
+ }
98
+ }
99
+ }
100
+ })