Convert merge_conflict_service.js to axios

This commit is contained in:
Phil Hughes 2018-01-30 16:47:19 +00:00
parent 05a3479c9e
commit 8750507b5d
No known key found for this signature in database
GPG Key ID: 32245528C52E0F9F
2 changed files with 11 additions and 21 deletions

View File

@ -1,4 +1,5 @@
/* eslint-disable no-param-reassign, comma-dangle */ /* eslint-disable no-param-reassign, comma-dangle */
import axios from '../lib/utils/axios_utils';
((global) => { ((global) => {
global.mergeConflicts = global.mergeConflicts || {}; global.mergeConflicts = global.mergeConflicts || {};
@ -10,20 +11,11 @@
} }
fetchConflictsData() { fetchConflictsData() {
return $.ajax({ return axios.get(this.conflictsPath);
dataType: 'json',
url: this.conflictsPath
});
} }
submitResolveConflicts(data) { submitResolveConflicts(data) {
return $.ajax({ return axios.post(this.resolveConflictsPath, data);
url: this.resolveConflictsPath,
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
method: 'POST'
});
} }
} }

View File

@ -38,24 +38,22 @@ $(() => {
showDiffViewTypeSwitcher() { return mergeConflictsStore.fileTextTypePresent(); } showDiffViewTypeSwitcher() { return mergeConflictsStore.fileTextTypePresent(); }
}, },
created() { created() {
mergeConflictsService mergeConflictsService.fetchConflictsData()
.fetchConflictsData() .then(({ data }) => {
.done((data) => {
if (data.type === 'error') { if (data.type === 'error') {
mergeConflictsStore.setFailedRequest(data.message); mergeConflictsStore.setFailedRequest(data.message);
} else { } else {
mergeConflictsStore.setConflictsData(data); mergeConflictsStore.setConflictsData(data);
} }
})
.error(() => {
mergeConflictsStore.setFailedRequest();
})
.always(() => {
mergeConflictsStore.setLoadingState(false); mergeConflictsStore.setLoadingState(false);
this.$nextTick(() => { this.$nextTick(() => {
syntaxHighlight($('.js-syntax-highlight')); syntaxHighlight($('.js-syntax-highlight'));
}); });
})
.catch(() => {
mergeConflictsStore.setFailedRequest();
}); });
}, },
methods: { methods: {
@ -82,10 +80,10 @@ $(() => {
mergeConflictsService mergeConflictsService
.submitResolveConflicts(mergeConflictsStore.getCommitData()) .submitResolveConflicts(mergeConflictsStore.getCommitData())
.done((data) => { .then(({ data }) => {
window.location.href = data.redirect_to; window.location.href = data.redirect_to;
}) })
.error(() => { .catch(() => {
mergeConflictsStore.setSubmitState(false); mergeConflictsStore.setSubmitState(false);
new Flash('Failed to save merge conflicts resolutions. Please try again!'); new Flash('Failed to save merge conflicts resolutions. Please try again!');
}); });