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

95 lines
3.3 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable new-cap, comma-dangle, no-new */
import Vue from 'vue';
2018-03-17 18:26:18 +05:30
import Flash from '../flash';
2017-09-10 17:25:29 +05:30
import initIssuableSidebar from '../init_issuable_sidebar';
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';
2018-03-17 18:26:18 +05:30
import syntaxHighlight from '../syntax_highlight';
2016-11-03 12:29:30 +05:30
$(() => {
const INTERACTIVE_RESOLVE_MODE = 'interactive';
const conflictsEl = document.querySelector('#conflicts');
const mergeConflictsStore = gl.mergeConflicts.mergeConflictsStore;
const mergeConflictsService = new gl.mergeConflicts.mergeConflictsService({
conflictsPath: conflictsEl.dataset.conflictsPath,
resolveConflictsPath: conflictsEl.dataset.resolveConflictsPath
});
2017-09-10 17:25:29 +05:30
initIssuableSidebar();
2016-11-03 12:29:30 +05:30
gl.MergeConflictsResolverApp = new Vue({
el: '#conflicts',
components: {
'diff-file-editor': gl.mergeConflicts.diffFileEditor,
'inline-conflict-lines': gl.mergeConflicts.inlineConflictLines,
'parallel-conflict-lines': gl.mergeConflicts.parallelConflictLines
},
2018-03-17 18:26:18 +05:30
data: mergeConflictsStore.state,
2016-11-03 12:29:30 +05:30
computed: {
2017-08-17 22:00:37 +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-03-17 18:26:18 +05:30
mergeConflictsService.fetchConflictsData()
.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);
new Flash('Failed to save merge conflicts resolutions. Please try again!');
});
}
}
2017-08-17 22:00:37 +05:30
});
2016-11-03 12:29:30 +05:30
});