forked from likeastore/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter-events.js
More file actions
37 lines (34 loc) · 913 Bytes
/
Copy pathfilter-events.js
File metadata and controls
37 lines (34 loc) · 913 Bytes
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
'use strict';
angular.module('dashboardApp').service('filterEvents', function() {
this.getEvents = function() {
return localStorage.neededEvents && JSON.parse(localStorage.neededEvents);
};
this.filter = function(events) {
var result = [],
neededEvents = localStorage.neededEvents && JSON.parse(localStorage.neededEvents);
if(!neededEvents) {
result = events.map(function(event) {
return {
key: event,
value: true
}
});
} else {
for(var i = 0; i < events.length; i++) {
var value = neededEvents.indexOf(events[i]) != -1 || false;
result.push({key: events[i], value: value});
}
}
this.setEvents(result);
return result;
};
this.setEvents = function(events) {
var result = events
.filter(function(item) {
return item.value;
}).map(function(item) {
return item.key;
});
localStorage.neededEvents = JSON.stringify(result);
};
});