@gudhub/core 1.1.74 → 1.1.76

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.
@@ -7,9 +7,8 @@ export class Interpritate {
7
7
  // In this method we are looking for interpretation in data model according to interpretation src
8
8
  // then we merged with default interpretation from defaultFieldDataModel
9
9
  // if there are no current interpretation we use default interpretation
10
- getInterpretationObj(fieldDataModel, defaultFieldDataModel, src, containerId) {
11
- var currentIntrpr = {};
12
-
10
+ async getInterpretationObj(fieldDataModel, defaultFieldDataModel, src, containerId, itemId, appId) {
11
+ var currentIntrpr = [];
13
12
  // Creating default interpretation
14
13
  var defaultIntrprObj = defaultFieldDataModel.data_model.interpretation.find(function (interpritation) {
15
14
  return interpritation.src == src;
@@ -17,15 +16,34 @@ export class Interpritate {
17
16
  return interpritation.src == 'table';
18
17
  }) || { id: 'default' };
19
18
 
19
+ var interpretation = defaultIntrprObj;
20
+
20
21
  if (fieldDataModel.data_model && fieldDataModel.data_model.interpretation) {
21
22
  // To detect interpretation we use (container_id), if there is not (container_id) we use (src)
22
- currentIntrpr = fieldDataModel.data_model.interpretation.find(function (interpritation) {
23
- return interpritation.src == containerId;
24
- }) || fieldDataModel.data_model.interpretation.find(function (interpritation) {
25
- return interpritation.src == src;
26
- });
23
+ for(var i = 0; i < fieldDataModel.data_model.interpretation.length; i++) {
24
+ if(fieldDataModel.data_model.interpretation[i].src == src || fieldDataModel.data_model.interpretation[i].src == containerId) {
25
+ currentIntrpr.push(fieldDataModel.data_model.interpretation[i]);
26
+ }
27
+ }
28
+
29
+ for(var i = 0; i < currentIntrpr.length; i++) {
30
+ if(currentIntrpr[i].settings.condition_filter && currentIntrpr[i].settings.filters_list.length > 0) {
31
+ const item = await gudhub.getItem(appId, itemId);
32
+ if(item) {
33
+ const filteredItems = gudhub.filter([item], currentIntrpr[i].settings.filters_list);
34
+ if(filteredItems.length > 0) {
35
+ interpretation = currentIntrpr[i];
36
+ break;
37
+ }
38
+ }
39
+ } else {
40
+ interpretation = gudhub.mergeObjects(interpretation, currentIntrpr[i]);
41
+ }
42
+ }
43
+
27
44
  }
28
- return gudhub.mergeObjects(defaultIntrprObj, currentIntrpr);
45
+
46
+ return interpretation;
29
47
  }
30
48
 
31
49
  /*********************** GET INTERPRETATION ***********************/
@@ -39,9 +57,9 @@ export class Interpritate {
39
57
  /*---- Constructing Data Object ----*/
40
58
  if (data_type) {
41
59
  /*-- if we have data_type then we construct new data object to interpritate value*/
42
- gudhub.ghconstructor.getInstance(data_type).then(function (data) {
60
+ gudhub.ghconstructor.getInstance(data_type).then(async function (data) {
43
61
  if(data) {
44
- var interpretationObj = self.getInterpretationObj(field, data.getTemplate().model, source, containerId);
62
+ var interpretationObj = await self.getInterpretationObj(field, data.getTemplate().model, source, containerId, itemId, appId);
45
63
  data.getInterpretation(value, interpretationObj.id, data_type, field, itemId, appId).then(function (result) {
46
64
  // console.log(result, interpretationObj)
47
65
 
@@ -1162,11 +1162,25 @@ export default function generateModulesList(async_modules_path, file_server_url,
1162
1162
  },
1163
1163
  {
1164
1164
  data_type: 'TwilioSMS',
1165
- name: 'Twilio',
1165
+ name: 'Twilio SMS',
1166
1166
  url: file_server_url + '/' + automation_modules_path + 'twilio_sms.js',
1167
1167
  type: 'automation',
1168
1168
  icon: 'automation_twilio'
1169
1169
  },
1170
+ {
1171
+ data_type: 'TwilioAuth',
1172
+ name: 'Twilio Auth',
1173
+ url: file_server_url + '/' + automation_modules_path + 'twilio_auth.js',
1174
+ type: 'automation',
1175
+ icon: 'table'
1176
+ },
1177
+ {
1178
+ data_type: 'TwilioDevice',
1179
+ name: 'Twilio Device',
1180
+ url: file_server_url + '/' + automation_modules_path + 'twilio_device.js',
1181
+ type: 'automation',
1182
+ icon: 'table'
1183
+ },
1170
1184
  {
1171
1185
  data_type: 'UpdateItemsApi',
1172
1186
  name: 'Update Items Api',
@@ -1253,6 +1267,13 @@ export default function generateModulesList(async_modules_path, file_server_url,
1253
1267
  url: file_server_url + '/' + automation_modules_path + 'delete_items.js',
1254
1268
  type: 'automation',
1255
1269
  icon: 'rubbish'
1270
+ },
1271
+ {
1272
+ data_type: 'GoToItem',
1273
+ name: 'Go To Item',
1274
+ url: file_server_url + '/' + automation_modules_path + 'go_to_item.js',
1275
+ type: 'automation',
1276
+ icon: 'cursor_point'
1256
1277
  }
1257
1278
  ]
1258
1279
  }
@@ -23,6 +23,7 @@ import AppsTemplateService from "./AppsTemplateService/AppsTemplateService.js";
23
23
  import { FileHelper } from "./FIleHelper/FileHelper.js";
24
24
  import { compareObjects } from "./compareObjects/compareObjects.js";
25
25
  import { dynamicPromiseAll } from "./dynamicPromiseAll/dynamicPromiseAll.js";
26
+ import { sortItems } from './filter/sortItems.js';
26
27
 
27
28
  export class Utils {
28
29
  constructor(gudhub) {
@@ -212,4 +213,8 @@ export class Utils {
212
213
  dynamicPromiseAll(promisesArray) {
213
214
  return dynamicPromiseAll(promisesArray);
214
215
  }
216
+
217
+ sortItems(items, options) {
218
+ return sortItems(items, options);
219
+ }
215
220
  }
@@ -0,0 +1,63 @@
1
+
2
+ /**
3
+ * Sort items by field value of given field
4
+ *
5
+ * @param {array} items - items of application
6
+ * @param {object} options - object with options for sorting
7
+ * @property {number|string} sort_field_id - field id for sorting items
8
+ * @property {boolean} descending - sort type (if set to true - items sort by descending else by ascending)
9
+ *
10
+ */
11
+
12
+ export function sortItems(items, options) {
13
+
14
+ /*-- stop filtering if arguments are empty*/
15
+ if (!items || !items.length) {
16
+ return [];
17
+ }
18
+
19
+ if (!items[0].fields.length) {
20
+ return items;
21
+ }
22
+
23
+ var compareFieldId = options && options.sort_field_id || items[0].fields[0].field_id;
24
+
25
+ /* Get field value*/
26
+ function getFieldValue(item) {
27
+ var result = null;
28
+ for (var i = 0; i < item.fields.length; i++) {
29
+
30
+ if (item.fields[i].field_id == compareFieldId) {
31
+ result = item.fields[i].field_value;
32
+ break;
33
+ }
34
+
35
+ }
36
+ return result;
37
+
38
+ }
39
+
40
+ /* Sort items array*/
41
+ items.sort(function(a, b) {
42
+ var aVal = getFieldValue(a);
43
+ var bVal = getFieldValue(b);
44
+
45
+ if (aVal === null) {
46
+ return -1;
47
+ }
48
+ if (bVal === null) {
49
+ return 1;
50
+ }
51
+
52
+ if (/^\d+$/.test(aVal) && /^\d+$/.test(bVal)) {
53
+ return Number(aVal) < Number(bVal) ? -1 : 1;
54
+ }
55
+
56
+ if (/^\d+$/.test(aVal) || /^\d+$/.test(bVal)) {
57
+ return /^\d+$/.test(aVal) ? -1 : 1;
58
+ }
59
+
60
+ return aVal.toLowerCase() > bVal.toLowerCase() ? 1 : -1;
61
+ });
62
+ return options && options.descending ? items.reverse() : items;
63
+ }
@@ -0,0 +1,26 @@
1
+ import {GudHub} from './../../gudhub.js';
2
+
3
+ import { app_8263 } from '../../../fake_server/fake_server_data/app_8263.js';
4
+
5
+ const items = app_8263.items_list;
6
+
7
+ describe('Sort Items', function() {
8
+ const gudhub = new GudHub();
9
+
10
+ it('Should return sorted items by descending', function(){
11
+ const options = {
12
+ sort_field_id: "96606",
13
+ descending: true
14
+ }
15
+ gudhub.sortItems(items, options)[0].item_id.should.equal(396898);
16
+ });
17
+
18
+ it('Should return sorted items by ascending', function(){
19
+ const options = {
20
+ sort_field_id: "96606",
21
+ descending: false
22
+ }
23
+ gudhub.sortItems(items, options)[0].item_id.should.equal(396906);
24
+ });
25
+
26
+ });
package/GUDHUB/gudhub.js CHANGED
@@ -198,6 +198,10 @@ export class GudHub {
198
198
  );
199
199
  }
200
200
 
201
+ sortItems(items, options) {
202
+ return this.util.sortItems(items, options);
203
+ }
204
+
201
205
  jsonToItems(json, map) {
202
206
  return this.util.jsonToItems(json, map);
203
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.1.74",
3
+ "version": "1.1.76",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {