Skip to content

Commit

Permalink
v1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zack9433 committed Apr 13, 2017
2 parents e154470 + 4f8fef2 commit 926e6dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"__BASE_PATH__": true
},
"rules": {
"no-unexpected-multiline": "off",
"indent": [
"error",
2,
Expand Down
2 changes: 1 addition & 1 deletion dist/sanji-rest-ui.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sanji-rest-ui",
"author": "Zack Yang <[email protected]> (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": {
Expand Down
32 changes: 15 additions & 17 deletions src/component/restful.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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);
}
},
Expand All @@ -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) {
Expand All @@ -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];
Expand All @@ -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;
}
Expand Down

0 comments on commit 926e6dc

Please sign in to comment.