2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2017-03-17 17:21:25 +00:00
|
|
|
import Vue from 'vue';
|
2018-06-15 09:30:07 +00:00
|
|
|
import createFlash from '../flash';
|
2017-07-26 10:13:35 +00:00
|
|
|
import initIssuableSidebar from '../init_issuable_sidebar';
|
2017-05-16 20:52:40 +00:00
|
|
|
import './merge_conflict_store';
|
2018-06-13 11:35:32 +00:00
|
|
|
import MergeConflictsService from './merge_conflict_service';
|
2017-05-16 20:52:40 +00:00
|
|
|
import './components/diff_file_editor';
|
|
|
|
import './components/inline_conflict_lines';
|
|
|
|
import './components/parallel_conflict_lines';
|
2017-12-13 09:26:44 +00:00
|
|
|
import syntaxHighlight from '../syntax_highlight';
|
2019-05-02 13:07:34 +00:00
|
|
|
import { __ } from '~/locale';
|
2016-09-28 10:12:13 +00:00
|
|
|
|
2018-02-27 22:53:49 +00:00
|
|
|
export default function initMergeConflicts() {
|
2016-09-28 10:12:13 +00:00
|
|
|
const INTERACTIVE_RESOLVE_MODE = 'interactive';
|
2016-10-06 01:49:43 +00:00
|
|
|
const conflictsEl = document.querySelector('#conflicts');
|
2018-06-16 21:50:13 +00:00
|
|
|
const { mergeConflictsStore } = gl.mergeConflicts;
|
2018-06-13 11:35:32 +00:00
|
|
|
const mergeConflictsService = new MergeConflictsService({
|
2016-10-06 01:49:43 +00:00
|
|
|
conflictsPath: conflictsEl.dataset.conflictsPath,
|
2018-06-15 09:30:07 +00:00
|
|
|
resolveConflictsPath: conflictsEl.dataset.resolveConflictsPath,
|
2016-09-28 10:12:13 +00:00
|
|
|
});
|
|
|
|
|
2017-07-26 10:13:35 +00:00
|
|
|
initIssuableSidebar();
|
|
|
|
|
2016-10-06 01:49:43 +00:00
|
|
|
gl.MergeConflictsResolverApp = new Vue({
|
2016-09-28 10:12:13 +00:00
|
|
|
el: '#conflicts',
|
|
|
|
components: {
|
2016-10-05 12:57:22 +00:00
|
|
|
'diff-file-editor': gl.mergeConflicts.diffFileEditor,
|
|
|
|
'inline-conflict-lines': gl.mergeConflicts.inlineConflictLines,
|
2018-06-15 09:30:07 +00:00
|
|
|
'parallel-conflict-lines': gl.mergeConflicts.parallelConflictLines,
|
2016-09-28 10:12:13 +00:00
|
|
|
},
|
2018-01-03 23:14:55 +00:00
|
|
|
data: mergeConflictsStore.state,
|
2016-09-28 10:12:13 +00:00
|
|
|
computed: {
|
2018-06-15 09:30:07 +00:00
|
|
|
conflictsCountText() {
|
|
|
|
return mergeConflictsStore.getConflictsCountText();
|
|
|
|
},
|
|
|
|
readyToCommit() {
|
|
|
|
return mergeConflictsStore.isReadyToCommit();
|
|
|
|
},
|
|
|
|
commitButtonText() {
|
|
|
|
return mergeConflictsStore.getCommitButtonText();
|
|
|
|
},
|
|
|
|
showDiffViewTypeSwitcher() {
|
|
|
|
return mergeConflictsStore.fileTextTypePresent();
|
|
|
|
},
|
2016-09-28 10:12:13 +00:00
|
|
|
},
|
|
|
|
created() {
|
2018-06-15 09:30:07 +00:00
|
|
|
mergeConflictsService
|
|
|
|
.fetchConflictsData()
|
2018-01-30 16:47:19 +00:00
|
|
|
.then(({ data }) => {
|
2016-09-28 10:12:13 +00:00
|
|
|
if (data.type === 'error') {
|
|
|
|
mergeConflictsStore.setFailedRequest(data.message);
|
|
|
|
} else {
|
|
|
|
mergeConflictsStore.setConflictsData(data);
|
|
|
|
}
|
2018-01-30 16:47:19 +00:00
|
|
|
|
2016-09-28 10:12:13 +00:00
|
|
|
mergeConflictsStore.setLoadingState(false);
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
2017-12-13 09:26:44 +00:00
|
|
|
syntaxHighlight($('.js-syntax-highlight'));
|
2016-09-28 10:12:13 +00:00
|
|
|
});
|
2018-01-30 16:47:19 +00:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2018-02-02 16:33:38 +00:00
|
|
|
mergeConflictsStore.setLoadingState(false);
|
2018-01-30 16:47:19 +00:00
|
|
|
mergeConflictsStore.setFailedRequest();
|
2016-09-28 10:12:13 +00: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())
|
2018-01-30 16:47:19 +00:00
|
|
|
.then(({ data }) => {
|
2016-09-28 10:12:13 +00:00
|
|
|
window.location.href = data.redirect_to;
|
|
|
|
})
|
2018-01-30 16:47:19 +00:00
|
|
|
.catch(() => {
|
2016-09-28 10:12:13 +00:00
|
|
|
mergeConflictsStore.setSubmitState(false);
|
2019-05-02 13:07:34 +00:00
|
|
|
createFlash(__('Failed to save merge conflicts resolutions. Please try again!'));
|
2016-09-28 10:12:13 +00:00
|
|
|
});
|
2018-06-15 09:30:07 +00:00
|
|
|
},
|
|
|
|
},
|
2017-01-10 22:54:56 +00:00
|
|
|
});
|
2018-02-27 22:53:49 +00:00
|
|
|
}
|