11/**
22* @author Jason Dobry <jason.dobry@gmail.com>
33* @file angular-data.js
4- * @version 1.4.1 - Homepage <http://angular-data.pseudobry.com/>
4+ * @version 1.4.2 - Homepage <http://angular-data.pseudobry.com/>
55* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
66* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77*
@@ -4139,6 +4139,7 @@ Defaults.prototype.idAttribute = 'id';
41394139Defaults . prototype . defaultAdapter = 'DSHttpAdapter' ;
41404140Defaults . prototype . defaultFilter = function ( collection , resourceName , params , options ) {
41414141 var _this = this ;
4142+ var DSUtils = _this . utils ;
41424143 var filtered = collection ;
41434144 var where = null ;
41444145 var reserved = {
@@ -4152,14 +4153,14 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
41524153
41534154 params = params || { } ;
41544155
4155- if ( _this . utils . isObject ( params . where ) ) {
4156+ if ( DSUtils . isObject ( params . where ) ) {
41564157 where = params . where ;
41574158 } else {
41584159 where = { } ;
41594160 }
41604161
41614162 if ( options . allowSimpleWhere ) {
4162- _this . utils . forEach ( params , function ( value , key ) {
4163+ DSUtils . forEach ( params , function ( value , key ) {
41634164 if ( ! ( key in reserved ) && ! ( key in where ) ) {
41644165 where [ key ] = {
41654166 '==' : value
@@ -4168,26 +4169,26 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
41684169 } ) ;
41694170 }
41704171
4171- if ( _this . utils . isEmpty ( where ) ) {
4172+ if ( DSUtils . isEmpty ( where ) ) {
41724173 where = null ;
41734174 }
41744175
41754176 if ( where ) {
4176- filtered = _this . utils . filter ( filtered , function ( attrs ) {
4177+ filtered = DSUtils . filter ( filtered , function ( attrs ) {
41774178 var first = true ;
41784179 var keep = true ;
4179- _this . utils . forEach ( where , function ( clause , field ) {
4180- if ( _this . utils . isString ( clause ) ) {
4180+ DSUtils . forEach ( where , function ( clause , field ) {
4181+ if ( DSUtils . isString ( clause ) ) {
41814182 clause = {
41824183 '===' : clause
41834184 } ;
4184- } else if ( _this . utils . isNumber ( clause ) || _this . utils . isBoolean ( clause ) ) {
4185+ } else if ( DSUtils . isNumber ( clause ) || DSUtils . isBoolean ( clause ) ) {
41854186 clause = {
41864187 '==' : clause
41874188 } ;
41884189 }
4189- if ( _this . utils . isObject ( clause ) ) {
4190- _this . utils . forEach ( clause , function ( val , op ) {
4190+ if ( DSUtils . isObject ( clause ) ) {
4191+ DSUtils . forEach ( clause , function ( val , op ) {
41914192 if ( op === '==' ) {
41924193 keep = first ? ( attrs [ field ] == val ) : keep && ( attrs [ field ] == val ) ;
41934194 } else if ( op === '===' ) {
@@ -4205,9 +4206,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42054206 } else if ( op === '<=' ) {
42064207 keep = first ? ( attrs [ field ] <= val ) : keep && ( attrs [ field ] <= val ) ;
42074208 } else if ( op === 'in' ) {
4208- keep = first ? _this . utils . contains ( val , attrs [ field ] ) : keep && _this . utils . contains ( val , attrs [ field ] ) ;
4209+ if ( DSUtils . isString ( val ) ) {
4210+ keep = first ? val . indexOf ( attrs [ field ] ) !== - 1 : keep && val . indexOf ( attrs [ field ] ) !== - 1 ;
4211+ } else {
4212+ keep = first ? DSUtils . contains ( val , attrs [ field ] ) : keep && DSUtils . contains ( val , attrs [ field ] ) ;
4213+ }
42094214 } else if ( op === 'notIn' ) {
4210- keep = first ? ! _this . utils . contains ( val , attrs [ field ] ) : keep && ! _this . utils . contains ( val , attrs [ field ] ) ;
4215+ if ( DSUtils . isString ( val ) ) {
4216+ keep = first ? val . indexOf ( attrs [ field ] ) === - 1 : keep && val . indexOf ( attrs [ field ] ) === - 1 ;
4217+ } else {
4218+ keep = first ? ! DSUtils . contains ( val , attrs [ field ] ) : keep && ! DSUtils . contains ( val , attrs [ field ] ) ;
4219+ }
42114220 } else if ( op === '|==' ) {
42124221 keep = first ? ( attrs [ field ] == val ) : keep || ( attrs [ field ] == val ) ;
42134222 } else if ( op === '|===' ) {
@@ -4225,9 +4234,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42254234 } else if ( op === '|<=' ) {
42264235 keep = first ? ( attrs [ field ] <= val ) : keep || ( attrs [ field ] <= val ) ;
42274236 } else if ( op === '|in' ) {
4228- keep = first ? _this . utils . contains ( val , attrs [ field ] ) : keep || _this . utils . contains ( val , attrs [ field ] ) ;
4237+ if ( DSUtils . isString ( val ) ) {
4238+ keep = first ? val . indexOf ( attrs [ field ] ) !== - 1 : keep || val . indexOf ( attrs [ field ] ) !== - 1 ;
4239+ } else {
4240+ keep = first ? DSUtils . contains ( val , attrs [ field ] ) : keep || DSUtils . contains ( val , attrs [ field ] ) ;
4241+ }
42294242 } else if ( op === '|notIn' ) {
4230- keep = first ? ! _this . utils . contains ( val , attrs [ field ] ) : keep || ! _this . utils . contains ( val , attrs [ field ] ) ;
4243+ if ( DSUtils . isString ( val ) ) {
4244+ keep = first ? val . indexOf ( attrs [ field ] ) === - 1 : keep || val . indexOf ( attrs [ field ] ) === - 1 ;
4245+ } else {
4246+ keep = first ? ! DSUtils . contains ( val , attrs [ field ] ) : keep || ! DSUtils . contains ( val , attrs [ field ] ) ;
4247+ }
42314248 }
42324249 first = false ;
42334250 } ) ;
@@ -4239,29 +4256,29 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42394256
42404257 var orderBy = null ;
42414258
4242- if ( _this . utils . isString ( params . orderBy ) ) {
4259+ if ( DSUtils . isString ( params . orderBy ) ) {
42434260 orderBy = [
42444261 [ params . orderBy , 'ASC' ]
42454262 ] ;
4246- } else if ( _this . utils . isArray ( params . orderBy ) ) {
4263+ } else if ( DSUtils . isArray ( params . orderBy ) ) {
42474264 orderBy = params . orderBy ;
42484265 }
42494266
4250- if ( ! orderBy && _this . utils . isString ( params . sort ) ) {
4267+ if ( ! orderBy && DSUtils . isString ( params . sort ) ) {
42514268 orderBy = [
42524269 [ params . sort , 'ASC' ]
42534270 ] ;
4254- } else if ( ! orderBy && _this . utils . isArray ( params . sort ) ) {
4271+ } else if ( ! orderBy && DSUtils . isArray ( params . sort ) ) {
42554272 orderBy = params . sort ;
42564273 }
42574274
42584275 // Apply 'orderBy'
42594276 if ( orderBy ) {
42604277 var index = 0 ;
42614278 angular . forEach ( orderBy , function ( def , i ) {
4262- if ( _this . utils . isString ( def ) ) {
4279+ if ( DSUtils . isString ( def ) ) {
42634280 orderBy [ i ] = [ def , 'ASC' ] ;
4264- } else if ( ! _this . utils . isArray ( def ) ) {
4281+ } else if ( ! DSUtils . isArray ( def ) ) {
42654282 throw new _this . errors . IllegalArgumentError ( 'DS.filter(resourceName[, params][, options]): ' + JSON . stringify ( def ) + ': Must be a string or an array!' , {
42664283 params : {
42674284 'orderBy[i]' : {
@@ -4271,8 +4288,8 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42714288 }
42724289 } ) ;
42734290 }
4274- filtered = _this . utils . sort ( filtered , function ( a , b ) {
4275- return compare ( _this . utils , orderBy , index , a , b ) ;
4291+ filtered = DSUtils . sort ( filtered , function ( a , b ) {
4292+ return compare ( DSUtils , orderBy , index , a , b ) ;
42764293 } ) ;
42774294 } ) ;
42784295 }
0 commit comments