2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { joinPaths } from '~/lib/utils/url_utility';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2022-01-26 12:08:38 +05:30
|
|
|
import { EVENT_ISSUABLE_VUE_APP_CHANGE } from '~/issuable/constants';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { addDelimiter } from '~/lib/utils/text_utility';
|
|
|
|
import { __ } from '~/locale';
|
2022-03-02 08:16:31 +05:30
|
|
|
import CreateMergeRequestDropdown from './create_merge_request_dropdown';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
export default class Issue {
|
2017-08-17 22:00:37 +05:30
|
|
|
constructor() {
|
2020-06-23 00:09:42 +05:30
|
|
|
if ($('.js-alert-moved-from-service-desk-warning').length) {
|
2021-02-22 17:27:13 +05:30
|
|
|
Issue.initIssueMovedFromServiceDeskDismissHandler();
|
2020-06-23 00:09:42 +05:30
|
|
|
}
|
|
|
|
|
2019-04-03 18:18:56 +05:30
|
|
|
if (document.querySelector('#related-branches')) {
|
|
|
|
Issue.initRelatedBranches();
|
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
Issue.createMrDropdownWrap = document.querySelector('.create-mr-dropdown-wrap');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if (Issue.createMrDropdownWrap) {
|
|
|
|
this.createMergeRequestDropdown = new CreateMergeRequestDropdown(Issue.createMrDropdownWrap);
|
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
// Listen to state changes in the Vue app
|
2021-04-17 20:07:23 +05:30
|
|
|
this.issuableVueAppChangeHandler = (event) =>
|
2018-03-27 19:54:05 +05:30
|
|
|
this.updateTopState(event.detail.isClosed, event.detail.data);
|
2021-04-17 20:07:23 +05:30
|
|
|
document.addEventListener(EVENT_ISSUABLE_VUE_APP_CHANGE, this.issuableVueAppChangeHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose() {
|
|
|
|
document.removeEventListener(EVENT_ISSUABLE_VUE_APP_CHANGE, this.issuableVueAppChangeHandler);
|
2018-03-27 19:54:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method updates the top area of the issue.
|
|
|
|
*
|
|
|
|
* Once the issue state changes, either through a click on the top area (jquery)
|
|
|
|
* or a click on the bottom area (Vue) we need to update the top area.
|
|
|
|
*
|
|
|
|
* @param {Boolean} isClosed
|
|
|
|
* @param {Array} data
|
|
|
|
* @param {String} issueFailMessage
|
|
|
|
*/
|
2019-09-04 21:01:54 +05:30
|
|
|
updateTopState(
|
|
|
|
isClosed,
|
|
|
|
data,
|
|
|
|
issueFailMessage = __('Unable to update this issue at this time.'),
|
|
|
|
) {
|
2018-03-27 19:54:05 +05:30
|
|
|
if ('id' in data) {
|
2022-07-16 23:28:13 +05:30
|
|
|
const isClosedBadge = $('.issuable-status-badge-closed');
|
|
|
|
const isOpenBadge = $('.issuable-status-badge-open');
|
2018-03-27 19:54:05 +05:30
|
|
|
const projectIssuesCounter = $('.issue_counter');
|
|
|
|
|
|
|
|
isClosedBadge.toggleClass('hidden', !isClosed);
|
|
|
|
isOpenBadge.toggleClass('hidden', isClosed);
|
|
|
|
|
|
|
|
$(document).trigger('issuable:change', isClosed);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
let numProjectIssues = Number(
|
2021-03-08 18:12:59 +05:30
|
|
|
projectIssuesCounter.first().text().trim().replace(/[^\d]/, ''),
|
2018-12-13 13:39:08 +05:30
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
numProjectIssues = isClosed ? numProjectIssues - 1 : numProjectIssues + 1;
|
|
|
|
projectIssuesCounter.text(addDelimiter(numProjectIssues));
|
|
|
|
|
|
|
|
if (this.createMergeRequestDropdown) {
|
2021-01-29 00:20:46 +05:30
|
|
|
this.createMergeRequestDropdown.checkAbilityToCreateBranch();
|
2018-03-27 19:54:05 +05:30
|
|
|
}
|
|
|
|
} else {
|
2023-03-04 22:38:38 +05:30
|
|
|
createAlert({
|
2021-09-30 23:02:18 +05:30
|
|
|
message: issueFailMessage,
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
static initIssueMovedFromServiceDeskDismissHandler() {
|
|
|
|
const alertMovedFromServiceDeskWarning = $('.js-alert-moved-from-service-desk-warning');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const trimmedPathname = window.location.pathname.slice(1);
|
|
|
|
const alertMovedFromServiceDeskDismissedKey = joinPaths(
|
|
|
|
trimmedPathname,
|
|
|
|
'alert-issue-moved-from-service-desk-dismissed',
|
2020-11-24 15:15:51 +05:30
|
|
|
);
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
if (!localStorage.getItem(alertMovedFromServiceDeskDismissedKey)) {
|
2020-06-23 00:09:42 +05:30
|
|
|
alertMovedFromServiceDeskWarning.show();
|
|
|
|
}
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
alertMovedFromServiceDeskWarning.on('click', '.js-close', (e) => {
|
2020-06-23 00:09:42 +05:30
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
alertMovedFromServiceDeskWarning.remove();
|
2021-02-22 17:27:13 +05:30
|
|
|
localStorage.setItem(alertMovedFromServiceDeskDismissedKey, true);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
static initRelatedBranches() {
|
2019-12-26 22:10:19 +05:30
|
|
|
const $container = $('#related-branches');
|
2021-02-22 17:27:13 +05:30
|
|
|
axios
|
2018-12-13 13:39:08 +05:30
|
|
|
.get($container.data('url'))
|
2018-03-17 18:26:18 +05:30
|
|
|
.then(({ data }) => {
|
|
|
|
if ('html' in data) {
|
|
|
|
$container.html(data.html);
|
|
|
|
}
|
2018-12-13 13:39:08 +05:30
|
|
|
})
|
2021-09-30 23:02:18 +05:30
|
|
|
.catch(() =>
|
2023-03-04 22:38:38 +05:30
|
|
|
createAlert({
|
2021-09-30 23:02:18 +05:30
|
|
|
message: __('Failed to load related branches'),
|
|
|
|
}),
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|