Skip to content

Commit

Permalink
Update to latest version of AeroGear.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kborchers committed Dec 17, 2012
1 parent 069e694 commit 24403b0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 17 deletions.
74 changes: 59 additions & 15 deletions app/scripts/vendor/aerogear.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! AeroGear JavaScript Library - v1.0.0.Alpha - 2012-12-11
/*! AeroGear JavaScript Library - v1.0.0.Alpha - 2012-12-13
* https://github.com/aerogear/aerogear-js
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
Expand Down Expand Up @@ -1062,6 +1062,33 @@ AeroGear.Core = function() {
this.getDataSync = function() {
return dataSync;
};

/**
Little utility used to compare nested object values in the filter method
@private
@augments Memory
@param {String} nestedKey - Filter key to test
@param {Object} nestedFilter - Filter object to test
@param {Object} nestedValue - Value object to test
@returns {Boolean}
*/
this.traverseObjects = function( nestedKey, nestedFilter, nestedValue ) {
while ( typeof nestedFilter === "object" ) {
if ( nestedValue ) {
// Value contains this key so continue checking down the object tree
nestedKey = Object.keys( nestedFilter )[ 0 ];
nestedFilter = nestedFilter[ nestedKey ];
nestedValue = nestedValue[ nestedKey ];
} else {
break;
}
}
if ( nestedFilter === nestedValue ) {
return true;
} else {
return false;
}
};
};

// Public Methods
Expand Down Expand Up @@ -1213,8 +1240,8 @@ AeroGear.Core = function() {
});
*/
AeroGear.DataManager.adapters.Memory.prototype.filter = function( filterParameters, matchAny ) {
var filtered,
key, j, k, l;
var filtered, key, j, k, l, nestedKey, nestedFilter, nestedValue,
that = this;

if ( !filterParameters ) {
filtered = this.getData() || [];
Expand All @@ -1234,7 +1261,7 @@ AeroGear.Core = function() {

for ( j = 0; j < filterObj.data.length; j++ ) {
if( AeroGear.isArray( value[ keys[ key ] ] ) ) {
if(value[ keys [ key ] ].length ) {
if( value[ keys [ key ] ].length ) {
if( $( value[ keys ] ).not( filterObj.data ).length === 0 && $( filterObj.data ).not( value[ keys ] ).length === 0 ) {
paramResult = true;
break;
Expand Down Expand Up @@ -1266,15 +1293,28 @@ AeroGear.Core = function() {
paramResult = false;
}
} else {
if ( filterObj.matchAny && filterObj.data[ j ] === value[ keys[ key ] ] ) {
// At least one value must match and this one does so return true
paramResult = true;
break;
}
if ( !filterObj.matchAny && filterObj.data[ j ] !== value[ keys[ key ] ] ) {
// All must match but this one doesn't so return false
paramResult = false;
break;
if ( typeof filterObj.data[ j ] === "object" ) {
if ( filterObj.matchAny && that.traverseObjects( keys[ key ], filterObj.data[ j ], value[ keys[ key ] ] ) ) {
// At least one value must match and this one does so return true
paramResult = true;
break;
}
if ( !filterObj.matchAny && !that.traverseObjects( keys[ key ], filterObj.data[ j ], value[ keys[ key ] ] ) ) {
// All must match but this one doesn't so return false
paramResult = false;
break;
}
} else {
if ( filterObj.matchAny && filterObj.data[ j ] === value[ keys[ key ] ] ) {
// At least one value must match and this one does so return true
paramResult = true;
break;
}
if ( !filterObj.matchAny && filterObj.data[ j ] !== value[ keys[ key ] ] ) {
// All must match but this one doesn't so return false
paramResult = false;
break;
}
}
}
}
Expand All @@ -1283,7 +1323,7 @@ AeroGear.Core = function() {
if( AeroGear.isArray( value[ keys[ key ] ] ) ) {
paramResult = matchAny ? false: true;

if(value[ keys[ key ] ].length ) {
if( value[ keys[ key ] ].length ) {
for(j = 0; j < value[ keys[ key ] ].length; j++ ) {
if( matchAny && filterParameters[ keys[ key ] ] === value[ keys[ key ] ][ j ] ) {
//at least one must match and this one does so return true
Expand All @@ -1300,7 +1340,11 @@ AeroGear.Core = function() {
paramResult = false;
}
} else {
paramResult = filterParameters[ keys[ key ] ] === value[ keys[ key ] ] ? true : false;
if ( typeof filterParameters[ keys[ key ] ] === "object" ) {
paramResult = that.traverseObjects( keys[ key ], filterParameters[ keys[ key ] ], value[ keys[ key ] ] );
} else {
paramResult = filterParameters[ keys[ key ] ] === value[ keys[ key ] ] ? true : false;
}
}
}

Expand Down
Loading

0 comments on commit 24403b0

Please sign in to comment.