Skip to content

Instantly share code, notes, and snippets.

@gdoteof
Created August 8, 2014 17:43
Show Gist options
  • Save gdoteof/94cc37b0cb9710f3d8cd to your computer and use it in GitHub Desktop.
Save gdoteof/94cc37b0cb9710f3d8cd to your computer and use it in GitHub Desktop.
filter examples
<div class="col-md-3 thumbnail-container magic-animate apositive"
ng-repeat="object in filteredpos = (container.objects | classIs: 1 | orderBy:'score' | scoreIs:'>':pos.lowest | scoreIs: '<': pos.highest)">
<vmx-exemplar score="object.score" image="{{object.image}}" tyme="{{object.time}}" class="object.class_label"></vmx-exemplar>
</div>
vmxServices
.filter('includeParams',function(){
return function(objects,toInclude){
if (toInclude && toInclude instanceof Array){
var tmpParams = {};
for(var paramName in objects){
if(!paramName){ continue; }
if(toInclude.indexOf(paramName) !== -1 || _.intersection(objects[paramName].group, toInclude).length){
tmpParams[paramName] = objects[paramName];
}
}
objects = tmpParams;
}
return objects;
};
});
vmxServices
.filter('modelNameContains',function(){
return function(objects,name){
if(!objects) {
return [];
}
return objects.filter(
function(elm){ return (elm.model.name !== "none") && !name || elm.model.name.indexOf(name) !== -1 }
);
};
});
vmxServices
.filter('scoreIs',function(){
return function(objects,op,_score){
var op_fun;
if(typeof _score === 'undefined' || _score === '') {
return objects;
}
switch(op){
case '<':
case 'lt': op_fun = function(left,right){ return left < right; };
break;
case '>':
case 'gt': op_fun = function(left,right){ return left > right; };
}
return objects.filter(function(elm){ return op_fun(elm.score,_score); });
};
});;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment