self addFilter function filter lookup value isNot var item filter filt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
self.addFilter = function(filter, lookup, value, isNot) {
var item = {filter: filter, values: [], isNot: isNot};
var types = filter.type.split('|'),
keys = filter.key.split('|'),
values = (value !== undefined) ? value.split('|') : [],
lookups = (lookup !== undefined) ? lookup.split('|') : [];
for (var i = 0; i < keys.length; i++) {
var v = {type: types[i], lookup: lookups[i]};
if (types[i] == 'dt') {
if (v.lookup == 'range') {
var range = values[i].split('r');
v.value = {from: moment(range[0]), to: moment(range[1])};
}
else if (['exact', 'lte', 'gte'].indexOf(v.lookup) > -1)
v.value = {from: moment(values[i])};
else
v.value = {days: values[i]};
} else
v.value = values[i];
v.lookup = lookups[i];
if (types[i] == 'sl') {
v.facets = $scope.filtering.getFacetsAction(keys[i])({facet: keys[i]});
}
item.values.push(v);
}
return item;
};
self.getQueryFilters = function(query){
var filters = [];
angular.forEach(query.items, function(item) {
var values = [], lookups = [];
angular.forEach(item.values, function (v) {
if (v.lookup !== undefined && v.value !== undefined && v.value !== '') {
if (v.type == 'dt') {
if (v.lookup == 'range')
v._value = v.value.from.format("YYYY-MM-DD") + 'r' + v.value.to.format("YYYY-MM-DD");
else if (['exact', 'lte', 'gte'].indexOf(v.lookup) > -1)
v._value = v.value.from.format("YYYY-MM-DD");
else
v._value = v.value.days;
} else
v._value = v.value;
values.push(v._value);
lookups.push(v.lookup);
}
});
filters.push({filter: item.filter.id, lookup: lookups.join('|'), value: values.join('|'), is_not: item.isNot});
});
return filters;
};