2018-03-17 18:26:18 +05:30
|
|
|
|
<script>
|
2022-08-13 15:12:31 +05:30
|
|
|
|
import { GlSprintf, GlModal } from '@gitlab/ui';
|
2023-05-27 22:25:52 +05:30
|
|
|
|
import { createAlert } from '~/alert';
|
2018-12-13 13:39:08 +05:30
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2023-04-23 21:23:45 +05:30
|
|
|
|
import { HTTP_STATUS_NOT_FOUND } from '~/lib/utils/http_status';
|
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
|
|
|
|
You’re 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|
|
|
|
|
|
You’re 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
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
|
if (error.response && error.response.status === HTTP_STATUS_NOT_FOUND) {
|
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'),
|
2023-05-27 22:25:52 +05:30
|
|
|
|
attributes: { variant: 'danger', category: 'primary' },
|
2021-01-03 14:25:43 +05:30
|
|
|
|
},
|
|
|
|
|
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>
|