debian-mirror-gitlab/app/assets/javascripts/milestones/index.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
3.9 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import $ from 'jquery';
2018-03-27 19:54:05 +05:30
import Vue from 'vue';
2022-01-26 12:08:38 +05:30
import initDatePicker from '~/behaviors/date_picker';
import GLForm from '~/gl_form';
2021-03-11 19:13:27 +05:30
import { BV_SHOW_MODAL } from '~/lib/utils/constants';
2022-01-26 12:08:38 +05:30
import Milestone from '~/milestones/milestone';
2023-07-09 08:55:56 +05:30
import { renderGFM } from '~/behaviors/markdown/render_gfm';
2022-01-26 12:08:38 +05:30
import Sidebar from '~/right_sidebar';
import MountMilestoneSidebar from '~/sidebar/mount_milestone_sidebar';
2018-03-27 19:54:05 +05:30
import Translate from '~/vue_shared/translate';
2022-01-26 12:08:38 +05:30
import ZenMode from '~/zen_mode';
2021-01-03 14:25:43 +05:30
import DeleteMilestoneModal from './components/delete_milestone_modal.vue';
2022-01-26 12:08:38 +05:30
import PromoteMilestoneModal from './components/promote_milestone_modal.vue';
2018-03-27 19:54:05 +05:30
import eventHub from './event_hub';
2023-07-09 08:55:56 +05:30
// See app/views/shared/milestones/_description.html.haml
export const MILESTONE_DESCRIPTION_ELEMENT = '.milestone-detail .description';
2022-01-26 12:08:38 +05:30
export function initForm(initGFM = true) {
new ZenMode(); // eslint-disable-line no-new
initDatePicker();
// eslint-disable-next-line no-new
new GLForm($('.milestone-form'), {
emojis: true,
members: initGFM,
issues: initGFM,
mergeRequests: initGFM,
epics: initGFM,
milestones: initGFM,
labels: initGFM,
snippets: initGFM,
vulnerabilities: initGFM,
});
}
export function initShow() {
new Milestone(); // eslint-disable-line no-new
new Sidebar(); // eslint-disable-line no-new
new MountMilestoneSidebar(); // eslint-disable-line no-new
2023-07-09 08:55:56 +05:30
renderGFM(document.querySelector(MILESTONE_DESCRIPTION_ELEMENT));
2022-01-26 12:08:38 +05:30
}
export function initPromoteMilestoneModal() {
Vue.use(Translate);
const promoteMilestoneModal = document.getElementById('promote-milestone-modal');
if (!promoteMilestoneModal) {
return null;
}
return new Vue({
el: promoteMilestoneModal,
2022-04-04 11:22:00 +05:30
name: 'PromoteMilestoneModalRoot',
2022-01-26 12:08:38 +05:30
render(createElement) {
return createElement(PromoteMilestoneModal);
},
});
}
export function initDeleteMilestoneModal() {
2018-03-27 19:54:05 +05:30
Vue.use(Translate);
const onRequestFinished = ({ milestoneUrl, successful }) => {
2018-12-13 13:39:08 +05:30
const button = document.querySelector(
`.js-delete-milestone-button[data-milestone-url="${milestoneUrl}"]`,
);
2018-03-27 19:54:05 +05:30
if (!successful) {
button.removeAttribute('disabled');
}
};
2021-01-03 14:25:43 +05:30
const deleteMilestoneButtons = document.querySelectorAll('.js-delete-milestone-button');
2021-03-08 18:12:59 +05:30
const onRequestStarted = (milestoneUrl) => {
2018-12-13 13:39:08 +05:30
const button = document.querySelector(
`.js-delete-milestone-button[data-milestone-url="${milestoneUrl}"]`,
);
2018-03-27 19:54:05 +05:30
button.setAttribute('disabled', '');
eventHub.$once('deleteMilestoneModal.requestFinished', onRequestFinished);
};
return new Vue({
2021-01-03 14:25:43 +05:30
el: '#js-delete-milestone-modal',
2022-04-04 11:22:00 +05:30
name: 'DeleteMilestoneModalRoot',
2018-03-27 19:54:05 +05:30
data() {
return {
modalProps: {
milestoneId: -1,
milestoneTitle: '',
milestoneUrl: '',
issueCount: -1,
mergeRequestCount: -1,
},
};
},
mounted() {
eventHub.$on('deleteMilestoneModal.props', this.setModalProps);
2021-03-08 18:12:59 +05:30
deleteMilestoneButtons.forEach((button) => {
2021-01-03 14:25:43 +05:30
button.removeAttribute('disabled');
button.addEventListener('click', () => {
2021-03-11 19:13:27 +05:30
this.$root.$emit(BV_SHOW_MODAL, 'delete-milestone-modal');
2021-01-03 14:25:43 +05:30
eventHub.$once('deleteMilestoneModal.requestStarted', onRequestStarted);
this.setModalProps({
milestoneId: parseInt(button.dataset.milestoneId, 10),
milestoneTitle: button.dataset.milestoneTitle,
milestoneUrl: button.dataset.milestoneUrl,
issueCount: parseInt(button.dataset.milestoneIssueCount, 10),
mergeRequestCount: parseInt(button.dataset.milestoneMergeRequestCount, 10),
});
});
});
2018-03-27 19:54:05 +05:30
},
methods: {
setModalProps(modalProps) {
this.modalProps = modalProps;
},
},
render(createElement) {
2021-01-03 14:25:43 +05:30
return createElement(DeleteMilestoneModal, {
2018-03-27 19:54:05 +05:30
props: this.modalProps,
});
},
});
2022-01-26 12:08:38 +05:30
}