-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
141 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "angular-restmod", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"authors": [ | ||
"Ignacio Baixas <[email protected]>" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
@@ -3594,38 +3594,30 @@ RMModule.factory('RMSerializer', ['$injector', 'inflector', '$filter', 'RMUtils' | |
}]); | ||
RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', function(restmod, inflector, packerCache) { | ||
|
||
// process metadata | ||
function processMeta(_meta, _raw, _skip) { | ||
var metaDef = _meta; | ||
if(typeof metaDef === 'string') { | ||
if(metaDef === '.') { | ||
var meta = {}; | ||
for(var key in _raw) { | ||
if(_raw.hasOwnProperty(key) && _skip.indexOf(key) === -1) { // skip links and object root if extracting from root. | ||
meta[key] = _raw[key]; | ||
} | ||
} | ||
return meta; | ||
} else { | ||
return _raw[metaDef]; | ||
function include(_source, _list, _do) { | ||
for(var i = 0, l = _list.length; i < l; i++) { | ||
_do(_list[i], _source[_list[i]]); | ||
} | ||
} | ||
|
||
function exclude(_source, _skip, _do) { | ||
for(var key in _source) { | ||
if(_source.hasOwnProperty(key) && _skip.indexOf(key) === -1) { | ||
_do(key, _source[key]); | ||
} | ||
} else if(typeof metaDef === 'function') { | ||
return metaDef(_raw); | ||
} | ||
} | ||
|
||
// process links and stores them in the packer cache | ||
function processLinks(_links, _raw, _skip) { | ||
var source = _links === '.' ? _raw : _raw[_links]; | ||
if(!source) return; | ||
|
||
// feed packer cache | ||
for(var key in source) { | ||
if(source.hasOwnProperty(key) && _skip.indexOf(key) === -1) { | ||
var cache = source[key]; | ||
// TODO: check that cache is an array. | ||
packerCache.feed(key, cache); | ||
} | ||
function processFeature(_raw, _name, _feature, _other, _do) { | ||
if(_feature === '.' || _feature === true) { | ||
var skip = [_name]; | ||
if(_other) skip.push.apply(skip, angular.isArray(_other) ? _other : [_other]); | ||
exclude(_raw, skip, _do); | ||
} else if(typeof _feature === 'string') { | ||
exclude(_raw[_feature], [], _do); | ||
} else { // links is an array | ||
include(_raw, _feature, _do); | ||
} | ||
} | ||
|
||
|
@@ -3658,7 +3650,8 @@ RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', func | |
* | ||
* By default the mixin will look for links to other resources in the 'linked' root property, you | ||
* can change this by setting the jsonLinks variable. To use the root element as link source | ||
* use `jsonLinks: true`. To skip links processing, set it to false. | ||
* use `jsonLinks: '.'`. You can also explicitly select which properties to consider links using an | ||
* array of property names. To skip links processing altogether, set it to false. | ||
* | ||
* Links are expected to use the pluralized version of the name for the referenced model. For example, | ||
* given the following response: | ||
|
@@ -3680,9 +3673,9 @@ RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', func | |
* By default metadata is only captured if it comes in the 'meta' root property. Metadata is then | ||
* stored in the $meta property of the resource being unwrapped. | ||
* | ||
* To change the metadata source property set the jsonMeta property to the desired name, set | ||
* it to '.' to capture the entire raw response or set it to false to skip metadata. It can also be set | ||
* to a function, for custom processsing. | ||
* Just like links, to change the metadata source property set the jsonMeta property to the desired name, set | ||
* it to '.' to capture the entire raw response or set it to false to skip metadata and set it to an array of properties | ||
* to be extract selected properties. | ||
* | ||
* @property {mixed} single The expected single resource wrapper property name | ||
* @property {object} plural The expected collection wrapper property name | ||
|
@@ -3703,8 +3696,20 @@ RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', func | |
name = this.getProperty('jsonRootSingle') || this.getProperty('jsonRoot') || this.getProperty('name'); | ||
} | ||
|
||
if(meta) _resource.$metadata = processMeta(meta, _raw, [name, links]); | ||
if(links) processLinks(links, _raw, [name]); | ||
if(meta) { | ||
_resource.$metadata = {}; | ||
processFeature(_raw, name, meta, links, function(_key, _value) { | ||
_resource.$metadata[_key] = _value; | ||
}); | ||
} | ||
|
||
if(links) { | ||
processFeature(_raw, name, links, meta, function(_key, _value) { | ||
// TODO: check that cache is an array. | ||
packerCache.feed(_key, _value); | ||
}); | ||
} | ||
|
||
return _raw[name]; | ||
}); | ||
}); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
@@ -3356,38 +3356,30 @@ RMModule.factory('RMSerializer', ['$injector', 'inflector', '$filter', 'RMUtils' | |
}]); | ||
RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', function(restmod, inflector, packerCache) { | ||
|
||
// process metadata | ||
function processMeta(_meta, _raw, _skip) { | ||
var metaDef = _meta; | ||
if(typeof metaDef === 'string') { | ||
if(metaDef === '.') { | ||
var meta = {}; | ||
for(var key in _raw) { | ||
if(_raw.hasOwnProperty(key) && _skip.indexOf(key) === -1) { // skip links and object root if extracting from root. | ||
meta[key] = _raw[key]; | ||
} | ||
} | ||
return meta; | ||
} else { | ||
return _raw[metaDef]; | ||
function include(_source, _list, _do) { | ||
for(var i = 0, l = _list.length; i < l; i++) { | ||
_do(_list[i], _source[_list[i]]); | ||
} | ||
} | ||
|
||
function exclude(_source, _skip, _do) { | ||
for(var key in _source) { | ||
if(_source.hasOwnProperty(key) && _skip.indexOf(key) === -1) { | ||
_do(key, _source[key]); | ||
} | ||
} else if(typeof metaDef === 'function') { | ||
return metaDef(_raw); | ||
} | ||
} | ||
|
||
// process links and stores them in the packer cache | ||
function processLinks(_links, _raw, _skip) { | ||
var source = _links === '.' ? _raw : _raw[_links]; | ||
if(!source) return; | ||
|
||
// feed packer cache | ||
for(var key in source) { | ||
if(source.hasOwnProperty(key) && _skip.indexOf(key) === -1) { | ||
var cache = source[key]; | ||
// TODO: check that cache is an array. | ||
packerCache.feed(key, cache); | ||
} | ||
function processFeature(_raw, _name, _feature, _other, _do) { | ||
if(_feature === '.' || _feature === true) { | ||
var skip = [_name]; | ||
if(_other) skip.push.apply(skip, angular.isArray(_other) ? _other : [_other]); | ||
exclude(_raw, skip, _do); | ||
} else if(typeof _feature === 'string') { | ||
exclude(_raw[_feature], [], _do); | ||
} else { // links is an array | ||
include(_raw, _feature, _do); | ||
} | ||
} | ||
|
||
|
@@ -3420,7 +3412,8 @@ RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', func | |
* | ||
* By default the mixin will look for links to other resources in the 'linked' root property, you | ||
* can change this by setting the jsonLinks variable. To use the root element as link source | ||
* use `jsonLinks: true`. To skip links processing, set it to false. | ||
* use `jsonLinks: '.'`. You can also explicitly select which properties to consider links using an | ||
* array of property names. To skip links processing altogether, set it to false. | ||
* | ||
* Links are expected to use the pluralized version of the name for the referenced model. For example, | ||
* given the following response: | ||
|
@@ -3442,9 +3435,9 @@ RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', func | |
* By default metadata is only captured if it comes in the 'meta' root property. Metadata is then | ||
* stored in the $meta property of the resource being unwrapped. | ||
* | ||
* To change the metadata source property set the jsonMeta property to the desired name, set | ||
* it to '.' to capture the entire raw response or set it to false to skip metadata. It can also be set | ||
* to a function, for custom processsing. | ||
* Just like links, to change the metadata source property set the jsonMeta property to the desired name, set | ||
* it to '.' to capture the entire raw response or set it to false to skip metadata and set it to an array of properties | ||
* to be extract selected properties. | ||
* | ||
* @property {mixed} single The expected single resource wrapper property name | ||
* @property {object} plural The expected collection wrapper property name | ||
|
@@ -3465,8 +3458,20 @@ RMModule.factory('DefaultPacker', ['restmod', 'inflector', 'RMPackerCache', func | |
name = this.getProperty('jsonRootSingle') || this.getProperty('jsonRoot') || this.getProperty('name'); | ||
} | ||
|
||
if(meta) _resource.$metadata = processMeta(meta, _raw, [name, links]); | ||
if(links) processLinks(links, _raw, [name]); | ||
if(meta) { | ||
_resource.$metadata = {}; | ||
processFeature(_raw, name, meta, links, function(_key, _value) { | ||
_resource.$metadata[_key] = _value; | ||
}); | ||
} | ||
|
||
if(links) { | ||
processFeature(_raw, name, links, meta, function(_key, _value) { | ||
// TODO: check that cache is an array. | ||
packerCache.feed(_key, _value); | ||
}); | ||
} | ||
|
||
return _raw[name]; | ||
}); | ||
}); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
@@ -9,7 +9,7 @@ | |
(function(angular, undefined) { | ||
'use strict'; | ||
/** | ||
* @mixin Populate | ||
* @mixin FindMany | ||
* | ||
* @description | ||
* | ||
|
@@ -23,8 +23,8 @@ angular.module('restmod').factory('restmod.FindMany', ['restmod', 'RMPackerCache | |
return restmod.mixin(function() { | ||
|
||
/** | ||
* @method $populate | ||
* @memberOf Populate | ||
* @method $findManyUrl | ||
* @memberOf FindMany | ||
* | ||
* @description Provides the url for a findMany/populate operation. | ||
*/ | ||
|
@@ -33,7 +33,7 @@ angular.module('restmod').factory('restmod.FindMany', ['restmod', 'RMPackerCache | |
}) | ||
/** | ||
* @method $populate | ||
* @memberOf Populate | ||
* @memberOf FindMany | ||
* | ||
* @description Resolves a series of records using a single api call. | ||
* | ||
|
@@ -63,12 +63,12 @@ angular.module('restmod').factory('restmod.FindMany', ['restmod', 'RMPackerCache | |
* @param {array} _records Records to resolve. | ||
* @return {Resource} Resource holding the populate promise. | ||
*/ | ||
.define('Scope.$populate', function(_records) { | ||
.define('Scope.$populate', function(_records, _params) { | ||
|
||
// Extract record pks for non resolved records and build a record map | ||
var pks = [], | ||
recordMap = {}, | ||
params = {}, | ||
params = _params || {}, | ||
model = this.$type, | ||
dummy = model.dummy(true), | ||
record, request; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* API Bound Models for AngularJS | ||
* @version v1.1.1 - 2014-09-23 | ||
* @version v1.1.2 - 2014-09-24 | ||
* @link https://github.com/angular-platanus/restmod | ||
* @author Ignacio Baixas <[email protected]> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
|
Oops, something went wrong.