From e41661fed6784ded47bf305f2e9e0162249af76e Mon Sep 17 00:00:00 2001 From: Martin Gontovnikas Date: Fri, 13 Dec 2013 14:16:40 -0300 Subject: [PATCH] 1.2.1 --- bower.json | 2 +- dist/restangular.js | 54 +++++++++++++++++++++++----------------- dist/restangular.min.js | 4 +-- dist/restangular.zip | Bin 65578 -> 66035 bytes package.json | 2 +- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/bower.json b/bower.json index d219de87..ac845b62 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "restangular", - "version": "1.2.0", + "version": "1.2.1", "main": "./dist/restangular.min.js", "description": "Restful Resources service for AngularJS apps", "repository": { diff --git a/dist/restangular.js b/dist/restangular.js index 958f5401..c273dcbd 100644 --- a/dist/restangular.js +++ b/dist/restangular.js @@ -1,6 +1,6 @@ /** * Restful Resources service for AngularJS apps - * @version v1.2.0 - 2013-12-09 + * @version v1.2.1 - 2013-12-13 * @link https://github.com/mgonto/restangular * @author Martin Gontovnikas * @license MIT License, http://www.opensource.org/licenses/MIT @@ -29,12 +29,12 @@ module.provider('Restangular', function() { return _.isUndefined(config.absoluteUrl) || _.isNull(config.absoluteUrl) ? string && absolutePattern.test(string) : config.absoluteUrl; - } + }; config.absoluteUrl = _.isUndefined(config.absoluteUrl) ? false : true; object.setSelfLinkAbsoluteUrl = function(value) { config.absoluteUrl = value; - } + }; /** * This is the BaseURL to be used with Restangular */ @@ -71,7 +71,7 @@ module.provider('Restangular', function() { config.encodeIds = _.isUndefined(config.encodeIds) ? true : config.encodeIds; object.setEncodeIds = function(encode) { config.encodeIds = encode; - } + }; config.defaultRequestParams = config.defaultRequestParams || { get: {}, @@ -98,7 +98,7 @@ module.provider('Restangular', function() { config.defaultRequestParams[method] = params; }); return this; - } + }; object.requestParams = config.defaultRequestParams; @@ -204,7 +204,7 @@ module.provider('Restangular', function() { config.isRestangularized = function(obj) { return !!obj[config.restangularFields.one] || !!obj[config.restangularFields.all]; - } + }; config.setFieldToElem = function(field, elem, value) { var properties = field.split('.'); @@ -238,23 +238,23 @@ module.provider('Restangular', function() { }; config.isValidId = function(elemId) { - return "" !== elemId && !_.isUndefined(elemId) && !_.isNull(elemId) - } + return "" !== elemId && !_.isUndefined(elemId) && !_.isNull(elemId); + }; config.setUrlToElem = function(elem, url) { config.setFieldToElem(config.restangularFields.selfLink, elem, url); return this; - } + }; config.getUrlFromElem = function(elem) { return config.getFieldFromElem(config.restangularFields.selfLink, elem); - } + }; config.useCannonicalId = _.isUndefined(config.useCannonicalId) ? false : config.useCannonicalId; object.setUseCannonicalId = function(value) { config.useCannonicalId = value; return this; - } + }; config.getCannonicalIdFromElem = function(elem) { var cannonicalId = elem[config.restangularFields.cannonicalId]; @@ -308,7 +308,7 @@ module.provider('Restangular', function() { params: params, element: interceptor(elem, operation, path, url), httpConfig: httpConfig - } + }; }; return this; }; @@ -327,7 +327,7 @@ module.provider('Restangular', function() { config.onBeforeElemRestangularized = config.onBeforeElemRestangularized || function(elem) { return elem; - } + }; object.setOnBeforeElemRestangularized = function(post) { config.onBeforeElemRestangularized = post; return this; @@ -362,11 +362,11 @@ module.provider('Restangular', function() { if (_.isArray(values)) { config.shouldSaveParent = function(route) { return !_.contains(values, route); - } + }; } else if (_.isBoolean(values)) { config.shouldSaveParent = function() { return !values; - } + }; } return this; }; @@ -484,7 +484,7 @@ module.provider('Restangular', function() { return $http(_.extend(value, { url: url })); - } + }; } else { @@ -493,7 +493,7 @@ module.provider('Restangular', function() { url: url, data: data })); - } + }; } }); @@ -698,7 +698,7 @@ module.provider('Restangular', function() { config.urlCreatorFactory.path = Path; - } + }; var globalConfiguration = {}; @@ -867,7 +867,7 @@ module.provider('Restangular', function() { } else { callFunction = function(operation, elem, path, params, headers) { return _.bind(customFunction, this)(operation, path, params, headers, elem); - } + }; } elem[name] = _.bind(callFunction, elem, callOperation); }); @@ -888,13 +888,13 @@ module.provider('Restangular', function() { var localElem = restangularizeBase(parent, elem, route, reqParams); if (config.useCannonicalId) { - localElem[config.restangularFields.cannonicalId] = config.getIdFromElem(localElem) + localElem[config.restangularFields.cannonicalId] = config.getIdFromElem(localElem); } if (collection) { localElem[config.restangularFields.getParentList] = function() { return collection; - } + }; } localElem[config.restangularFields.restangularCollection] = false; @@ -931,6 +931,14 @@ module.provider('Restangular', function() { return config.transformElem(localElem, true, route, service); } + function restangularizeCollectionAndElements(parent, element, route) { + var collection = restangularizeCollection(parent, element, route); + _.each(collection, function(elem) { + restangularizeElem(parent, elem, route); + }); + return collection; + } + function getById(id, reqParams, headers){ return this.customGET(id.toString(), reqParams, headers); } @@ -1137,7 +1145,7 @@ module.provider('Restangular', function() { } else { this[name] = function(elem, params, headers) { return createdFunction(params, headers, elem); - } + }; } } @@ -1170,7 +1178,7 @@ module.provider('Restangular', function() { service.restangularizeElement = _.bind(restangularizeElem, service); - service.restangularizeCollection = _.bind(restangularizeCollection, service); + service.restangularizeCollection = _.bind(restangularizeCollectionAndElements, service); return service; } diff --git a/dist/restangular.min.js b/dist/restangular.min.js index 8fa00772..79f817a7 100644 --- a/dist/restangular.min.js +++ b/dist/restangular.min.js @@ -1,8 +1,8 @@ /** * Restful Resources service for AngularJS apps - * @version v1.2.0 - 2013-12-09 + * @version v1.2.1 - 2013-12-13 * @link https://github.com/mgonto/restangular * @author Martin Gontovnikas * @license MIT License, http://www.opensource.org/licenses/MIT */ -!function(){var a=angular.module("restangular",[]);a.provider("Restangular",function(){var a={};a.init=function(a,b){function c(a,b,c,d){var e={};return _.each(_.keys(d),function(f){var g=d[f];g.params=_.extend({},g.params,a.defaultRequestParams[g.method.toLowerCase()]),_.isEmpty(g.params)&&delete g.params,e[f]=a.isSafe(g.method)?function(){return b(_.extend(g,{url:c}))}:function(a){return b(_.extend(g,{url:c,data:a}))}}),e}a.configuration=b;var d=["get","head","options","trace","getlist"];b.isSafe=function(a){return _.contains(d,a.toLowerCase())};var e=/^https?:\/\//i;b.isAbsoluteUrl=function(a){return _.isUndefined(b.absoluteUrl)||_.isNull(b.absoluteUrl)?a&&e.test(a):b.absoluteUrl},b.absoluteUrl=_.isUndefined(b.absoluteUrl)?!1:!0,a.setSelfLinkAbsoluteUrl=function(a){b.absoluteUrl=a},b.baseUrl=_.isUndefined(b.baseUrl)?"":b.baseUrl,a.setBaseUrl=function(a){return b.baseUrl=/\/$/.test(a)?a.substring(0,a.length-1):a,this},b.extraFields=b.extraFields||[],a.setExtraFields=function(a){return b.extraFields=a,this},b.defaultHttpFields=b.defaultHttpFields||{},a.setDefaultHttpFields=function(a){return b.defaultHttpFields=a,this},b.withHttpValues=function(a,c){return _.defaults(c,a,b.defaultHttpFields)},b.encodeIds=_.isUndefined(b.encodeIds)?!0:b.encodeIds,a.setEncodeIds=function(a){b.encodeIds=a},b.defaultRequestParams=b.defaultRequestParams||{get:{},post:{},put:{},remove:{},common:{}},a.setDefaultRequestParams=function(a,c){var d=[],e=c||a;return _.isUndefined(c)?d.push("common"):_.isArray(a)?d=a:d.push(a),_.each(d,function(a){b.defaultRequestParams[a]=e}),this},a.requestParams=b.defaultRequestParams,b.defaultHeaders=b.defaultHeaders||{},a.setDefaultHeaders=function(c){return b.defaultHeaders=c,a.defaultHeaders=b.defaultHeaders,this},a.defaultHeaders=b.defaultHeaders,b.methodOverriders=b.methodOverriders||[],a.setMethodOverriders=function(a){var c=_.extend([],a);return b.isOverridenMethod("delete",c)&&c.push("remove"),b.methodOverriders=c,this},b.isOverridenMethod=function(a,c){var d=c||b.methodOverriders;return!_.isUndefined(_.find(d,function(b){return b.toLowerCase()===a.toLowerCase()}))},b.urlCreator=b.urlCreator||"path",a.setUrlCreator=function(a){if(!_.has(b.urlCreatorFactory,a))throw new Error("URL Path selected isn't valid");return b.urlCreator=a,this},b.restangularFields=b.restangularFields||{id:"id",route:"route",parentResource:"parentResource",restangularCollection:"restangularCollection",cannonicalId:"__cannonicalId",etag:"restangularEtag",selfLink:"href",get:"get",getList:"getList",put:"put",post:"post",remove:"remove",head:"head",trace:"trace",options:"options",patch:"patch",getRestangularUrl:"getRestangularUrl",getRequestedUrl:"getRequestedUrl",putElement:"putElement",addRestangularMethod:"addRestangularMethod",getParentList:"getParentList",clone:"clone",ids:"ids",httpConfig:"_$httpConfig",reqParams:"reqParams",one:"one",all:"all",several:"several",oneUrl:"oneUrl",allUrl:"allUrl",customPUT:"customPUT",customPOST:"customPOST",customDELETE:"customDELETE",customGET:"customGET",doPUT:"doPUT",doPOST:"doPOST",doDELETE:"doDELETE",doGET:"doGET"},a.setRestangularFields=function(a){return b.restangularFields=_.extend(b.restangularFields,a),this},b.isRestangularized=function(a){return!!a[b.restangularFields.one]||!!a[b.restangularFields.all]},b.setFieldToElem=function(a,b,c){var d=a.split("."),e=b;return _.each(_.initial(d),function(a){e[a]={},e=e[a]}),e[_.last(d)]=c,this},b.getFieldFromElem=function(a,b){var c=a.split("."),d=angular.copy(b);return _.each(c,function(a){d&&(d=d[a])}),d},b.setIdToElem=function(a,c){return b.setFieldToElem(b.restangularFields.id,a,c),this},b.getIdFromElem=function(a){return b.getFieldFromElem(b.restangularFields.id,a)},b.isValidId=function(a){return""!==a&&!_.isUndefined(a)&&!_.isNull(a)},b.setUrlToElem=function(a,c){return b.setFieldToElem(b.restangularFields.selfLink,a,c),this},b.getUrlFromElem=function(a){return b.getFieldFromElem(b.restangularFields.selfLink,a)},b.useCannonicalId=_.isUndefined(b.useCannonicalId)?!1:b.useCannonicalId,a.setUseCannonicalId=function(a){return b.useCannonicalId=a,this},b.getCannonicalIdFromElem=function(a){var c=a[b.restangularFields.cannonicalId],d=b.isValidId(c)?c:b.getIdFromElem(a);return d},b.responseExtractor=b.responseExtractor||function(a){return a},a.setResponseExtractor=function(a){return b.responseExtractor=a,this},a.setResponseInterceptor=a.setResponseExtractor,b.fullRequestInterceptor=b.fullRequestInterceptor||function(a,b,c,d,e,f,g){return{element:a,headers:e,params:f,httpConfig:g}},a.setRequestInterceptor=function(a){return b.fullRequestInterceptor=function(b,c,d,e,f,g,h){return{headers:f,params:g,element:a(b,c,d,e),httpConfig:h}},this},a.setFullRequestInterceptor=function(a){return b.fullRequestInterceptor=a,this},b.errorInterceptor=b.errorInterceptor||function(){},a.setErrorInterceptor=function(a){return b.errorInterceptor=a,this},b.onBeforeElemRestangularized=b.onBeforeElemRestangularized||function(a){return a},a.setOnBeforeElemRestangularized=function(a){return b.onBeforeElemRestangularized=a,this},b.onElemRestangularized=b.onElemRestangularized||function(a){return a},a.setOnElemRestangularized=function(a){return b.onElemRestangularized=a,this},a.setListTypeIsArray=function(){},b.shouldSaveParent=b.shouldSaveParent||function(){return!0},a.setParentless=function(a){return _.isArray(a)?b.shouldSaveParent=function(b){return!_.contains(a,b)}:_.isBoolean(a)&&(b.shouldSaveParent=function(){return!a}),this},b.suffix=_.isUndefined(b.suffix)?null:b.suffix,a.setRequestSuffix=function(a){return b.suffix=a,this},b.transformers=b.transformers||{},a.addElementTransformer=function(a,c,d){var e=null,f=null;2===arguments.length?f=c:(f=d,e=c);var g=b.transformers[a];g||(g=b.transformers[a]=[]),g.push(function(a,b){return _.isNull(e)||a==e?f(b):b})},a.extendCollection=function(b,c){return a.addElementTransformer(b,!0,c)},a.extendModel=function(b,c){return a.addElementTransformer(b,!1,c)},b.transformElem=function(a,c,d,e){var f=b.transformers[d],g=a;return f&&_.each(f,function(a){g=a(c,g)}),b.onElemRestangularized(g,c,d,e)},b.fullResponse=_.isUndefined(b.fullResponse)?!1:b.fullResponse,a.setFullResponse=function(a){return b.fullResponse=a,this},b.urlCreatorFactory={};var f=function(){};f.prototype.setConfig=function(a){return this.config=a,this},f.prototype.parentsArray=function(a){for(var b=[];a;)b.push(a),a=a[this.config.restangularFields.parentResource];return b.reverse()},f.prototype.resource=function(a,d,e,f,g,h,i,j){var k=_.defaults(g||{},this.config.defaultRequestParams.common),l=_.defaults(f||{},this.config.defaultHeaders);i&&(b.isSafe(j)?l["If-None-Match"]=i:l["If-Match"]=i);var m=this.base(a);if(h){var n="";/\/$/.test(m)||(n+="/"),n+=h,m+=n}return this.config.suffix&&-1===m.indexOf(this.config.suffix,m.length-this.config.suffix.length)&&!this.config.getUrlFromElem(a)&&(m+=this.config.suffix),a[this.config.restangularFields.httpConfig]=void 0,c(this.config,d,m,{getList:this.config.withHttpValues(e,{method:"GET",params:k,headers:l}),get:this.config.withHttpValues(e,{method:"GET",params:k,headers:l}),put:this.config.withHttpValues(e,{method:"PUT",params:k,headers:l}),post:this.config.withHttpValues(e,{method:"POST",params:k,headers:l}),remove:this.config.withHttpValues(e,{method:"DELETE",params:k,headers:l}),head:this.config.withHttpValues(e,{method:"HEAD",params:k,headers:l}),trace:this.config.withHttpValues(e,{method:"TRACE",params:k,headers:l}),options:this.config.withHttpValues(e,{method:"OPTIONS",params:k,headers:l}),patch:this.config.withHttpValues(e,{method:"PATCH",params:k,headers:l})})};var g=function(){};g.prototype=new f,g.prototype.base=function(a){var c=this;return _.reduce(this.parentsArray(a),function(a,d){var e,f=c.config.getUrlFromElem(d);if(f){if(c.config.isAbsoluteUrl(f))return f;e=f}else if(e=d[c.config.restangularFields.route],d[c.config.restangularFields.restangularCollection]){var g=d[c.config.restangularFields.ids];g&&(e+="/"+g.join(","))}else{var h;h=c.config.useCannonicalId?c.config.getCannonicalIdFromElem(d):c.config.getIdFromElem(d),b.isValidId(h)&&(e+="/"+(c.config.encodeIds?encodeURIComponent(h):h))}return a+"/"+e},this.config.baseUrl)},g.prototype.fetchUrl=function(a,b){var c=this.base(a);return b&&(c+="/"+b),c},g.prototype.fetchRequestedUrl=function(a,c){function d(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b.sort()}function e(a,b,c){for(var e=d(a),f=0;fhlA!`vl_tFXu?~i-V`#jJ4 zo~P$M_jL4xVBw@dR(B{#AW7h!bnn>#87@ad`EPpv@$^XqO%4lWz;3;A#mdjvFu3;~w zE+!%{4c;Tf?5NzR;1p~~b4>uf5-m6xDSW%@JfGH?_bNY*Ytuoi{gD?c^Ba=+MZPAt zvHb>1A|EuRNZ5PEn*u)gIVc2tL6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