function filterMultiple($filter) { return function (items, keyObj) { if(items === 'undefined') return ''; var filterObj = { data:items, filteredData:[], applyFilter : function(obj,key){ var fData = []; if(this.filteredData.length == 0) this.filteredData = this.data; if(obj){ var fObj = {}; if(angular.isString(obj)){ fObj[key] = obj; fData = fData.concat($filter('filter')(this.filteredData,fObj)); }else if(angular.isArray(obj)){ if(obj.length > 0){ for(var i=0;i 0){ this.filteredData = fData; } } } }; if(keyObj){ angular.forEach(keyObj,function(obj,key){ filterObj.applyFilter(obj,key); }); } return filterObj.filteredData; } }; function filterlevel(){ return function(input, val) { var result = []; input.forEach(function(item){ // if(item.level.indexOf(value*1) > -1){ // result.push(item); // } var chk = false; if(item.val & parseInt(val[0])) chk = true; if(item.cust){ if(item.cust & parseInt(val[1])) { chk = true; } else { chk = false; } } if(chk)result.push(item) }); return result; }; } function reverse() { return function(items) { return items.slice().reverse(); }; }; function sumOfValue() { return function (data, key) { if (angular.isUndefined(data) || angular.isUndefined(key)) return 0; var sum = 0; angular.forEach(data,function(value){ sum = sum + parseFloat(value[key], 10); }); return sum; } }; function timeformat(){ return function(input){ // console.log(input.length); return; if(input.length!=8) return input; var zero = new Padder(2); var tm = input.split(':'); var hr = parseInt(tm[0]); var mn = tm[1]; var mystr = ''; var s = ''; if(hr>12 ){ hr -= 12; s = 'PM'; } else { s = 'AM'; } mystr = zero.pad(hr) + ":" + mn + s; return mystr; } } function totalSumPriceQty() { return function (data, key1, key2) { if (angular.isUndefined(data) || angular.isUndefined(key1) || angular.isUndefined(key2)) return 0; var sum = 0; angular.forEach(data,function(value){ sum = sum + (parseInt(value[key1], 10) * parseInt(value[key2], 10)); }); return sum; } }; function unique() { // we will return a function which will take in a collection // and a keyname return function(collection, keyname) { // we define our output and keys array; var output = [], keys = []; // we utilize angular's foreach function // this takes in our original collection and an iterator function angular.forEach(collection, function(item) { // we check to see whether our object exists var key = item[keyname]; if(key != null){ // if it's not already part of our keys array if(keys.indexOf(key) === -1) { // add it to our keys array keys.push(key); // push this item to our final output array output.push(item); } } }); // return our array which should be devoid of // any duplicates return output; }; }; angular.module('mzzsetia') .filter('filterMultiple',filterMultiple) .filter('filterlevel',filterlevel) .filter('reverse',reverse) .filter('sumOfValue',sumOfValue) .filter('timeformat',timeformat) .filter('totalSumPriceQty',totalSumPriceQty) .filter('unique',unique)