2017-01-10 17:54:56 -05:00
|
|
|
/* eslint-disable new-cap, comma-dangle, no-new */
|
2016-12-13 22:01:05 -05:00
|
|
|
/* global Flash */
|
|
|
|
|
2017-03-17 13:21:25 -04:00
|
|
|
import Vue from 'vue';
|
2017-05-16 16:52:40 -04:00
|
|
|
import './merge_conflict_store';
|
|
|
|
import './merge_conflict_service';
|
|
|
|
import './mixins/line_conflict_utils';
|
|
|
|
import './mixins/line_conflict_actions';
|
|
|
|
import './components/diff_file_editor';
|
|
|
|
import './components/inline_conflict_lines';
|
|
|
|
import './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: {
|
2017-01-10 17:54:56 -05:00
|
|
|
conflictsCountText() { return mergeConflictsStore.getConflictsCountText(); },
|
|
|
|
readyToCommit() { return mergeConflictsStore.isReadyToCommit(); },
|
|
|
|
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!');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 17:54:56 -05:00
|
|
|
});
|
2016-09-28 06:12:13 -04:00
|
|
|
});
|