-
Notifications
You must be signed in to change notification settings - Fork 2
/
processFilters.js
89 lines (75 loc) · 2.31 KB
/
processFilters.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
document.querySelector("form").addEventListener("click", processActiveFilters);
function processActiveFilters() {
var filt_data = Jobs.map(function(el){return el});
var activeCBs = document.querySelectorAll('input[type="checkbox"]:checked');
var freshness = +(document.getElementById('freshness').value);
// console.log(freshness);
var experience = +(document.getElementById("experience").value);
var exp_value = document.getElementById('exp-value')
if(experience == 31){
exp_value.textContent = 'Any';
}
else{
exp_value.textContent = experience;
}
var activeSalaryCBs = [...activeCBs].filter(function (el) {
return el.name == "salary";
});
var activeEducationCBs = [...activeCBs].filter(function (el) {
return el.name == "education";
});
var activeLocationCBs = [...activeCBs].filter(function (el) {
return el.name == "location";
});
var wfh = [...activeCBs].filter(function (el) {
return el.name == "wfh";
});
console.log(activeLocationCBs);
if(freshness != -1){
filt_data = filterByFreshness(filt_data,freshness);
}
if(experience !=31 && experience<=30 ){
filt_data = filterByExperience(filt_data,experience);
}
if(activeEducationCBs.length > 0){
let tmp = [];
for(cb of activeEducationCBs){
console.log(cb.value);
res = filterByEducation(filt_data,cb.value);
tmp.push(...res);
}
filt_data = tmp;
}
if(activeLocationCBs.length>0){
let tmp = [];
for (cb of activeLocationCBs){
res = filterByLocation(filt_data,cb.value);
tmp.push(...res);
}
filt_data = tmp;
}
if(activeSalaryCBs.length > 0){
let tmp = [];
for(cb of activeSalaryCBs){
res = filterBySalary(filt_data,JSON.parse(cb.value));
tmp.push(...res);
}
filt_data = tmp;
}
if(wfh.length > 0)
filt_data = filterByWFH(filt_data);
// remove duplicates, the in which data is filtered will produce duplicate entries when certain conditions are met
filt_data = removeDuplicates(filt_data,'id');
renderData(filt_data);
}
function removeDuplicates(array,key){
let tmpObj = {};
let unique = [];
for( let i=0;i<array.length;i++){
if(tmpObj[array[i][key]] == undefined){
tmpObj[array[i][key]] = true;
unique.push(array[i]);
}
}
return unique;
}