2017-04-21 11:16:22 -04:00
|
|
|
<script>
|
2020-11-18 01:09:29 -05:00
|
|
|
import { GlDropdown, GlDropdownItem, GlIcon, GlLoadingIcon, GlTooltipDirective } from '@gitlab/ui';
|
2018-10-08 09:06:00 -04:00
|
|
|
import { formatTime } from '~/lib/utils/datetime_utility';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { __, s__, sprintf } from '~/locale';
|
2018-07-10 04:11:04 -04:00
|
|
|
import eventHub from '../event_hub';
|
2017-04-21 11:16:22 -04:00
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
export default {
|
|
|
|
directives: {
|
2020-10-12 05:08:38 -04:00
|
|
|
GlTooltip: GlTooltipDirective,
|
2018-07-10 04:11:04 -04:00
|
|
|
},
|
|
|
|
components: {
|
2020-11-18 01:09:29 -05:00
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
2020-08-24 11:10:11 -04:00
|
|
|
GlIcon,
|
2018-11-07 05:06:15 -05:00
|
|
|
GlLoadingIcon,
|
2018-07-10 04:11:04 -04:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
actions: {
|
|
|
|
type: Array,
|
|
|
|
required: false,
|
|
|
|
default: () => [],
|
2017-04-21 11:16:22 -04:00
|
|
|
},
|
2018-07-10 04:11:04 -04:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
title() {
|
2019-07-01 16:24:59 -04:00
|
|
|
return __('Deploy to...');
|
2018-01-05 09:31:01 -05:00
|
|
|
},
|
2018-07-10 04:11:04 -04:00
|
|
|
},
|
|
|
|
methods: {
|
2018-10-08 09:06:00 -04:00
|
|
|
onClickAction(action) {
|
|
|
|
if (action.scheduledAt) {
|
2018-10-15 06:27:59 -04:00
|
|
|
const confirmationMessage = sprintf(
|
|
|
|
s__(
|
2020-11-18 01:09:29 -05:00
|
|
|
'DelayedJobs|Are you sure you want to run %{jobName} immediately? Otherwise this job will run automatically after its timer finishes.',
|
2018-10-15 06:27:59 -04:00
|
|
|
),
|
|
|
|
{ jobName: action.name },
|
|
|
|
);
|
2019-09-18 10:02:45 -04:00
|
|
|
// https://gitlab.com/gitlab-org/gitlab-foss/issues/52156
|
2018-10-08 09:06:00 -04:00
|
|
|
// eslint-disable-next-line no-alert
|
|
|
|
if (!window.confirm(confirmationMessage)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
this.isLoading = true;
|
2017-04-21 11:16:22 -04:00
|
|
|
|
2018-10-08 09:06:00 -04:00
|
|
|
eventHub.$emit('postAction', { endpoint: action.playPath });
|
2018-07-10 04:11:04 -04:00
|
|
|
},
|
2017-04-21 11:16:22 -04:00
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
isActionDisabled(action) {
|
|
|
|
if (action.playable === undefined) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-21 11:16:22 -04:00
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
return !action.playable;
|
2017-04-21 11:16:22 -04:00
|
|
|
},
|
2018-10-08 09:06:00 -04:00
|
|
|
|
|
|
|
remainingTime(action) {
|
|
|
|
const remainingMilliseconds = new Date(action.scheduledAt).getTime() - Date.now();
|
|
|
|
return formatTime(Math.max(0, remainingMilliseconds));
|
|
|
|
},
|
2018-07-10 04:11:04 -04:00
|
|
|
},
|
|
|
|
};
|
2017-04-21 11:16:22 -04:00
|
|
|
</script>
|
|
|
|
<template>
|
2020-11-18 01:09:29 -05:00
|
|
|
<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" />
|
|
|
|
<gl-loading-icon v-if="isLoading" />
|
|
|
|
</template>
|
|
|
|
<gl-dropdown-item
|
|
|
|
v-for="(action, i) in actions"
|
|
|
|
:key="i"
|
|
|
|
:disabled="isActionDisabled(action)"
|
|
|
|
data-testid="manual-action-link"
|
|
|
|
@click="onClickAction(action)"
|
2018-01-05 09:31:01 -05:00
|
|
|
>
|
2020-11-18 01:09:29 -05:00
|
|
|
<span class="gl-flex-fill-1">{{ action.name }}</span>
|
|
|
|
<span v-if="action.scheduledAt" class="gl-text-gray-500 float-right">
|
|
|
|
<gl-icon name="clock" />
|
|
|
|
{{ remainingTime(action) }}
|
2017-04-21 11:16:22 -04:00
|
|
|
</span>
|
2020-11-18 01:09:29 -05:00
|
|
|
</gl-dropdown-item>
|
|
|
|
</gl-dropdown>
|
2017-04-21 11:16:22 -04:00
|
|
|
</template>
|