2019-12-26 22:10:19 +05:30
|
|
|
/* eslint-disable func-names, no-underscore-dangle, consistent-return */
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
import $ from 'jquery';
|
2020-07-28 23:09:34 +05:30
|
|
|
import axios from './lib/utils/axios_utils';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { __ } from '~/locale';
|
2019-03-02 22:35:43 +05:30
|
|
|
import createFlash from '~/flash';
|
2017-09-10 17:25:29 +05:30
|
|
|
import TaskList from './task_list';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MergeRequestTabs from './merge_request_tabs';
|
2017-09-10 17:25:29 +05:30
|
|
|
import IssuablesHelper from './helpers/issuables_helper';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { addDelimiter } from './lib/utils/text_utility';
|
|
|
|
|
|
|
|
function MergeRequest(opts) {
|
|
|
|
// Initialize MergeRequest behavior
|
|
|
|
//
|
|
|
|
// Options:
|
|
|
|
// action - String, current controller action
|
|
|
|
//
|
|
|
|
this.opts = opts != null ? opts : {};
|
|
|
|
this.submitNoteForm = this.submitNoteForm.bind(this);
|
|
|
|
this.$el = $('.merge-request');
|
2019-12-26 22:10:19 +05:30
|
|
|
this.$('.show-all-commits').on('click', () => this.showAllCommits());
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
this.initTabs();
|
|
|
|
this.initMRBtnListeners();
|
|
|
|
this.initCommitMessageListeners();
|
|
|
|
this.closeReopenReportToggle = IssuablesHelper.initCloseReopenReport();
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
if ($('.description.js-task-list-container').length) {
|
2018-03-17 18:26:18 +05:30
|
|
|
this.taskList = new TaskList({
|
|
|
|
dataType: 'merge_request',
|
|
|
|
fieldName: 'description',
|
|
|
|
selector: '.detail-page-description',
|
2019-03-02 22:35:43 +05:30
|
|
|
lockVersion: this.$el.data('lockVersion'),
|
2018-12-13 13:39:08 +05:30
|
|
|
onSuccess: result => {
|
2018-03-17 18:26:18 +05:30
|
|
|
document.querySelector('#task_status').innerText = result.task_status;
|
|
|
|
document.querySelector('#task_status_short').innerText = result.task_status_short;
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
onError: () => {
|
|
|
|
createFlash(
|
|
|
|
__(
|
|
|
|
'Someone edited this merge request at the same time you did. Please refresh the page to see changes.',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local jQuery finder
|
|
|
|
MergeRequest.prototype.$ = function(selector) {
|
|
|
|
return this.$el.find(selector);
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initTabs = function() {
|
|
|
|
if (window.mrTabs) {
|
|
|
|
window.mrTabs.unbindEvents();
|
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
window.mrTabs = new MergeRequestTabs(this.opts);
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.showAllCommits = function() {
|
|
|
|
this.$('.first-commits').remove();
|
|
|
|
return this.$('.all-commits').removeClass('hide');
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initMRBtnListeners = function() {
|
2019-12-26 22:10:19 +05:30
|
|
|
const _this = this;
|
2020-07-28 23:09:34 +05:30
|
|
|
return $('.btn-close, .btn-reopen').on('click', function(e) {
|
2019-12-26 22:10:19 +05:30
|
|
|
const $this = $(this);
|
|
|
|
const shouldSubmit = $this.hasClass('btn-comment');
|
2020-07-28 23:09:34 +05:30
|
|
|
if ($this.hasClass('js-btn-issue-action')) {
|
|
|
|
const url = $this.data('endpoint');
|
|
|
|
return axios
|
|
|
|
.put(url)
|
|
|
|
.then(() => window.location.reload())
|
|
|
|
.catch(() => createFlash(__('Something went wrong.')));
|
|
|
|
}
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if (shouldSubmit && $this.data('submitted')) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if (this.closeReopenReportToggle) this.closeReopenReportToggle.setDisable();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if (shouldSubmit) {
|
|
|
|
if ($this.hasClass('btn-comment-and-close') || $this.hasClass('btn-comment-and-reopen')) {
|
2017-08-17 22:00:37 +05:30
|
|
|
e.preventDefault();
|
2018-03-17 18:26:18 +05:30
|
|
|
e.stopImmediatePropagation();
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
_this.submitNoteForm($this.closest('form'), $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.submitNoteForm = function(form, $button) {
|
2019-12-26 22:10:19 +05:30
|
|
|
const noteText = form.find('textarea.js-note-text').val();
|
2018-03-17 18:26:18 +05:30
|
|
|
if (noteText.trim().length > 0) {
|
|
|
|
form.submit();
|
|
|
|
$button.data('submitted', true);
|
|
|
|
return $button.trigger('click');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initCommitMessageListeners = function() {
|
2019-12-21 20:55:43 +05:30
|
|
|
$(document).on('click', 'a.js-with-description-link', e => {
|
2019-12-26 22:10:19 +05:30
|
|
|
const textarea = $('textarea.js-commit-message');
|
2018-03-17 18:26:18 +05:30
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithDescription'));
|
|
|
|
$('.js-with-description-hint').hide();
|
|
|
|
$('.js-without-description-hint').show();
|
|
|
|
});
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
$(document).on('click', 'a.js-without-description-link', e => {
|
2019-12-26 22:10:19 +05:30
|
|
|
const textarea = $('textarea.js-commit-message');
|
2018-03-17 18:26:18 +05:30
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithoutDescription'));
|
|
|
|
$('.js-with-description-hint').show();
|
|
|
|
$('.js-without-description-hint').hide();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.setStatusBoxToMerged = function() {
|
|
|
|
$('.detail-page-header .status-box')
|
|
|
|
.removeClass('status-box-open')
|
|
|
|
.addClass('status-box-mr-merged')
|
|
|
|
.find('span')
|
|
|
|
.text(__('Merged'));
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.decreaseCounter = function(by = 1) {
|
|
|
|
const $el = $('.js-merge-counter');
|
2018-12-13 13:39:08 +05:30
|
|
|
const count = Math.max(parseInt($el.text().replace(/[^\d]/, ''), 10) - by, 0);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
$el.text(addDelimiter(count));
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.hideCloseButton = function() {
|
|
|
|
const el = document.querySelector('.merge-request .js-issuable-actions');
|
|
|
|
const closeDropdownItem = el.querySelector('li.close-item');
|
|
|
|
if (closeDropdownItem) {
|
|
|
|
closeDropdownItem.classList.add('hidden');
|
|
|
|
// Selects the next dropdown item
|
|
|
|
el.querySelector('li.report-item').click();
|
|
|
|
} else {
|
|
|
|
// No dropdown just hide the Close button
|
|
|
|
el.querySelector('.btn-close').classList.add('hidden');
|
|
|
|
}
|
|
|
|
// Dropdown for mobile screen
|
|
|
|
el.querySelector('li.js-close-item').classList.add('hidden');
|
|
|
|
};
|
|
|
|
|
|
|
|
export default MergeRequest;
|