summaryrefslogtreecommitdiff
path: root/static/scripts/app/filters.js
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2014-12-28 12:24:22 +0000
committerMichaël Ball <michael.ball@gmail.com>2015-11-27 20:02:04 +0000
commit75beec91a8526fbbc0a90134140b9dff6af15c0c (patch)
tree02414e46da3e08000384c40c27b7aab9748de0fe /static/scripts/app/filters.js
parenta2964845e3c03b9cf5f01583f53f7553c7d67caf (diff)
Initial frontend work
Diffstat (limited to 'static/scripts/app/filters.js')
-rw-r--r--static/scripts/app/filters.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/static/scripts/app/filters.js b/static/scripts/app/filters.js
new file mode 100644
index 0000000..ed1f537
--- /dev/null
+++ b/static/scripts/app/filters.js
@@ -0,0 +1,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));
+ });
+ };
+}); \ No newline at end of file