blob: ed1f537d0c331aa816dcb2af15253990a2937fff (
plain)
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
|
var mach2Filters = angular.module('mach2Filters',[]);
mach2Filters.filter('alphabetFilter', function() {
return function(items, search) {
if (!search) {
return items;
}
return items.filter(function(element, index, array) {
var searchTerm = search.param;
var searchAttrs = search.attrs;
var regexp = new RegExp(searchTerm, 'i');
var searchString = null;
for(i = 0; i < searchAttrs.length; i++) {
if (element[searchAttrs[i]]) {
searchString = element[searchAttrs[i]];
break;
}
}
if (searchTerm === '0-9') {
regexp = /[0-9]/;
} else if (searchTerm === 'Other') {
regexp = /\W/;
}
if (searchString.charAt(0).match(regexp) !== null) {
return true;
} else {
return false;
}
});
};
});
mach2Filters.filter('dateFilter', function() {
return function(items, search) {
return items.filter(function(element, index, array) {
var albumDate = moment(element.date, 'YYYY-MM-DD');
var compDate = moment(search, 'YYYY');
var compNextDate = moment((parseInt(search) + 10), 'YYYY');
return (albumDate.isAfter(compDate) && albumDate.isBefore(compNextDate));
});
};
});
|