debian-mirror-gitlab/app/assets/javascripts/pipelines/components/pipelines_list/pipelines_actions.vue

115 lines
3.2 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { GlTooltipDirective, GlButton, GlLoadingIcon, GlIcon } from '@gitlab/ui';
2019-10-12 21:52:04 +05:30
import axios from '~/lib/utils/axios_utils';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as flash } from '~/flash';
2019-10-12 21:52:04 +05:30
import { s__, __, sprintf } from '~/locale';
2019-02-15 15:39:39 +05:30
import GlCountdown from '~/vue_shared/components/gl_countdown.vue';
2020-07-28 23:09:34 +05:30
import eventHub from '../../event_hub';
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
export default {
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2018-11-08 19:23:39 +05:30
},
components: {
2020-11-24 15:15:51 +05:30
GlIcon,
2018-12-13 13:39:08 +05:30
GlCountdown,
2020-11-24 15:15:51 +05:30
GlButton,
2018-12-13 13:39:08 +05:30
GlLoadingIcon,
2018-11-08 19:23:39 +05:30
},
props: {
actions: {
type: Array,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
},
data() {
return {
isLoading: false,
};
},
methods: {
2018-12-05 23:21:45 +05:30
onClickAction(action) {
if (action.scheduled_at) {
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-05 23:21:45 +05:30
),
{ jobName: action.name },
);
2019-12-04 20:38:33 +05:30
// https://gitlab.com/gitlab-org/gitlab-foss/issues/52156
2018-12-05 23:21:45 +05:30
// eslint-disable-next-line no-alert
if (!window.confirm(confirmationMessage)) {
return;
}
}
2018-11-08 19:23:39 +05:30
this.isLoading = true;
2017-09-10 17:25:29 +05:30
2019-10-12 21:52:04 +05:30
/**
* Ideally, the component would not make an api call directly.
* However, in order to use the eventhub and know when to
* toggle back the `isLoading` property we'd need an ID
* to track the request with a wacther - since this component
* is rendered at least 20 times in the same page, moving the
* api call directly here is the most performant solution
*/
axios
.post(`${action.path}.json`)
.then(() => {
this.isLoading = false;
eventHub.$emit('updateTable');
})
.catch(() => {
this.isLoading = false;
flash(__('An error occurred while making the request.'));
});
2018-11-08 19:23:39 +05:30
},
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
isActionDisabled(action) {
if (action.playable === undefined) {
return false;
}
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
return !action.playable;
2017-09-10 17:25:29 +05:30
},
2018-11-08 19:23:39 +05:30
},
};
2017-09-10 17:25:29 +05:30
</script>
<template>
<div class="btn-group">
2019-07-07 11:18:12 +05:30
<button
2019-02-15 15:39:39 +05:30
v-gl-tooltip
2019-07-07 11:18:12 +05:30
type="button"
2018-11-08 19:23:39 +05:30
:disabled="isLoading"
2017-09-10 17:25:29 +05:30
class="dropdown-new btn btn-default js-pipeline-dropdown-manual-actions"
2020-11-24 15:15:51 +05:30
:title="__('Run manual or delayed jobs')"
2017-09-10 17:25:29 +05:30
data-toggle="dropdown"
2020-11-24 15:15:51 +05:30
:aria-label="__('Run manual or delayed jobs')"
2018-03-17 18:26:18 +05:30
>
2020-11-24 15:15:51 +05:30
<gl-icon name="play" class="icon-play" />
2021-01-29 00:20:46 +05:30
<gl-icon name="chevron-down" />
2018-12-05 23:21:45 +05:30
<gl-loading-icon v-if="isLoading" />
2019-07-07 11:18:12 +05:30
</button>
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
<ul class="dropdown-menu dropdown-menu-right">
2019-02-15 15:39:39 +05:30
<li v-for="action in actions" :key="action.path">
2020-11-24 15:15:51 +05:30
<gl-button
category="tertiary"
2018-11-08 19:23:39 +05:30
:class="{ disabled: isActionDisabled(action) }"
:disabled="isActionDisabled(action)"
2020-11-24 15:15:51 +05:30
class="js-pipeline-action-link"
2019-03-02 22:35:43 +05:30
@click="onClickAction(action)"
2018-03-17 18:26:18 +05:30
>
2020-11-24 15:15:51 +05:30
<div class="d-flex justify-content-between flex-wrap">
{{ action.name }}
<span v-if="action.scheduled_at">
<gl-icon name="clock" />
<gl-countdown :end-date-string="action.scheduled_at" />
</span>
</div>
</gl-button>
2017-09-10 17:25:29 +05:30
</li>
</ul>
</div>
</template>