debian-mirror-gitlab/app/assets/javascripts/environments/components/environment_actions.vue

109 lines
2.6 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2022-03-02 08:16:31 +05:30
import { GlDropdown, GlDropdownItem, GlIcon, GlTooltipDirective } from '@gitlab/ui';
2022-05-07 20:08:51 +05:30
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
2018-12-13 13:39:08 +05:30
import { formatTime } from '~/lib/utils/datetime_utility';
2021-03-11 19:13:27 +05:30
import { __, s__, sprintf } from '~/locale';
2018-11-18 11:00:15 +05:30
import eventHub from '../event_hub';
2022-03-02 08:16:31 +05:30
import actionMutation from '../graphql/mutations/action.mutation.graphql';
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
export default {
directives: {
2021-01-03 14:25:43 +05:30
GlTooltip: GlTooltipDirective,
2018-11-18 11:00:15 +05:30
},
components: {
2021-02-22 17:27:13 +05:30
GlDropdown,
GlDropdownItem,
2020-11-24 15:15:51 +05:30
GlIcon,
2018-11-18 11:00:15 +05:30
},
props: {
actions: {
type: Array,
required: false,
default: () => [],
2017-08-17 22:00:37 +05:30
},
2022-03-02 08:16:31 +05:30
graphql: {
type: Boolean,
required: false,
default: false,
},
2018-11-18 11:00:15 +05:30
},
data() {
return {
isLoading: false,
};
},
computed: {
title() {
2019-09-30 21:07:59 +05:30
return __('Deploy to...');
2018-03-17 18:26:18 +05:30
},
2018-11-18 11:00:15 +05:30
},
methods: {
2022-05-07 20:08:51 +05:30
async onClickAction(action) {
2018-12-13 13:39:08 +05:30
if (action.scheduledAt) {
const confirmationMessage = sprintf(
s__(
2021-02-22 17:27:13 +05:30
'DelayedJobs|Are you sure you want to run %{jobName} immediately? Otherwise this job will run automatically after its timer finishes.',
2018-12-13 13:39:08 +05:30
),
{ jobName: action.name },
);
2022-05-07 20:08:51 +05:30
const confirmed = await confirmAction(confirmationMessage);
if (!confirmed) {
2018-12-13 13:39:08 +05:30
return;
}
}
2018-11-18 11:00:15 +05:30
this.isLoading = true;
2017-08-17 22:00:37 +05:30
2022-03-02 08:16:31 +05:30
if (this.graphql) {
this.$apollo.mutate({ mutation: actionMutation, variables: { action } });
} else {
eventHub.$emit('postAction', { endpoint: action.playPath });
}
2018-11-18 11:00:15 +05:30
},
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
isActionDisabled(action) {
if (action.playable === undefined) {
return false;
}
2017-08-17 22:00:37 +05:30
2018-11-18 11:00:15 +05:30
return !action.playable;
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
remainingTime(action) {
const remainingMilliseconds = new Date(action.scheduledAt).getTime() - Date.now();
return formatTime(Math.max(0, remainingMilliseconds));
},
2018-11-18 11:00:15 +05:30
},
};
2017-08-17 22:00:37 +05:30
</script>
<template>
2021-02-22 17:27:13 +05:30
<gl-dropdown
v-gl-tooltip
2022-03-02 08:16:31 +05:30
:text="title"
2021-02-22 17:27:13 +05:30
:title="title"
2022-03-02 08:16:31 +05:30
:loading="isLoading"
2021-02-22 17:27:13 +05:30
:aria-label="title"
2022-03-02 08:16:31 +05:30
icon="play"
text-sr-only
2021-02-22 17:27:13 +05:30
right
data-container="body"
data-testid="environment-actions-button"
>
<gl-dropdown-item
v-for="(action, i) in actions"
:key="i"
:disabled="isActionDisabled(action)"
data-testid="manual-action-link"
@click="onClickAction(action)"
2018-03-17 18:26:18 +05:30
>
2021-09-04 01:27:46 +05:30
<span class="gl-flex-grow-1">{{ action.name }}</span>
2021-02-22 17:27:13 +05:30
<span v-if="action.scheduledAt" class="gl-text-gray-500 float-right">
<gl-icon name="clock" />
{{ remainingTime(action) }}
2017-08-17 22:00:37 +05:30
</span>
2021-02-22 17:27:13 +05:30
</gl-dropdown-item>
</gl-dropdown>
2017-08-17 22:00:37 +05:30
</template>