2017-08-17 22:00:37 +05:30
|
|
|
<script>
|
2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-10-15 14:42:47 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { dasherize } from '~/lib/utils/text_utility';
|
|
|
|
import { __ } from '~/locale';
|
|
|
|
import createFlash from '~/flash';
|
|
|
|
import tooltip from '~/vue_shared/directives/tooltip';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
/**
|
2018-10-15 14:42:47 +05:30
|
|
|
* Renders either a cancel, retry or play icon button and handles the post request
|
|
|
|
*
|
|
|
|
* Used in:
|
|
|
|
* - mr widget mini pipeline graph: `mr_widget_pipeline.vue`
|
|
|
|
* - pipelines table
|
|
|
|
* - pipelines table in merge request page
|
|
|
|
* - pipelines table in commit page
|
2018-11-08 19:23:39 +05:30
|
|
|
* - pipelines detail page in big graph
|
2018-05-09 12:01:36 +05:30
|
|
|
*/
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Icon,
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
directives: {
|
|
|
|
tooltip,
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
props: {
|
|
|
|
tooltipText: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
link: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
actionIcon: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isDisabled: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
computed: {
|
|
|
|
cssClass() {
|
|
|
|
const actionIconDash = dasherize(this.actionIcon);
|
|
|
|
return `${actionIconDash} js-icon-${actionIconDash}`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2018-10-15 14:42:47 +05:30
|
|
|
/**
|
|
|
|
* The request should not be handled here.
|
|
|
|
* However due to this component being used in several
|
|
|
|
* different apps it avoids repetition & complexity.
|
|
|
|
*
|
|
|
|
*/
|
2018-05-09 12:01:36 +05:30
|
|
|
onClickAction() {
|
|
|
|
$(this.$el).tooltip('hide');
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
this.isDisabled = true;
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
axios
|
|
|
|
.post(`${this.link}.json`)
|
2018-10-15 14:42:47 +05:30
|
|
|
.then(() => {
|
|
|
|
this.isDisabled = false;
|
|
|
|
this.$emit('pipelineActionRequestComplete');
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.isDisabled = false;
|
|
|
|
|
|
|
|
createFlash(__('An error occurred while making the request.'));
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
</script>
|
|
|
|
<template>
|
2018-05-09 12:01:36 +05:30
|
|
|
<button
|
2017-09-10 17:25:29 +05:30
|
|
|
v-tooltip
|
2017-08-17 22:00:37 +05:30
|
|
|
:title="tooltipText"
|
2018-11-08 19:23:39 +05:30
|
|
|
:class="cssClass"
|
|
|
|
:disabled="isDisabled"
|
|
|
|
type="button"
|
2018-10-15 14:42:47 +05:30
|
|
|
class="js-ci-action btn btn-blank
|
|
|
|
btn-transparent ci-action-icon-container ci-action-icon-wrapper"
|
2018-03-17 18:26:18 +05:30
|
|
|
data-container="body"
|
2018-11-08 19:23:39 +05:30
|
|
|
data-boundary="viewport"
|
|
|
|
@click="onClickAction"
|
2018-03-17 18:26:18 +05:30
|
|
|
>
|
2018-10-15 14:42:47 +05:30
|
|
|
<icon :name="actionIcon"/>
|
2018-05-09 12:01:36 +05:30
|
|
|
</button>
|
2017-08-17 22:00:37 +05:30
|
|
|
</template>
|