From 75beec91a8526fbbc0a90134140b9dff6af15c0c Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Sun, 28 Dec 2014 12:24:22 +0000 Subject: Initial frontend work --- static/scripts/app/filters.js | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 static/scripts/app/filters.js (limited to 'static/scripts/app/filters.js') 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 -- cgit v1.2.3