Skip to content

Commit

Permalink
Closes #249
Browse files Browse the repository at this point in the history
Stable Version 1.5.0.
  • Loading branch information
jmdobry committed Dec 1, 2014
1 parent 0c9d4e4 commit 7ecf97d
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 68 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
##### 1.4.3 - 30 November 2014
##### 1.5.0 - 01 December 2014

###### Backwards compatible API changes
- Added DSHttpAdapter.getPath and DSLocalStorageAdapter.getPath

###### Backwards compatible bug fixes
- #253 - Injecting an item with relationships a second time breaks relationships
- Removed console.logs left over from a previous commit

##### 1.4.3 - 30 November 2014

###### Backwards compatible bug fixes
- Fixed "allowSimpleWhere" default not being set
- #253 - Injecting an item with relationships a second time breaks relationships

##### 1.4.2 - 18 November 2014

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.3](https://github.com/jmdobry/angular-data/releases/tag/1.4.3)
__Latest Release:__ [1.5.0](https://github.com/jmdobry/angular-data/releases/tag/1.5.0)

Angular-data is finally 1.0.!

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.3",
"version": "1.5.0",
"homepage": "http://angular-data.pseudobry.com/",
"repository": {
"type": "git",
Expand Down
120 changes: 91 additions & 29 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.3 - Homepage <http://angular-data.pseudobry.com/>
* @version 1.5.0 - 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 @@ -1891,6 +1891,36 @@ function DSHttpAdapterProvider() {

this.$get = ['$http', '$log', 'DSUtils', function ($http, $log, DSUtils) {

/**
* @doc method
* @id DSHttpAdapter.methods:getPath
* @name getPath
* @description
* Return the path that would be used by this adapter for a given operation.
*
* ## Signature:
* ```js
* DSHttpAdapter.getPath(method, resourceConfig, id|attrs|params, options))
* ```
*
* @param {string} method The name of the method .
* @param {object} resourceConfig The object returned by DS.defineResource.
* @param {string|object} id|attrs|params The id, attrs, or params that you would pass into the method.
* @param {object} options Configuration options.
* @returns {string} The path.
*/
function getPath(method, resourceConfig, id, options) {
options = options || {};
var args = [
options.baseUrl || resourceConfig.baseUrl,
resourceConfig.getEndpoint((DSUtils.isString(id) || DSUtils.isNumber(id) || method === 'create') ? id : null, options)
];
if (method === 'find' || method === 'update' || method === 'destroy') {
args.push(id);
}
return DSUtils.makePath.apply(DSUtils, args);
}

/**
* @doc interface
* @id DSHttpAdapter
Expand All @@ -1909,6 +1939,8 @@ function DSHttpAdapterProvider() {
*/
defaults: defaults,

getPath: getPath,

/**
* @doc method
* @id DSHttpAdapter.methods:HTTP
Expand Down Expand Up @@ -2072,7 +2104,7 @@ function DSHttpAdapterProvider() {
find: function (resourceConfig, id, options) {
options = options || {};
return this.GET(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(id, options), id),
getPath('find', resourceConfig, id, options),
options
);
},
Expand Down Expand Up @@ -2109,7 +2141,7 @@ function DSHttpAdapterProvider() {
DSUtils.deepMixIn(options.params, params);
}
return this.GET(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(null, options)),
getPath('findAll', resourceConfig, params, options),
options
);
},
Expand Down Expand Up @@ -2141,7 +2173,7 @@ function DSHttpAdapterProvider() {
create: function (resourceConfig, attrs, options) {
options = options || {};
return this.POST(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(attrs, options)),
getPath('create', resourceConfig, attrs, options),
attrs,
options
);
Expand Down Expand Up @@ -2175,7 +2207,7 @@ function DSHttpAdapterProvider() {
update: function (resourceConfig, id, attrs, options) {
options = options || {};
return this.PUT(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(id, options), id),
getPath('update', resourceConfig, id, options),
attrs,
options
);
Expand Down Expand Up @@ -2214,7 +2246,7 @@ function DSHttpAdapterProvider() {
DSUtils.deepMixIn(options.params, params);
}
return this.PUT(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(null, options)),
getPath('updateAll', resourceConfig, attrs, options),
attrs,
options
);
Expand Down Expand Up @@ -2247,7 +2279,7 @@ function DSHttpAdapterProvider() {
destroy: function (resourceConfig, id, options) {
options = options || {};
return this.DEL(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(id, options), id),
getPath('destroy', resourceConfig, id, options),
options
);
},
Expand Down Expand Up @@ -2284,7 +2316,7 @@ function DSHttpAdapterProvider() {
DSUtils.deepMixIn(options.params, params);
}
return this.DEL(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(null, options)),
getPath('destroyAll', resourceConfig, params, options),
options
);
}
Expand All @@ -2304,6 +2336,36 @@ function DSLocalStorageAdapterProvider() {

this.$get = ['$q', 'DSUtils', 'DSErrors', function ($q, DSUtils) {

/**
* @doc method
* @id DSLocalStorageAdapter.methods:getPath
* @name getPath
* @description
* Return the path that would be used by this adapter for a given operation.
*
* ## Signature:
* ```js
* DSLocalStorageAdapter.getPath(method, resourceConfig, id|attrs|params, options))
* ```
*
* @param {string} method The name of the method .
* @param {object} resourceConfig The object returned by DS.defineResource.
* @param {string|object} id|attrs|params The id, attrs, or params that you would pass into the method.
* @param {object} options Configuration options.
* @returns {string} The path.
*/
function getPath(method, resourceConfig, id, options) {
options = options || {};
var args = [
options.baseUrl || resourceConfig.baseUrl,
resourceConfig.getEndpoint((DSUtils.isString(id) || DSUtils.isNumber(id) || method === 'create') ? id : null, options)
];
if (method === 'find' || method === 'update' || method === 'destroy') {
args.push(id);
}
return DSUtils.makePath.apply(DSUtils, args);
}

/**
* @doc interface
* @id DSLocalStorageAdapter
Expand Down Expand Up @@ -2454,7 +2516,7 @@ function DSLocalStorageAdapterProvider() {
*/
find: function find(resourceConfig, id, options) {
options = options || {};
return this.GET(DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.endpoint, id)).then(function (item) {
return this.GET(getPath('find', resourceConfig, id, options)).then(function (item) {
if (!item) {
return $q.reject(new Error('Not Found!'));
} else {
Expand Down Expand Up @@ -2493,7 +2555,7 @@ function DSLocalStorageAdapterProvider() {
var items = [];
var ids = DSUtils.keys(_this.getIds(resourceConfig.name, options));
DSUtils.forEach(ids, function (id) {
var itemJson = localStorage.getItem(DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(id, options), id));
var itemJson = localStorage.getItem(getPath('find', resourceConfig, id, options));
if (itemJson) {
items.push(DSUtils.fromJson(itemJson));
}
Expand Down Expand Up @@ -2536,15 +2598,19 @@ function DSLocalStorageAdapterProvider() {
*/
create: function (resourceConfig, attrs, options) {
var _this = this;
attrs[resourceConfig.idAttribute] = attrs[resourceConfig.idAttribute] || DSUtils.guid();
var id = attrs[resourceConfig.idAttribute];
options = options || {};
return this.PUT(
DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(attrs, options), attrs[resourceConfig.idAttribute]),
attrs
).then(function (item) {
_this.ensureId(item[resourceConfig.idAttribute], resourceConfig.name, options);
return item;
});
return _this.GET(getPath('find', resourceConfig, id, options)).then(function (item) {
if (item) {
DSUtils.deepMixIn(item, attrs);
} else {
attrs[resourceConfig.idAttribute] = id = id || DSUtils.guid();
}
return _this.PUT(getPath('update', resourceConfig, id, options), item || attrs);
}).then(function (item) {
_this.ensureId(item[resourceConfig.idAttribute], resourceConfig.name, options);
return item;
});
},

/**
Expand Down Expand Up @@ -2582,9 +2648,13 @@ function DSLocalStorageAdapterProvider() {
update: function (resourceConfig, id, attrs, options) {
options = options || {};
var _this = this;
return _this.find(resourceConfig, id, options).then(function (item) {
return _this.GET(getPath('find', resourceConfig, id, options)).then(function (item) {
item = item || {};
DSUtils.deepMixIn(item, attrs);
return _this.PUT(DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(id, options), id), item);
return _this.PUT(getPath('update', resourceConfig, id, options), item);
}).then(function (item) {
_this.ensureId(item[resourceConfig.idAttribute], resourceConfig.name, options);
return item;
});
},

Expand Down Expand Up @@ -2653,7 +2723,7 @@ function DSLocalStorageAdapterProvider() {
*/
destroy: function (resourceConfig, id, options) {
options = options || {};
return this.DEL(DSUtils.makePath(options.baseUrl || resourceConfig.baseUrl, resourceConfig.getEndpoint(id, options), id));
return this.DEL(getPath('destroy', resourceConfig, id, options));
},

/**
Expand Down Expand Up @@ -6814,7 +6884,6 @@ function _link(definition, injected, options) {
* the items that were injected into the data store.
*/
function inject(resourceName, attrs, options) {
console.log('inject', resourceName, attrs);
var DS = this;
var IA = DS.errors.IA;
var definition = DS.definitions[resourceName];
Expand Down Expand Up @@ -6847,9 +6916,7 @@ function inject(resourceName, attrs, options) {
resource.collectionModified = DS.utils.updateTimestamp(resource.collectionModified);
}

console.log(options);
if (options.linkInverse && typeof options.linkInverse === 'boolean') {
console.log('linkInverse', typeof options.linkInverse, options.linkInverse);
if (DS.utils.isArray(injected)) {
if (injected.length) {
DS.linkInverse(definition.name, injected[0][definition.idAttribute]);
Expand All @@ -6859,8 +6926,6 @@ function inject(resourceName, attrs, options) {
}
}

console.log(injected);

if (DS.utils.isArray(injected)) {
DS.utils.forEach(injected, function (injectedI) {
_link.call(DS, definition, injectedI, options);
Expand Down Expand Up @@ -7072,7 +7137,6 @@ function _link(definition, linked, relations) {
* @returns {object|array} A reference to the item with its linked relations.
*/
function link(resourceName, id, relations) {
console.log('link', resourceName, id);
var DS = this;
var IA = DS.errors.IA;
var definition = DS.definitions[resourceName];
Expand All @@ -7099,8 +7163,6 @@ function link(resourceName, id, relations) {
}
}

console.log('linked', linked);

return linked;
}

Expand Down
6 changes: 3 additions & 3 deletions dist/angular-data.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.4.3</li>
<li class="nav-header">Angular-data - 1.5.0</li>
<li>
<a href="/documentation/api/angular-data/angular-data">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.3",
"version": "1.5.0",
"homepage": "http://angular-data.pseudobry.com",
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 7ecf97d

Please sign in to comment.