@gudhub/core 1.1.75 → 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.
- package/GUDHUB/Storage/ModulesList.js +7 -0
- package/GUDHUB/Utils/Utils.js +5 -0
- package/GUDHUB/Utils/filter/sortItems.js +63 -0
- package/GUDHUB/Utils/filter/sortItems.test.js +26 -0
- package/GUDHUB/gudhub.js +4 -0
- package/package.json +1 -1
- package/umd/library.min.js +50 -50
- package/umd/library.min.js.map +1 -1
|
@@ -1267,6 +1267,13 @@ export default function generateModulesList(async_modules_path, file_server_url,
|
|
|
1267
1267
|
url: file_server_url + '/' + automation_modules_path + 'delete_items.js',
|
|
1268
1268
|
type: 'automation',
|
|
1269
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'
|
|
1270
1277
|
}
|
|
1271
1278
|
]
|
|
1272
1279
|
}
|
package/GUDHUB/Utils/Utils.js
CHANGED
|
@@ -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