2019-11-18 10:06:27 -05:00
|
|
|
/* eslint-disable func-names, no-underscore-dangle, consistent-return */
|
2018-03-09 15:18:59 -05:00
|
|
|
|
|
|
|
import $ from 'jquery';
|
2018-01-17 09:09:59 -05:00
|
|
|
import { __ } from '~/locale';
|
2019-02-06 18:18:07 -05:00
|
|
|
import createFlash from '~/flash';
|
2017-07-06 14:05:58 -04:00
|
|
|
import TaskList from './task_list';
|
2017-12-15 04:31:58 -05:00
|
|
|
import MergeRequestTabs from './merge_request_tabs';
|
2017-07-07 11:04:43 -04:00
|
|
|
import IssuablesHelper from './helpers/issuables_helper';
|
2017-11-13 04:11:54 -05:00
|
|
|
import { addDelimiter } from './lib/utils/text_utility';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-12-15 07:57:08 -05:00
|
|
|
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-11-05 10:06:17 -05:00
|
|
|
this.$('.show-all-commits').on('click', () => this.showAllCommits());
|
2017-12-15 07:57:08 -05:00
|
|
|
|
|
|
|
this.initTabs();
|
|
|
|
this.initMRBtnListeners();
|
|
|
|
this.initCommitMessageListeners();
|
|
|
|
this.closeReopenReportToggle = IssuablesHelper.initCloseReopenReport();
|
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
if ($('.description.js-task-list-container').length) {
|
2017-12-15 07:57:08 -05:00
|
|
|
this.taskList = new TaskList({
|
|
|
|
dataType: 'merge_request',
|
|
|
|
fieldName: 'description',
|
|
|
|
selector: '.detail-page-description',
|
2019-01-24 18:31:14 -05:00
|
|
|
lockVersion: this.$el.data('lockVersion'),
|
2018-10-10 03:13:34 -04:00
|
|
|
onSuccess: result => {
|
2017-12-15 07:57:08 -05:00
|
|
|
document.querySelector('#task_status').innerText = result.task_status;
|
|
|
|
document.querySelector('#task_status_short').innerText = result.task_status_short;
|
2018-10-10 03:13:34 -04:00
|
|
|
},
|
2019-02-06 18:18:07 -05:00
|
|
|
onError: () => {
|
|
|
|
createFlash(
|
|
|
|
__(
|
|
|
|
'Someone edited this merge request at the same time you did. Please refresh the page to see changes.',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2017-12-15 07:57:08 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local jQuery finder
|
|
|
|
MergeRequest.prototype.$ = function(selector) {
|
|
|
|
return this.$el.find(selector);
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initTabs = function() {
|
|
|
|
if (window.mrTabs) {
|
|
|
|
window.mrTabs.unbindEvents();
|
|
|
|
}
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2017-12-15 07:57:08 -05:00
|
|
|
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-11-18 10:06:27 -05:00
|
|
|
const _this = this;
|
2017-12-15 07:57:08 -05:00
|
|
|
return $('a.btn-close, a.btn-reopen').on('click', function(e) {
|
2019-11-18 10:06:27 -05:00
|
|
|
const $this = $(this);
|
|
|
|
const shouldSubmit = $this.hasClass('btn-comment');
|
2017-12-15 07:57:08 -05:00
|
|
|
if (shouldSubmit && $this.data('submitted')) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 06:30:25 -05:00
|
|
|
|
2017-12-15 07:57:08 -05:00
|
|
|
if (this.closeReopenReportToggle) this.closeReopenReportToggle.setDisable();
|
2016-11-28 06:30:25 -05:00
|
|
|
|
2017-12-15 07:57:08 -05:00
|
|
|
if (shouldSubmit) {
|
|
|
|
if ($this.hasClass('btn-comment-and-close') || $this.hasClass('btn-comment-and-reopen')) {
|
2016-11-28 06:30:25 -05:00
|
|
|
e.preventDefault();
|
2017-12-15 07:57:08 -05:00
|
|
|
e.stopImmediatePropagation();
|
2016-11-28 06:30:25 -05:00
|
|
|
|
2017-12-15 07:57:08 -05:00
|
|
|
_this.submitNoteForm($this.closest('form'), $this);
|
2017-09-07 16:25:50 -04:00
|
|
|
}
|
2017-12-15 07:57:08 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.submitNoteForm = function(form, $button) {
|
2019-11-18 10:06:27 -05:00
|
|
|
const noteText = form.find('textarea.js-note-text').val();
|
2017-12-15 07:57:08 -05:00
|
|
|
if (noteText.trim().length > 0) {
|
|
|
|
form.submit();
|
|
|
|
$button.data('submitted', true);
|
|
|
|
return $button.trigger('click');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MergeRequest.prototype.initCommitMessageListeners = function() {
|
2019-09-24 05:06:04 -04:00
|
|
|
$(document).on('click', 'a.js-with-description-link', e => {
|
2019-11-18 10:06:27 -05:00
|
|
|
const textarea = $('textarea.js-commit-message');
|
2017-12-15 07:57:08 -05:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithDescription'));
|
|
|
|
$('.js-with-description-hint').hide();
|
|
|
|
$('.js-without-description-hint').show();
|
|
|
|
});
|
|
|
|
|
2019-09-24 05:06:04 -04:00
|
|
|
$(document).on('click', 'a.js-without-description-link', e => {
|
2019-11-18 10:06:27 -05:00
|
|
|
const textarea = $('textarea.js-commit-message');
|
2017-12-15 07:57:08 -05:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
textarea.val(textarea.data('messageWithoutDescription'));
|
|
|
|
$('.js-with-description-hint').show();
|
|
|
|
$('.js-without-description-hint').hide();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-01-17 09:09:59 -05:00
|
|
|
MergeRequest.setStatusBoxToMerged = function() {
|
2017-12-15 07:57:08 -05:00
|
|
|
$('.detail-page-header .status-box')
|
2018-01-17 09:09:59 -05:00
|
|
|
.removeClass('status-box-open')
|
|
|
|
.addClass('status-box-mr-merged')
|
2017-12-15 07:57:08 -05:00
|
|
|
.find('span')
|
2018-01-17 09:09:59 -05:00
|
|
|
.text(__('Merged'));
|
2017-12-15 07:57:08 -05:00
|
|
|
};
|
|
|
|
|
2018-01-15 12:06:38 -05:00
|
|
|
MergeRequest.decreaseCounter = function(by = 1) {
|
|
|
|
const $el = $('.js-merge-counter');
|
2018-10-10 03:13:34 -04:00
|
|
|
const count = Math.max(parseInt($el.text().replace(/[^\d]/, ''), 10) - by, 0);
|
2017-12-15 07:57:08 -05:00
|
|
|
|
|
|
|
$el.text(addDelimiter(count));
|
|
|
|
};
|
|
|
|
|
2018-01-15 12:06:38 -05:00
|
|
|
MergeRequest.hideCloseButton = function() {
|
2017-12-15 07:57:08 -05:00
|
|
|
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;
|