@gudhub/core 1.1.69 → 1.1.71
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/GHConstructor/interpritate.js +5 -19
- package/GUDHUB/Storage/ModulesList.js +9 -0
- package/GUDHUB/Utils/Utils.js +6 -4
- package/GUDHUB/Utils/filter/filter.js +66 -23
- package/GUDHUB/Utils/filter/filter.test.js +60 -0
- package/GUDHUB/Utils/filter/filterPreparation.js +2 -0
- package/GUDHUB/Utils/filter/mergeFilters.js +32 -0
- package/GUDHUB/gudhub.js +5 -0
- package/package.json +1 -1
- package/umd/library.min.js +51 -51
- package/umd/library.min.js.map +1 -1
|
@@ -4,10 +4,13 @@ export class Interpritate {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
/*********************** GET INTERPRETATION OBJ ***********************/
|
|
7
|
-
|
|
7
|
+
// In this method we are looking for interpretation in data model according to interpretation src
|
|
8
|
+
// then we merged with default interpretation from defaultFieldDataModel
|
|
9
|
+
// if there are no current interpretation we use default interpretation
|
|
8
10
|
getInterpretationObj(fieldDataModel, defaultFieldDataModel, src, containerId) {
|
|
9
11
|
var currentIntrpr = {};
|
|
10
12
|
|
|
13
|
+
// Creating default interpretation
|
|
11
14
|
var defaultIntrprObj = defaultFieldDataModel.data_model.interpretation.find(function (interpritation) {
|
|
12
15
|
return interpritation.src == src;
|
|
13
16
|
}) || defaultFieldDataModel.data_model.interpretation.find(function (interpritation) {
|
|
@@ -50,28 +53,11 @@ export class Interpritate {
|
|
|
50
53
|
}, function (error) { });
|
|
51
54
|
|
|
52
55
|
} else {
|
|
53
|
-
|
|
54
|
-
resolve(this.getDefaultInterpretation(value, field));
|
|
56
|
+
console.error('Get Interpretation: data_type is undefined', dataType, field);
|
|
55
57
|
}
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
/*********************** GET DEFAULT INTERPRETATION ***********************/
|
|
60
|
-
|
|
61
|
-
getDefaultInterpretation(value, options) {
|
|
62
|
-
var result = value;
|
|
63
|
-
|
|
64
|
-
if (options) {
|
|
65
|
-
/*-- Iterating through options from data_model to find a nave for selected*/
|
|
66
|
-
options.forEach(item => {
|
|
67
|
-
if(item.value == value && value != '') {
|
|
68
|
-
result = item.name;
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
61
|
/********************* GET INTERPRETATION BY ID *********************/
|
|
76
62
|
|
|
77
63
|
// We add ability to pass value as argument, to reduce number of operations in this case (getFieldValue)
|
|
@@ -909,6 +909,15 @@ export default function generateModulesList(async_modules_path, file_server_url,
|
|
|
909
909
|
type: 'gh_element',
|
|
910
910
|
technology: 'class'
|
|
911
911
|
},
|
|
912
|
+
{
|
|
913
|
+
data_type: 'static_nested_list',
|
|
914
|
+
name: 'Nested Filter',
|
|
915
|
+
icon: 'scheduling',
|
|
916
|
+
js: 'https://gudhub.com/modules/nested-filter/dist/main.js?t=1',
|
|
917
|
+
css: 'https://gudhub.com/modules/nested-filter/dist/style.css?t=1',
|
|
918
|
+
type: 'gh_element',
|
|
919
|
+
technology: 'class'
|
|
920
|
+
},
|
|
912
921
|
/* AUTOMATION MODULES */
|
|
913
922
|
/*
|
|
914
923
|
We have next types for automations:
|
package/GUDHUB/Utils/Utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { filterPreparation } from "./filter/filterPreparation.js";
|
|
2
2
|
import filter from "./filter/filter.js";
|
|
3
|
+
import { mergeFilters } from "./filter/mergeFilters.js";
|
|
3
4
|
import { jsonToItems } from "./json_to_items/json_to_items.js";
|
|
4
5
|
import {
|
|
5
6
|
mergeItems,
|
|
@@ -48,6 +49,10 @@ export class Utils {
|
|
|
48
49
|
return filter(items, filter_list);
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
mergeFilters(src, dest) {
|
|
53
|
+
return mergeFilters(src, dest);
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
group(fieldGroup, items) {
|
|
52
57
|
return group(fieldGroup, items);
|
|
53
58
|
}
|
|
@@ -68,10 +73,7 @@ export class Utils {
|
|
|
68
73
|
app_id,
|
|
69
74
|
item_id
|
|
70
75
|
);
|
|
71
|
-
const itemsList = this.filter(items,
|
|
72
|
-
...filters_list,
|
|
73
|
-
...modified_filters_list,
|
|
74
|
-
]);
|
|
76
|
+
const itemsList = this.filter(items, modified_filters_list);
|
|
75
77
|
const newItems = this.group(field_group, itemsList);
|
|
76
78
|
return newItems
|
|
77
79
|
.filter((newItem) => {
|
|
@@ -1,34 +1,13 @@
|
|
|
1
1
|
import { getDate, getDistanceFromLatLonInKm, isSimilarStrings } from "./utils.js";
|
|
2
2
|
|
|
3
3
|
export default function (items, filters) {
|
|
4
|
-
const
|
|
5
|
-
const filterChecker = new Checker();
|
|
4
|
+
const itemsFilter = new ItemsFilter();
|
|
6
5
|
|
|
7
6
|
if (!items || !items.length) {
|
|
8
7
|
return [];
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
return
|
|
12
|
-
return filters
|
|
13
|
-
.filter(function (filter) {
|
|
14
|
-
return filter.valuesArray.length;
|
|
15
|
-
})
|
|
16
|
-
.every(function (filter) {
|
|
17
|
-
var currField = item.fields.find(function (itemField) {
|
|
18
|
-
return filter.field_id == itemField.field_id;
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
filterAggregate
|
|
22
|
-
.setStrategy(filter.search_type)
|
|
23
|
-
.setEntity(
|
|
24
|
-
currField && currField.field_value != undefined
|
|
25
|
-
? currField.field_value
|
|
26
|
-
: null
|
|
27
|
-
)
|
|
28
|
-
.setFilterValues(filter.valuesArray);
|
|
29
|
-
return filterChecker.check(filterAggregate);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
10
|
+
return itemsFilter.filter(filters, items);
|
|
32
11
|
}
|
|
33
12
|
|
|
34
13
|
class Checker {
|
|
@@ -326,3 +305,67 @@ class Aggregate {
|
|
|
326
305
|
return this._checkOption;
|
|
327
306
|
}
|
|
328
307
|
}
|
|
308
|
+
|
|
309
|
+
class ItemsFilter {
|
|
310
|
+
constructor() {
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
filter(filters, items) {
|
|
315
|
+
|
|
316
|
+
const filteredItems = [];
|
|
317
|
+
const activeFilters = filters.filter(function (filter) {
|
|
318
|
+
return filter.valuesArray.length;
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
for(let item of items) {
|
|
322
|
+
let result = true;
|
|
323
|
+
|
|
324
|
+
for(let i = 0; i < activeFilters.length; i++) {
|
|
325
|
+
const filter = activeFilters[i];
|
|
326
|
+
|
|
327
|
+
const currField = item.fields.find(function (itemField) {
|
|
328
|
+
return filter.field_id == itemField.field_id;
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const filterAggregate = new Aggregate();
|
|
332
|
+
const filterChecker = new Checker();
|
|
333
|
+
|
|
334
|
+
filterAggregate
|
|
335
|
+
.setStrategy(filter.search_type)
|
|
336
|
+
.setEntity(
|
|
337
|
+
currField && currField.field_value != undefined
|
|
338
|
+
? currField.field_value
|
|
339
|
+
: null
|
|
340
|
+
)
|
|
341
|
+
.setFilterValues(filter.valuesArray);
|
|
342
|
+
|
|
343
|
+
switch(filter.boolean_strategy) {
|
|
344
|
+
case 'and':
|
|
345
|
+
result = result && filterChecker.check(filterAggregate);
|
|
346
|
+
break;
|
|
347
|
+
|
|
348
|
+
case 'or':
|
|
349
|
+
result = result || filterChecker.check(filterAggregate);
|
|
350
|
+
break;
|
|
351
|
+
|
|
352
|
+
default:
|
|
353
|
+
result = result && filterChecker.check(filterAggregate);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if(result) {
|
|
359
|
+
filteredItems.push(item);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if(filteredItems.length || filters.length && !filteredItems.length) {
|
|
364
|
+
return filteredItems;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
return items;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
}
|
|
371
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import should from 'should';
|
|
2
2
|
import {GudHub} from './../../gudhub.js';
|
|
3
3
|
|
|
4
|
+
import { app_8263 } from '../../../fake_server/fake_server_data/app_8263.js';
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
describe('Filter', function() {
|
|
@@ -9,6 +11,64 @@ import {GudHub} from './../../gudhub.js';
|
|
|
9
11
|
it('Should return one Item', function(){
|
|
10
12
|
gudhub.filter(items, filters).length.should.equal(1);
|
|
11
13
|
});
|
|
14
|
+
|
|
15
|
+
it('FILTER AND / should return items matching first AND second filter', function() {
|
|
16
|
+
const filters = [
|
|
17
|
+
{
|
|
18
|
+
"field_id": 96606,
|
|
19
|
+
"data_type": "text",
|
|
20
|
+
"valuesArray": [
|
|
21
|
+
"Dothan"
|
|
22
|
+
],
|
|
23
|
+
"search_type": "contain_or",
|
|
24
|
+
"boolean_strategy": "and",
|
|
25
|
+
"selected_search_option_variable": "Value"
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
{
|
|
29
|
+
"field_id": 96608,
|
|
30
|
+
"data_type": "phone",
|
|
31
|
+
"valuesArray": [
|
|
32
|
+
"677"
|
|
33
|
+
],
|
|
34
|
+
"search_type": "contain_or",
|
|
35
|
+
"boolean_strategy": "and",
|
|
36
|
+
"selected_search_option_variable": "Value"
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const filteredItems = gudhub.filter(app_8263.items_list, filters);
|
|
41
|
+
filteredItems.length.should.equal(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('FILTER OR / should return items matching first OR second filter', function() {
|
|
45
|
+
const filters = [
|
|
46
|
+
{
|
|
47
|
+
"field_id": 96606,
|
|
48
|
+
"data_type": "text",
|
|
49
|
+
"valuesArray": [
|
|
50
|
+
"Distributors"
|
|
51
|
+
],
|
|
52
|
+
"search_type": "contain_or",
|
|
53
|
+
"boolean_strategy": "and",
|
|
54
|
+
"selected_search_option_variable": "Value"
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
"field_id": 96608,
|
|
59
|
+
"data_type": "phone",
|
|
60
|
+
"valuesArray": [
|
|
61
|
+
"353"
|
|
62
|
+
],
|
|
63
|
+
"search_type": "contain_or",
|
|
64
|
+
"boolean_strategy": "or",
|
|
65
|
+
"selected_search_option_variable": "Value"
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const filteredItems = gudhub.filter(app_8263.items_list, filters);
|
|
70
|
+
filteredItems.length.should.equal(8);
|
|
71
|
+
});
|
|
12
72
|
|
|
13
73
|
});
|
|
14
74
|
|
|
@@ -55,6 +55,8 @@ export async function filterPreparation(
|
|
|
55
55
|
if (filters_list) {
|
|
56
56
|
for (const filter of filters_list) {
|
|
57
57
|
if (filter) {
|
|
58
|
+
// ---------------------- WARNING !!! -------------------------------
|
|
59
|
+
// Should be fixed: modification of filters_list valuesArray
|
|
58
60
|
switch (filter.input_type) {
|
|
59
61
|
case "variable":
|
|
60
62
|
const functionName =
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function mergeFilters(srcFilters, destFilters) {
|
|
2
|
+
const mergedFieldIds = [];
|
|
3
|
+
let filters = [];
|
|
4
|
+
|
|
5
|
+
if(srcFilters.length > 0) {
|
|
6
|
+
srcFilters.forEach(filter => {
|
|
7
|
+
filters.push(filter);
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
filters = destFilters;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if(filters.length > 0) {
|
|
14
|
+
|
|
15
|
+
filters.forEach((filter, index) => {
|
|
16
|
+
for(let i = 0; i < destFilters.length; i++) {
|
|
17
|
+
if(filter.field_id == destFilters[i].field_id) {
|
|
18
|
+
mergedFieldIds.push(filter.field_id);
|
|
19
|
+
filters[index] = gudhub.mergeObjects(destFilters[i], filter);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
for(let k = 0; k < destFilters.length; k++) {
|
|
25
|
+
if(!mergedFieldIds.includes(destFilters[k].field_id)) {
|
|
26
|
+
filters.push(destFilters[k]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
return filters;
|
|
32
|
+
}
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -176,6 +176,11 @@ export class GudHub {
|
|
|
176
176
|
return this.util.filter(items, filter_list);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
//============ MERGE FILTERS ==========//
|
|
180
|
+
mergeFilters(source, destination) {
|
|
181
|
+
return this.util.mergeFilters(source, destination);
|
|
182
|
+
}
|
|
183
|
+
|
|
179
184
|
//============ GROUP ==========//
|
|
180
185
|
group(fieldGroup, items) {
|
|
181
186
|
return this.util.group(fieldGroup, items);
|