Skip to content

Commit

Permalink
Stable Version 1.4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Nov 19, 2014
1 parent 2487771 commit 3a02d3d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 52 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
##### 1.4.2 - 18 November 2014

###### Backwards compatible API changes
- #238 - Filter by substring ("in", "notIn', "|in" and "|notIn" operators now work on strings)

###### Backwards compatible bug fixes
- Fixed "allowSimpleWhere" default not being set

##### 1.4.1 - 11 November 2014

###### Backwards compatible bug fixes
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Unlike Backbone and Ember Models, angular-data does not require the use of gette

Supporting relations, computed properties, model lifecycle control and a slew of other features, angular-data is the tool for giving your data the respect it deserves.

__Latest Release:__ [1.4.1](https://github.com/jmdobry/angular-data/releases/tag/1.4.1)
__Latest Release:__ [1.4.2](https://github.com/jmdobry/angular-data/releases/tag/1.4.2)

Angular-data is finally 1.0.!

Angular-data 1.x will continue to see bug fixes, but all new development will be on [js-data](https://github.com/js-data/js-data) and [js-data-angular](https://github.com/jmdobry/angular-data/pull/198) (Angular-data 2.0).
Angular-data 1.x will continue to see bug fixes, but most new development will be on [js-data](https://github.com/js-data/js-data) and [js-data-angular](https://github.com/jmdobry/angular-data/pull/198) (Angular-data 2.0).

#### A note about Angular-data 2.0 (in development)
See [angular-data/pull/198](https://github.com/jmdobry/angular-data/pull/198).
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Jason Dobry",
"name": "angular-data",
"description": "Data store for Angular.js.",
"version": "1.4.1",
"version": "1.4.2",
"homepage": "http://angular-data.pseudobry.com/",
"repository": {
"type": "git",
Expand Down
61 changes: 39 additions & 22 deletions dist/angular-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @author Jason Dobry <jason.dobry@gmail.com>
* @file angular-data.js
* @version 1.4.1 - Homepage <http://angular-data.pseudobry.com/>
* @version 1.4.2 - Homepage <http://angular-data.pseudobry.com/>
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
*
Expand Down Expand Up @@ -4139,6 +4139,7 @@ Defaults.prototype.idAttribute = 'id';
Defaults.prototype.defaultAdapter = 'DSHttpAdapter';
Defaults.prototype.defaultFilter = function (collection, resourceName, params, options) {
var _this = this;
var DSUtils = _this.utils;
var filtered = collection;
var where = null;
var reserved = {
Expand All @@ -4152,14 +4153,14 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o

params = params || {};

if (_this.utils.isObject(params.where)) {
if (DSUtils.isObject(params.where)) {
where = params.where;
} else {
where = {};
}

if (options.allowSimpleWhere) {
_this.utils.forEach(params, function (value, key) {
DSUtils.forEach(params, function (value, key) {
if (!(key in reserved) && !(key in where)) {
where[key] = {
'==': value
Expand All @@ -4168,26 +4169,26 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
});
}

if (_this.utils.isEmpty(where)) {
if (DSUtils.isEmpty(where)) {
where = null;
}

if (where) {
filtered = _this.utils.filter(filtered, function (attrs) {
filtered = DSUtils.filter(filtered, function (attrs) {
var first = true;
var keep = true;
_this.utils.forEach(where, function (clause, field) {
if (_this.utils.isString(clause)) {
DSUtils.forEach(where, function (clause, field) {
if (DSUtils.isString(clause)) {
clause = {
'===': clause
};
} else if (_this.utils.isNumber(clause) || _this.utils.isBoolean(clause)) {
} else if (DSUtils.isNumber(clause) || DSUtils.isBoolean(clause)) {
clause = {
'==': clause
};
}
if (_this.utils.isObject(clause)) {
_this.utils.forEach(clause, function (val, op) {
if (DSUtils.isObject(clause)) {
DSUtils.forEach(clause, function (val, op) {
if (op === '==') {
keep = first ? (attrs[field] == val) : keep && (attrs[field] == val);
} else if (op === '===') {
Expand All @@ -4205,9 +4206,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
} else if (op === '<=') {
keep = first ? (attrs[field] <= val) : keep && (attrs[field] <= val);
} else if (op === 'in') {
keep = first ? _this.utils.contains(val, attrs[field]) : keep && _this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep && val.indexOf(attrs[field]) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep && DSUtils.contains(val, attrs[field]);
}
} else if (op === 'notIn') {
keep = first ? !_this.utils.contains(val, attrs[field]) : keep && !_this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep && val.indexOf(attrs[field]) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep && !DSUtils.contains(val, attrs[field]);
}
} else if (op === '|==') {
keep = first ? (attrs[field] == val) : keep || (attrs[field] == val);
} else if (op === '|===') {
Expand All @@ -4225,9 +4234,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
} else if (op === '|<=') {
keep = first ? (attrs[field] <= val) : keep || (attrs[field] <= val);
} else if (op === '|in') {
keep = first ? _this.utils.contains(val, attrs[field]) : keep || _this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep || val.indexOf(attrs[field]) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep || DSUtils.contains(val, attrs[field]);
}
} else if (op === '|notIn') {
keep = first ? !_this.utils.contains(val, attrs[field]) : keep || !_this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep || val.indexOf(attrs[field]) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep || !DSUtils.contains(val, attrs[field]);
}
}
first = false;
});
Expand All @@ -4239,29 +4256,29 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o

var orderBy = null;

if (_this.utils.isString(params.orderBy)) {
if (DSUtils.isString(params.orderBy)) {
orderBy = [
[params.orderBy, 'ASC']
];
} else if (_this.utils.isArray(params.orderBy)) {
} else if (DSUtils.isArray(params.orderBy)) {
orderBy = params.orderBy;
}

if (!orderBy && _this.utils.isString(params.sort)) {
if (!orderBy && DSUtils.isString(params.sort)) {
orderBy = [
[params.sort, 'ASC']
];
} else if (!orderBy && _this.utils.isArray(params.sort)) {
} else if (!orderBy && DSUtils.isArray(params.sort)) {
orderBy = params.sort;
}

// Apply 'orderBy'
if (orderBy) {
var index = 0;
angular.forEach(orderBy, function (def, i) {
if (_this.utils.isString(def)) {
if (DSUtils.isString(def)) {
orderBy[i] = [def, 'ASC'];
} else if (!_this.utils.isArray(def)) {
} else if (!DSUtils.isArray(def)) {
throw new _this.errors.IllegalArgumentError('DS.filter(resourceName[, params][, options]): ' + JSON.stringify(def) + ': Must be a string or an array!', {
params: {
'orderBy[i]': {
Expand All @@ -4271,8 +4288,8 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
}
});
}
filtered = _this.utils.sort(filtered, function (a, b) {
return compare(_this.utils, orderBy, index, a, b);
filtered = DSUtils.sort(filtered, function (a, b) {
return compare(DSUtils, orderBy, index, a, b);
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions dist/angular-data.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions guide/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<i class="icon-wrench icon-white"></i> API <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li class="nav-header">Angular-data - 1.3.0</li>
<li class="nav-header">Angular-data - 1.4.2</li>
<li>
<a href="/documentation/api/angular-data/angular-data">Overview</a>
</li>
Expand All @@ -107,7 +107,7 @@
<a href="/documentation/api/angular-data-mocks/DSHttpAdapter">DSHttpAdapter</a>
</li>
<li class="divider"></li>
<li class="nav-header">Angular-cache - 3.2.0</li>
<li class="nav-header">Angular-cache - 3.2.1</li>
<li>
<a href="/documentation/api/angular-cache/angular-cache">Overview</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-data",
"description": "Data store for Angular.js.",
"version": "1.4.1",
"version": "1.4.2",
"homepage": "http://angular-data.pseudobry.com",
"repository": {
"type": "git",
Expand Down
59 changes: 38 additions & 21 deletions src/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Defaults.prototype.idAttribute = 'id';
Defaults.prototype.defaultAdapter = 'DSHttpAdapter';
Defaults.prototype.defaultFilter = function (collection, resourceName, params, options) {
var _this = this;
var DSUtils = _this.utils;
var filtered = collection;
var where = null;
var reserved = {
Expand All @@ -60,14 +61,14 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o

params = params || {};

if (_this.utils.isObject(params.where)) {
if (DSUtils.isObject(params.where)) {
where = params.where;
} else {
where = {};
}

if (options.allowSimpleWhere) {
_this.utils.forEach(params, function (value, key) {
DSUtils.forEach(params, function (value, key) {
if (!(key in reserved) && !(key in where)) {
where[key] = {
'==': value
Expand All @@ -76,26 +77,26 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
});
}

if (_this.utils.isEmpty(where)) {
if (DSUtils.isEmpty(where)) {
where = null;
}

if (where) {
filtered = _this.utils.filter(filtered, function (attrs) {
filtered = DSUtils.filter(filtered, function (attrs) {
var first = true;
var keep = true;
_this.utils.forEach(where, function (clause, field) {
if (_this.utils.isString(clause)) {
DSUtils.forEach(where, function (clause, field) {
if (DSUtils.isString(clause)) {
clause = {
'===': clause
};
} else if (_this.utils.isNumber(clause) || _this.utils.isBoolean(clause)) {
} else if (DSUtils.isNumber(clause) || DSUtils.isBoolean(clause)) {
clause = {
'==': clause
};
}
if (_this.utils.isObject(clause)) {
_this.utils.forEach(clause, function (val, op) {
if (DSUtils.isObject(clause)) {
DSUtils.forEach(clause, function (val, op) {
if (op === '==') {
keep = first ? (attrs[field] == val) : keep && (attrs[field] == val);
} else if (op === '===') {
Expand All @@ -113,9 +114,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
} else if (op === '<=') {
keep = first ? (attrs[field] <= val) : keep && (attrs[field] <= val);
} else if (op === 'in') {
keep = first ? _this.utils.contains(val, attrs[field]) : keep && _this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep && val.indexOf(attrs[field]) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep && DSUtils.contains(val, attrs[field]);
}
} else if (op === 'notIn') {
keep = first ? !_this.utils.contains(val, attrs[field]) : keep && !_this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep && val.indexOf(attrs[field]) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep && !DSUtils.contains(val, attrs[field]);
}
} else if (op === '|==') {
keep = first ? (attrs[field] == val) : keep || (attrs[field] == val);
} else if (op === '|===') {
Expand All @@ -133,9 +142,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
} else if (op === '|<=') {
keep = first ? (attrs[field] <= val) : keep || (attrs[field] <= val);
} else if (op === '|in') {
keep = first ? _this.utils.contains(val, attrs[field]) : keep || _this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep || val.indexOf(attrs[field]) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep || DSUtils.contains(val, attrs[field]);
}
} else if (op === '|notIn') {
keep = first ? !_this.utils.contains(val, attrs[field]) : keep || !_this.utils.contains(val, attrs[field]);
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep || val.indexOf(attrs[field]) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep || !DSUtils.contains(val, attrs[field]);
}
}
first = false;
});
Expand All @@ -147,29 +164,29 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o

var orderBy = null;

if (_this.utils.isString(params.orderBy)) {
if (DSUtils.isString(params.orderBy)) {
orderBy = [
[params.orderBy, 'ASC']
];
} else if (_this.utils.isArray(params.orderBy)) {
} else if (DSUtils.isArray(params.orderBy)) {
orderBy = params.orderBy;
}

if (!orderBy && _this.utils.isString(params.sort)) {
if (!orderBy && DSUtils.isString(params.sort)) {
orderBy = [
[params.sort, 'ASC']
];
} else if (!orderBy && _this.utils.isArray(params.sort)) {
} else if (!orderBy && DSUtils.isArray(params.sort)) {
orderBy = params.sort;
}

// Apply 'orderBy'
if (orderBy) {
var index = 0;
angular.forEach(orderBy, function (def, i) {
if (_this.utils.isString(def)) {
if (DSUtils.isString(def)) {
orderBy[i] = [def, 'ASC'];
} else if (!_this.utils.isArray(def)) {
} else if (!DSUtils.isArray(def)) {
throw new _this.errors.IllegalArgumentError('DS.filter(resourceName[, params][, options]): ' + JSON.stringify(def) + ': Must be a string or an array!', {
params: {
'orderBy[i]': {
Expand All @@ -179,8 +196,8 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
}
});
}
filtered = _this.utils.sort(filtered, function (a, b) {
return compare(_this.utils, orderBy, index, a, b);
filtered = DSUtils.sort(filtered, function (a, b) {
return compare(DSUtils, orderBy, index, a, b);
});
});
}
Expand Down
16 changes: 16 additions & 0 deletions test/integration/datastore/sync_methods/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ describe('DS.filter(resourceName[, params][, options])', function () {

assert.deepEqual(angular.toJson(DS.filter('post', params)), angular.toJson([p1, p4, p5]), 'should accept normal "in" clause');

params.where = {
author: {
'in': 'John'
}
};

assert.deepEqual(JSON.stringify(DS.filter('post', params)), JSON.stringify([p1]), 'should accept normal "in" clause with a string');

params.where = {
author: {
'notIn': 'John'
}
};

assert.deepEqual(JSON.stringify(DS.filter('post', params)), JSON.stringify([p2, p3, p4, p5]), 'should accept normal "notIn" clause with a string');

params.where = {
age: {
'|in': [31]
Expand Down

1 comment on commit 3a02d3d

@jmdobry
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #238

Please sign in to comment.