diff --git a/.eslintrc b/.eslintrc index e8eb590..57049e3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,6 +19,7 @@ "__BASE_PATH__": true }, "rules": { + "no-unexpected-multiline": "off", "indent": [ "error", 2, diff --git a/dist/sanji-rest-ui.js b/dist/sanji-rest-ui.js index c9d9a77..4f5b27d 100644 --- a/dist/sanji-rest-ui.js +++ b/dist/sanji-rest-ui.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("angular"),require("ng-file-upload")):"function"==typeof define&&define.amd?define(["angular","ng-file-upload"],t):"object"==typeof exports?exports.sjRest=t(require("angular"),require("ng-file-upload")):e.sjRest=t(e.angular,e.ngFileUpload)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var u=n[r]={i:r,l:!1,exports:{}};return e[r].call(u.exports,u,u.exports,t),u.l=!0,u.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,t,n){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:{},o=e.defer(),c=JSON.parse(JSON.stringify(u)),f=c.basePath||a.basePath,l=[f+n];return t=t.toLowerCase(),t.match(/post|put/)&&l.push(r),t.match(/delete/)&&(c.data=r,c.headers?c.headers["Content-Type"]="application/json":c.headers={"Content-Type":"application/json"}),l.push(c),i[t](l).then(function(e){o.resolve(e)}).catch(function(e){o.reject(e)}),o.promise}var a=this.config,i=n.get(a.service);return{configure:function(e){return Object.assign(a,e)},get:function(e,t){return o("get",e,null,t)},post:function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("http"===a.service&&Array.isArray(n)){var c=i.basePath||a.basePath,f={url:c+e,method:"POST",data:{}};return u(f,t,n),r.upload(Object.assign(f,i))}return o("post",e,t,i)},put:function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if("http"===a.service&&Array.isArray(n)){i=i||{};var c=i.basePath||a.basePath,f={url:c+e,method:"PUT",data:{}};return u(f,t,n),r.upload(Object.assign(f,i))}return o("put",e,t,i)},delete:function(e,t,n){return o("delete",e,t,n)}}}]}]),e}();o.$inject=u,t.default=o},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.sjRest=void 0;var u=n(2),o=r(u),a=n(3),i=r(a),c=n(0),f=r(c),l=n(1),s=r(l),p=o.default.module("sanji.rest",[i.default]).service("http",f.default).provider("rest",s.default).name;t.sjRest=p}])}); \ No newline at end of file diff --git a/package.json b/package.json index f788213..8362d6c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "sanji-rest-ui", "author": "Zack Yang (https://github.com/zack9433)", "description": "sanji-rest-ui UI", - "version": "1.4.1", + "version": "1.4.2", "main": "dist/sanji-rest-ui.js", "config": { "ghooks": { diff --git a/src/component/restful.provider.js b/src/component/restful.provider.js index 68e4885..fa2b426 100644 --- a/src/component/restful.provider.js +++ b/src/component/restful.provider.js @@ -21,9 +21,8 @@ class RestProvider { get: (uri, options) => { return makeRequest('get', uri, null, options); }, - post: (uri, data, files, options) => { + post: (uri, data, files, options = {}) => { if ('http' === config.service && Array.isArray(files)) { - options = options || {}; const base = options.basePath || config.basePath; const setting = { url: base + uri, @@ -32,12 +31,11 @@ class RestProvider { }; transformUploadSetting(setting, data, files); return Upload.upload(Object.assign(setting, options)); - } - else { + } else { return makeRequest('post', uri, data, options); } }, - put: (uri, data, files, options) => { + put: (uri, data, files, options = {}) => { if ('http' === config.service && Array.isArray(files)) { options = options || {}; const base = options.basePath || config.basePath; @@ -48,8 +46,7 @@ class RestProvider { }; transformUploadSetting(setting, data, files); return Upload.upload(Object.assign(setting, options)); - } - else { + } else { return makeRequest('put', uri, data, options); } }, @@ -60,7 +57,7 @@ class RestProvider { function transformUploadSetting(setting, data, files) { if (files[0] instanceof File) { - (files.length === 1) ? setting.data.file = files[0] : setting.data.files = files; + files.length === 1 ? (setting.data.file = files[0]) : (setting.data.files = files); } else { files.forEach(item => { if (item.key) { @@ -73,9 +70,9 @@ class RestProvider { } } - function makeRequest(verb, uri, data, options) { + function makeRequest(verb, uri, data, options = {}) { let defer = $q.defer(); - let reqConfig = options || {}; + let reqConfig = JSON.parse(JSON.stringify(options)); let base = reqConfig.basePath || config.basePath; //start with the uri let args = [base + uri]; @@ -97,13 +94,14 @@ class RestProvider { args.push(reqConfig); - rest[verb](args) - .then(function(res) { - defer.resolve(res); - }) - .catch(function(res) { - defer.reject(res); - }); + rest + [verb](args) + .then(function(res) { + defer.resolve(res); + }) + .catch(function(res) { + defer.reject(res); + }); return defer.promise; }