2017-08-17 22:00:37 +05:30
|
|
|
<script>
|
2021-02-22 17:27:13 +05:30
|
|
|
import { GlDropdown, GlDropdownItem, GlIcon, GlLoadingIcon, GlTooltipDirective } from '@gitlab/ui';
|
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';
|
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-12-13 13:39:08 +05:30
|
|
|
GlLoadingIcon,
|
2018-11-18 11:00:15 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
actions: {
|
|
|
|
type: Array,
|
|
|
|
required: false,
|
|
|
|
default: () => [],
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
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: {
|
2018-12-13 13:39:08 +05:30
|
|
|
onClickAction(action) {
|
|
|
|
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 },
|
|
|
|
);
|
2019-12-04 20:38:33 +05:30
|
|
|
// https://gitlab.com/gitlab-org/gitlab-foss/issues/52156
|
2018-12-13 13:39:08 +05:30
|
|
|
// eslint-disable-next-line no-alert
|
|
|
|
if (!window.confirm(confirmationMessage)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
this.isLoading = true;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
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
|
|
|
|
:title="title"
|
|
|
|
:aria-label="title"
|
|
|
|
:disabled="isLoading"
|
|
|
|
right
|
|
|
|
data-container="body"
|
|
|
|
data-testid="environment-actions-button"
|
|
|
|
>
|
|
|
|
<template #button-content>
|
|
|
|
<gl-icon name="play" />
|
|
|
|
<gl-icon name="chevron-down" />
|
2021-09-30 23:02:18 +05:30
|
|
|
<gl-loading-icon v-if="isLoading" size="sm" />
|
2021-02-22 17:27:13 +05:30
|
|
|
</template>
|
|
|
|
<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>
|