Skip to content

Commit

Permalink
chore(pkg): update dist files
Browse files Browse the repository at this point in the history
update dist files.
  • Loading branch information
bret.ikehara committed Mar 17, 2016
1 parent 223f1b7 commit 1bc0660
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-eve-resource",
"version": "1.6.0",
"version": "1.6.1",
"homepage": "https://github.com/dailymotion/angular-eve-resource",
"authors": [
"Rahul Doshi <[email protected]>",
Expand Down
106 changes: 86 additions & 20 deletions dist/angular-eve-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ angular.module('com.dailymotion.ngEveResource', [

angular.module('com.dailymotion.ngEveResource')
.service('eve', function () {
function obj (key, comp, val) {
var o = {};
if (arguments.length === 3) {
(o[key] = {})[comp] = val;
} else {
o[key] = comp;
}
return o;
}

function prepareArgs () {
var args = angular.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.call(arguments);
return args.map(function (arg) {
Expand All @@ -19,6 +29,20 @@ angular.module('com.dailymotion.ngEveResource')
});
}

function simplify (conds, key) {
var newCond = [];

angular.forEach(conds, function (cond) {
if (cond[key]) {
newCond = [].concat(newCond, simplify(cond[key], key));
} else {
newCond.push(cond);
}
});

return newCond;
}

function isDefined (val) {
if (angular.isUndefined(val)) {
return false;
Expand All @@ -29,37 +53,79 @@ angular.module('com.dailymotion.ngEveResource')
return true;
}

function regexValue (val, match) {
if (angular.isFunction(match)) {
return match(val);
} else if (match === 'pre') {
return [
'.*?',
val,
].join('');
} else if (match === 'post') {
return [
val,
'.*?',
].join('');
} else if (match === 'wrap') {
return [
'.*?',
val,
'.*?',
].join('');
}
return val;
}

function regex (key, val, match) {
if (isDefined(key) && val) {
return obj(key, '$regex', regexValue(val, match));
}
}

function numComparison (comp) {
return function (key, num) {
if (angular.isNumber(num)) {
return obj(key, comp, num);
}
};
}

this.query = {
$and: function () {
var cond = prepareArgs.apply(null, arguments);
return cond.length > 1 ? {
$and: cond,
} : cond[0];
var cond = simplify(prepareArgs.apply(null, arguments), '$and');
return cond.length > 1 ? obj('$and', cond) : cond[0];
},
$or: function () {
var cond = prepareArgs.apply(null, arguments);
return cond.length > 1 ? {
$or: cond,
} : cond[0];
var cond = simplify(prepareArgs.apply(null, arguments), '$or');
return cond.length > 1 ? obj('$or', cond) : cond[0];
},
$eq: function (key, val) {
var o;
if (isDefined(key) && isDefined(val)) {
o = {};
o[key] = val;
return o;
return obj(key, val);
}
},
$ne: function (key, val) {
if (isDefined(key) && isDefined(val)) {
return obj(key, '$ne', val);
}
},
$in: function (key, val) {
if (isDefined(key) && angular.isArray(val)) {
return obj(key, '$in', val);
}
},
$like: function (key, val) {
var o;
if (isDefined(key) && val) {
o = {};
o[key] = {
$regex: val
};
return o;
$nin: function (key, val) {
if (isDefined(key) && angular.isArray(val)) {
return obj(key, '$nin', val);
}
},
// deprecated alias. Use $regex.
$like: regex,
$regex: regex,
$gt: numComparison('$gt'),
$gte: numComparison('$gte'),
$lt: numComparison('$lt'),
$lte: numComparison('$lte'),
};
});

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-eve-resource.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1bc0660

Please sign in to comment.