diff options
author | Fatih Acet <acetfatih@gmail.com> | 2017-08-24 12:13:42 +0000 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2017-08-24 12:13:42 +0000 |
commit | 6752a3bbe38bbd1a99caa2b3d8c36c55c3096ac4 (patch) | |
tree | f531a551c02a3d66a4316936257eac3bffd0d556 /app | |
parent | 610155e063251036f35aadd4dc0f707d1738e54b (diff) | |
parent | 9eb28bbf218d8d7bfdfc0db4bc49e59004c847e0 (diff) | |
download | gitlab-ce-6752a3bbe38bbd1a99caa2b3d8c36c55c3096ac4.tar.gz |
Merge branch 'thenable-ajax-api-calls' into 'master'
Thenable ajax api calls
See merge request !13427
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/api.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/repo/components/repo_commit_section.vue | 4 | ||||
-rw-r--r-- | app/assets/javascripts/repo/services/repo_service.js | 20 |
3 files changed, 18 insertions, 15 deletions
diff --git a/app/assets/javascripts/api.js b/app/assets/javascripts/api.js index 56f91e95bb9..4319bfcc57f 100644 --- a/app/assets/javascripts/api.js +++ b/app/assets/javascripts/api.js @@ -96,18 +96,17 @@ const Api = { .done(projects => callback(projects)); }, - commitMultiple(id, data, callback) { + commitMultiple(id, data) { + // see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions const url = Api.buildUrl(Api.commitPath) .replace(':id', id); - return $.ajax({ + return this.wrapAjaxCall({ url, type: 'POST', contentType: 'application/json; charset=utf-8', data: JSON.stringify(data), dataType: 'json', - }) - .done(commitData => callback(commitData)) - .fail(message => callback(message.responseJSON)); + }); }, // Return text for a specific license diff --git a/app/assets/javascripts/repo/components/repo_commit_section.vue b/app/assets/javascripts/repo/components/repo_commit_section.vue index 5ec4a9b6593..1282828b504 100644 --- a/app/assets/javascripts/repo/components/repo_commit_section.vue +++ b/app/assets/javascripts/repo/components/repo_commit_section.vue @@ -42,7 +42,9 @@ export default { actions, }; Store.submitCommitsLoading = true; - Service.commitFiles(payload, this.resetCommitState); + Service.commitFiles(payload) + .then(this.resetCommitState) + .catch(() => Flash('An error occured while committing your changes')); }, resetCommitState() { diff --git a/app/assets/javascripts/repo/services/repo_service.js b/app/assets/javascripts/repo/services/repo_service.js index 3cf204e6ec8..af83497fa39 100644 --- a/app/assets/javascripts/repo/services/repo_service.js +++ b/app/assets/javascripts/repo/services/repo_service.js @@ -65,15 +65,17 @@ const RepoService = { return urlArray.join('/'); }, - commitFiles(payload, cb) { - Api.commitMultiple(Store.projectId, payload, (data) => { - if (data.short_id && data.stats) { - Flash(`Your changes have been committed. Commit ${data.short_id} with ${data.stats.additions} additions, ${data.stats.deletions} deletions.`, 'notice'); - } else { - Flash(data.message); - } - cb(); - }); + commitFiles(payload) { + return Api.commitMultiple(Store.projectId, payload) + .then(this.commitFlash); + }, + + commitFlash(data) { + if (data.short_id && data.stats) { + window.Flash(`Your changes have been committed. Commit ${data.short_id} with ${data.stats.additions} additions, ${data.stats.deletions} deletions.`, 'notice'); + } else { + window.Flash(data.message); + } }, }; |