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

104 lines
3.3 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-03-11 19:13:27 +05:30
import { __ } from '~/locale';
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';
2021-03-11 19:13:27 +05:30
import syntaxHighlight from '../syntax_highlight';
2021-04-17 20:07:23 +05:30
import MergeConflictsResolverApp from './merge_conflict_resolver_app.vue';
2018-11-08 19:23:39 +05:30
import MergeConflictsService from './merge_conflict_service';
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
});
2021-04-17 20:07:23 +05:30
const { sourceBranchPath, mergeRequestPath } = conflictsEl.dataset;
2017-09-10 17:25:29 +05:30
initIssuableSidebar();
2021-04-17 20:07:23 +05:30
return new Vue({
el: conflictsEl,
provide: {
sourceBranchPath,
mergeRequestPath,
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
},
},
2021-04-17 20:07:23 +05:30
render(createElement) {
return createElement(MergeConflictsResolverApp);
},
2017-08-17 22:00:37 +05:30
});
2018-03-27 19:54:05 +05:30
}