debian-mirror-gitlab/app/assets/javascripts/merge_conflicts/merge_conflicts_bundle.js

104 lines
3.4 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2021-02-22 17:27:13 +05:30
import FileIcon from '~/vue_shared/components/file_icon.vue';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as createFlash } from '../flash';
2017-09-10 17:25:29 +05:30
import initIssuableSidebar from '../init_issuable_sidebar';
import './merge_conflict_store';
2018-11-08 19:23:39 +05:30
import MergeConflictsService from './merge_conflict_service';
2017-09-10 17:25:29 +05:30
import './components/diff_file_editor';
import './components/inline_conflict_lines';
import './components/parallel_conflict_lines';
2018-03-17 18:26:18 +05:30
import syntaxHighlight from '../syntax_highlight';
2019-07-31 22:56:46 +05:30
import { __ } from '~/locale';
2016-11-03 12:29:30 +05:30
2018-03-27 19:54:05 +05:30
export default function initMergeConflicts() {
2016-11-03 12:29:30 +05:30
const INTERACTIVE_RESOLVE_MODE = 'interactive';
const conflictsEl = document.querySelector('#conflicts');
2018-11-08 19:23:39 +05:30
const { mergeConflictsStore } = gl.mergeConflicts;
const mergeConflictsService = new MergeConflictsService({
2016-11-03 12:29:30 +05:30
conflictsPath: conflictsEl.dataset.conflictsPath,
2018-11-08 19:23:39 +05:30
resolveConflictsPath: conflictsEl.dataset.resolveConflictsPath,
2016-11-03 12:29:30 +05:30
});
2017-09-10 17:25:29 +05:30
initIssuableSidebar();
2016-11-03 12:29:30 +05:30
gl.MergeConflictsResolverApp = new Vue({
el: '#conflicts',
components: {
2021-02-22 17:27:13 +05:30
FileIcon,
2016-11-03 12:29:30 +05:30
'diff-file-editor': gl.mergeConflicts.diffFileEditor,
'inline-conflict-lines': gl.mergeConflicts.inlineConflictLines,
2018-11-08 19:23:39 +05:30
'parallel-conflict-lines': gl.mergeConflicts.parallelConflictLines,
2016-11-03 12:29:30 +05:30
},
2018-03-17 18:26:18 +05:30
data: mergeConflictsStore.state,
2016-11-03 12:29:30 +05:30
computed: {
2018-11-08 19:23:39 +05:30
conflictsCountText() {
return mergeConflictsStore.getConflictsCountText();
},
readyToCommit() {
return mergeConflictsStore.isReadyToCommit();
},
commitButtonText() {
return mergeConflictsStore.getCommitButtonText();
},
showDiffViewTypeSwitcher() {
return mergeConflictsStore.fileTextTypePresent();
},
2016-11-03 12:29:30 +05:30
},
created() {
2018-11-08 19:23:39 +05:30
mergeConflictsService
.fetchConflictsData()
2018-03-17 18:26:18 +05:30
.then(({ data }) => {
2016-11-03 12:29:30 +05:30
if (data.type === 'error') {
mergeConflictsStore.setFailedRequest(data.message);
} else {
mergeConflictsStore.setConflictsData(data);
}
2018-03-17 18:26:18 +05:30
2016-11-03 12:29:30 +05:30
mergeConflictsStore.setLoadingState(false);
this.$nextTick(() => {
2018-03-17 18:26:18 +05:30
syntaxHighlight($('.js-syntax-highlight'));
2016-11-03 12:29:30 +05:30
});
2018-03-17 18:26:18 +05:30
})
.catch(() => {
mergeConflictsStore.setLoadingState(false);
mergeConflictsStore.setFailedRequest();
2016-11-03 12:29:30 +05:30
});
},
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-03-17 18:26:18 +05:30
.then(({ data }) => {
2016-11-03 12:29:30 +05:30
window.location.href = data.redirect_to;
})
2018-03-17 18:26:18 +05:30
.catch(() => {
2016-11-03 12:29:30 +05:30
mergeConflictsStore.setSubmitState(false);
2019-07-31 22:56:46 +05:30
createFlash(__('Failed to save merge conflicts resolutions. Please try again!'));
2016-11-03 12:29:30 +05:30
});
2018-11-08 19:23:39 +05:30
},
},
2017-08-17 22:00:37 +05:30
});
2018-03-27 19:54:05 +05:30
}