2016-12-13 22:01:05 -05:00
|
|
|
/* eslint-disable new-cap, comma-dangle, no-new, semi */
|
|
|
|
/* global Vue */
|
|
|
|
/* global Flash */
|
|
|
|
|
2016-09-28 06:12:13 -04:00
|
|
|
//= require vue
|
|
|
|
//= require ./merge_conflict_store
|
|
|
|
//= require ./merge_conflict_service
|
2016-10-05 08:57:22 -04:00
|
|
|
//= require ./mixins/line_conflict_utils
|
|
|
|
//= require ./mixins/line_conflict_actions
|
2016-09-28 06:12:13 -04:00
|
|
|
//= require ./components/diff_file_editor
|
2016-10-05 08:57:22 -04:00
|
|
|
//= require ./components/inline_conflict_lines
|
|
|
|
//= require ./components/parallel_conflict_lines
|
2016-09-28 06:12:13 -04:00
|
|
|
|
|
|
|
$(() => {
|
|
|
|
const INTERACTIVE_RESOLVE_MODE = 'interactive';
|
2016-10-05 21:49:43 -04:00
|
|
|
const conflictsEl = document.querySelector('#conflicts');
|
2016-09-28 06:12:13 -04:00
|
|
|
const mergeConflictsStore = gl.mergeConflicts.mergeConflictsStore;
|
|
|
|
const mergeConflictsService = new gl.mergeConflicts.mergeConflictsService({
|
2016-10-05 21:49:43 -04:00
|
|
|
conflictsPath: conflictsEl.dataset.conflictsPath,
|
|
|
|
resolveConflictsPath: conflictsEl.dataset.resolveConflictsPath
|
2016-09-28 06:12:13 -04:00
|
|
|
});
|
|
|
|
|
2016-10-05 21:49:43 -04:00
|
|
|
gl.MergeConflictsResolverApp = new Vue({
|
2016-09-28 06:12:13 -04:00
|
|
|
el: '#conflicts',
|
|
|
|
data: mergeConflictsStore.state,
|
|
|
|
components: {
|
2016-10-05 08:57:22 -04:00
|
|
|
'diff-file-editor': gl.mergeConflicts.diffFileEditor,
|
|
|
|
'inline-conflict-lines': gl.mergeConflicts.inlineConflictLines,
|
|
|
|
'parallel-conflict-lines': gl.mergeConflicts.parallelConflictLines
|
2016-09-28 06:12:13 -04:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
conflictsCountText() { return mergeConflictsStore.getConflictsCountText() },
|
|
|
|
readyToCommit() { return mergeConflictsStore.isReadyToCommit() },
|
2016-09-30 17:23:38 -04:00
|
|
|
commitButtonText() { return mergeConflictsStore.getCommitButtonText() },
|
|
|
|
showDiffViewTypeSwitcher() { return mergeConflictsStore.fileTextTypePresent() }
|
2016-09-28 06:12:13 -04:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
mergeConflictsService
|
|
|
|
.fetchConflictsData()
|
|
|
|
.done((data) => {
|
|
|
|
if (data.type === 'error') {
|
|
|
|
mergeConflictsStore.setFailedRequest(data.message);
|
|
|
|
} else {
|
|
|
|
mergeConflictsStore.setConflictsData(data);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.error(() => {
|
|
|
|
mergeConflictsStore.setFailedRequest();
|
|
|
|
})
|
|
|
|
.always(() => {
|
|
|
|
mergeConflictsStore.setLoadingState(false);
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
2016-11-02 21:06:25 -04:00
|
|
|
$('.js-syntax-highlight').syntaxHighlight();
|
2016-09-28 06:12:13 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleViewTypeChange(viewType) {
|
|
|
|
mergeConflictsStore.setViewType(viewType);
|
|
|
|
},
|
|
|
|
onClickResolveModeButton(file, mode) {
|
|
|
|
if (mode === INTERACTIVE_RESOLVE_MODE && file.resolveEditChanged) {
|
|
|
|
mergeConflictsStore.setPromptConfirmationState(file, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mergeConflictsStore.setFileResolveMode(file, mode);
|
|
|
|
},
|
|
|
|
acceptDiscardConfirmation(file) {
|
|
|
|
mergeConflictsStore.setPromptConfirmationState(file, false);
|
|
|
|
mergeConflictsStore.setFileResolveMode(file, INTERACTIVE_RESOLVE_MODE);
|
|
|
|
},
|
|
|
|
cancelDiscardConfirmation(file) {
|
|
|
|
mergeConflictsStore.setPromptConfirmationState(file, false);
|
|
|
|
},
|
|
|
|
commit() {
|
|
|
|
mergeConflictsStore.setSubmitState(true);
|
|
|
|
|
|
|
|
mergeConflictsService
|
|
|
|
.submitResolveConflicts(mergeConflictsStore.getCommitData())
|
|
|
|
.done((data) => {
|
|
|
|
window.location.href = data.redirect_to;
|
|
|
|
})
|
|
|
|
.error(() => {
|
|
|
|
mergeConflictsStore.setSubmitState(false);
|
|
|
|
new Flash('Failed to save merge conflicts resolutions. Please try again!');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|