debian-mirror-gitlab/app/assets/javascripts/milestones/components/delete_milestone_modal.vue

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

129 lines
3.4 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2022-08-13 15:12:31 +05:30
import { GlSprintf, GlModal } from '@gitlab/ui';
import { createAlert } from '~/flash';
2018-12-13 13:39:08 +05:30
import axios from '~/lib/utils/axios_utils';
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
import { redirectTo } from '~/lib/utils/url_utility';
2021-03-11 19:13:27 +05:30
import { __, n__, s__, sprintf } from '~/locale';
2018-12-13 13:39:08 +05:30
import eventHub from '../event_hub';
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
export default {
components: {
2021-01-03 14:25:43 +05:30
GlModal,
2022-08-13 15:12:31 +05:30
GlSprintf,
2020-11-24 15:15:51 +05:30
},
2018-12-13 13:39:08 +05:30
props: {
issueCount: {
type: Number,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
mergeRequestCount: {
type: Number,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
milestoneId: {
type: Number,
required: true,
},
milestoneTitle: {
type: String,
required: true,
},
milestoneUrl: {
type: String,
required: true,
},
},
computed: {
text() {
if (this.issueCount === 0 && this.mergeRequestCount === 0) {
2022-08-13 15:12:31 +05:30
return s__(`Milestones|
2018-12-13 13:39:08 +05:30
Youre about to permanently delete the milestone %{milestoneTitle}.
2022-08-13 15:12:31 +05:30
This milestone is not currently used in any issues or merge requests.`);
2018-12-13 13:39:08 +05:30
}
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
return sprintf(
s__(`Milestones|
Youre about to permanently delete the milestone %{milestoneTitle} and remove it from %{issuesWithCount} and %{mergeRequestsWithCount}.
Once deleted, it cannot be undone or recovered.`),
{
issuesWithCount: n__('%d issue', '%d issues', this.issueCount),
mergeRequestsWithCount: n__(
'%d merge request',
'%d merge requests',
this.mergeRequestCount,
),
},
false,
);
},
title() {
return sprintf(s__('Milestones|Delete milestone %{milestoneTitle}?'), {
milestoneTitle: this.milestoneTitle,
});
},
},
methods: {
onSubmit() {
eventHub.$emit('deleteMilestoneModal.requestStarted', this.milestoneUrl);
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
return axios
.delete(this.milestoneUrl)
2021-03-08 18:12:59 +05:30
.then((response) => {
2018-12-13 13:39:08 +05:30
eventHub.$emit('deleteMilestoneModal.requestFinished', {
milestoneUrl: this.milestoneUrl,
successful: true,
});
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
// follow the rediect to milestones overview page
redirectTo(response.request.responseURL);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2018-12-13 13:39:08 +05:30
eventHub.$emit('deleteMilestoneModal.requestFinished', {
milestoneUrl: this.milestoneUrl,
successful: false,
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
if (error.response && error.response.status === 404) {
2022-08-13 15:12:31 +05:30
createAlert({
2021-09-30 23:02:18 +05:30
message: sprintf(s__('Milestones|Milestone %{milestoneTitle} was not found'), {
2018-12-13 13:39:08 +05:30
milestoneTitle: this.milestoneTitle,
}),
2021-09-30 23:02:18 +05:30
});
2018-12-13 13:39:08 +05:30
} else {
2022-08-13 15:12:31 +05:30
createAlert({
2021-09-30 23:02:18 +05:30
message: sprintf(s__('Milestones|Failed to delete milestone %{milestoneTitle}'), {
2018-12-13 13:39:08 +05:30
milestoneTitle: this.milestoneTitle,
}),
2021-09-30 23:02:18 +05:30
});
2018-12-13 13:39:08 +05:30
}
throw error;
});
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
},
2021-01-03 14:25:43 +05:30
primaryProps: {
text: s__('Milestones|Delete milestone'),
attributes: [{ variant: 'danger' }, { category: 'primary' }],
},
cancelProps: {
text: __('Cancel'),
},
2018-12-13 13:39:08 +05:30
};
2018-03-17 18:26:18 +05:30
</script>
<template>
2021-01-03 14:25:43 +05:30
<gl-modal
modal-id="delete-milestone-modal"
2018-03-17 18:26:18 +05:30
:title="title"
2021-01-03 14:25:43 +05:30
:action-primary="$options.primaryProps"
:action-cancel="$options.cancelProps"
@primary="onSubmit"
2019-02-15 15:39:39 +05:30
>
2022-08-13 15:12:31 +05:30
<gl-sprintf :message="text">
<template #milestoneTitle>
<strong>{{ milestoneTitle }}</strong>
</template>
</gl-sprintf>
2021-01-03 14:25:43 +05:30
</gl-modal>
2018-03-17 18:26:18 +05:30
</template>