Skip to content

Commit

Permalink
Merge pull request #56 from subpx/master
Browse files Browse the repository at this point in the history
Added support for Lambda operations
  • Loading branch information
devnixs committed Apr 3, 2016
2 parents ee0db37 + 8682d52 commit bd5648f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ double ceiling(double p0) | new $odata.Func('ceiling','Freight') | 33d
decimal ceiling(decimal p0) | new $odata.Func('floor','Freight') | 33
**Type Functions** | |
bool IsOf(expression p0, type p1) | new $odata.Func('isof','ShipCountry', 'Edm.String') | true
**Lambda Functions** | |
bool any(string p0, expression p1) | new $odata.Func('any','Categories', $odata.Predicate("firstName", "Bobby")) | true
bool all(string p0, expression p1) | new $odata.Func('any','Categories', $odata.Predicate("firstName", "Bobby")) | true

### OData V4 support
This project supports basic odata v4 queries and responses.
Expand Down
31 changes: 25 additions & 6 deletions build/odataresources.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,33 @@ factory('$odataMethodCall', ['$odataProperty', '$odataValue',
};

ODataMethodCall.prototype.execute = function() {
var invocation = this.methodName + "(";
for (var i = 0; i < this.params.length; i++) {
if (i > 0)
invocation += ",";
var lambdaOperators = ["any", "all"];
var invocation = "";

if(lambdaOperators.indexOf(this.methodName) > -1) {
for (var i = 0; i < this.params.length; i++) {
if (i === 0) {
var navigationPath = this.params[i].execute();
var varName = navigationPath.charAt(0).toLowerCase();
invocation += navigationPath + "/" + this.methodName + "(" + varName + ":" + varName + "/";
} else {
var expression = this.params[i].execute();
invocation += expression.substring(1, expression.length-1);
invocation += ")";
}
}
} else {
invocation += this.methodName + "(";

invocation += this.params[i].execute();
for (var j = 0; j < this.params.length; j++) {
if (j > 0)
invocation += ",";

invocation += this.params[j].execute();
}
invocation += ")";
}
invocation += ")";

return invocation;
};

Expand Down
4 changes: 2 additions & 2 deletions build/odataresources.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions specs/ODataTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@
var func = new $odata.Func("endswith", new $odata.Value("abc"), new $odata.Property("Name"));
expect(func.execute()).toBe("endswith('abc',Name)");
});
it('should allow lambda operator', function() {
var predicate = new $odata.Predicate("firstName", "Bobby");
var func = new $odata.Func("any", "clients", predicate);

expect(func.execute()).toBe("clients/any(c:c/firstName eq 'Bobby')");
});
});
});
describe('ODataProperty', function() {
Expand Down
31 changes: 25 additions & 6 deletions src/odatamethodcall.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,33 @@ factory('$odataMethodCall', ['$odataProperty', '$odataValue',
};

ODataMethodCall.prototype.execute = function() {
var invocation = this.methodName + "(";
for (var i = 0; i < this.params.length; i++) {
if (i > 0)
invocation += ",";
var lambdaOperators = ["any", "all"];
var invocation = "";

invocation += this.params[i].execute();
if(lambdaOperators.indexOf(this.methodName) > -1) {
for (var i = 0; i < this.params.length; i++) {
if (i === 0) {
var navigationPath = this.params[i].execute();
var varName = navigationPath.charAt(0).toLowerCase();
invocation += navigationPath + "/" + this.methodName + "(" + varName + ":" + varName + "/";
} else {
var expression = this.params[i].execute();
invocation += expression.substring(1, expression.length-1);
invocation += ")";
}
}
} else {
invocation += this.methodName + "(";

for (var j = 0; j < this.params.length; j++) {
if (j > 0)
invocation += ",";

invocation += this.params[j].execute();
}
invocation += ")";
}
invocation += ")";

return invocation;
};

Expand Down

0 comments on commit bd5648f

Please sign in to comment.