all files / app/core/filters/ filterByPropIds.filter.js

16.67% Statements 3/18
0% Branches 0/9
33.33% Functions 1/3
16.67% Lines 3/18
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                                                                                          
(function ()
{
    'use strict';
 
    angular
        .module('app.core')
        .filter('filterByPropIds', filterByPropIds);
 
    /** @ngInject */
    function filterByPropIds()
    {
        return function (items, parameter, ids)
        {
            if ( items.length === 0 || !ids || ids.length === 0 )
            {
                return items;
            }
 
            var filtered = [];
 
            for ( var i = 0; i < items.length; i++ )
            {
                var item = items[i];
                var match = false;
 
                for ( var j = 0; j < ids.length; j++ )
                {
                    var id = ids[j];
                    if ( item[parameter].indexOf(id) > -1 )
                    {
                        match = true;
                        break;
                    }
                }
 
                if ( match )
                {
                    filtered.push(item);
                }
 
            }
 
            return filtered;
 
        };
    }
 
})();