From 02767d44ae50d1442320e3dfbb03dc3642269a67 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 8 Apr 2015 21:55:05 +0200 Subject: [PATCH] add filters.js --- angular_app/js/filters.js | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 angular_app/js/filters.js diff --git a/angular_app/js/filters.js b/angular_app/js/filters.js new file mode 100644 index 0000000..bf5a483 --- /dev/null +++ b/angular_app/js/filters.js @@ -0,0 +1,52 @@ +'use strict'; + +/* Filters for EventMan(ager) lists of objects. */ + +/* Filter for events that have (or not) information about a registered person. */ +eventManApp.filter('eventWithPersonData', ['$filter', + function($filter) { + return function(inputArray, mustBePresent) { + if (mustBePresent === undefined) { + mustBePresent = true; + } + inputArray = inputArray || []; + var returnArray = []; + for (var x=0; x < inputArray.length; x++) { + var found = inputArray[x].person_data && inputArray[x].person_data.person_id; + if ((found && mustBePresent) || (!found && !mustBePresent)) { + returnArray.push(inputArray[x]); + } + } + return returnArray; + }; + }] +); + + +/* Filter for persons (not) registered for a given event. */ +eventManApp.filter('personRegistered', ['$filter', + function($filter) { + return function(inputArray, data) { + if (data.present === undefined) { + data.present = true; + } + inputArray = inputArray || []; + var returnArray = []; + var registeredIDs = []; + if (!(data.event && data.event.persons && data.event.persons.length)) { + return inputArray; + } + for (var x=0; x < data.event.persons.length; x++) { + registeredIDs.push(data.event.persons[x].person_id); + } + for (var x=0; x < inputArray.length; x++) { + var found = registeredIDs.indexOf(inputArray[x]._id) != -1; + if ((found && data.present) || (!found && !data.present)) { + returnArray.push(inputArray[x]); + } + } + return returnArray; + } + }] +); +