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

96 lines
2 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2018-03-17 18:26:18 +05:30
/* eslint-disable no-alert */
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
import eventHub from '../event_hub';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import icon from '../../vue_shared/components/icon.vue';
import tooltip from '../../vue_shared/directives/tooltip';
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
export default {
directives: {
tooltip,
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
components: {
loadingIcon,
icon,
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
props: {
endpoint: {
type: String,
required: true,
},
title: {
type: String,
required: true,
},
icon: {
type: String,
required: true,
},
cssClass: {
type: String,
required: true,
},
2018-03-27 19:54:05 +05:30
pipelineId: {
2018-03-17 18:26:18 +05:30
type: Number,
required: true,
},
2018-03-27 19:54:05 +05:30
type: {
type: String,
required: true,
},
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
data() {
return {
isLoading: false,
};
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
computed: {
buttonClass() {
return `btn ${this.cssClass}`;
},
2017-08-17 22:00:37 +05:30
},
2018-03-27 19:54:05 +05:30
created() {
// We're using eventHub to listen to the modal here instead of
// using props because it would would make the parent components
// much more complex to keep track of the loading state of each button
eventHub.$on('postAction', this.setLoading);
},
beforeDestroy() {
eventHub.$off('postAction', this.setLoading);
},
2018-03-17 18:26:18 +05:30
methods: {
onClick() {
2018-03-27 19:54:05 +05:30
eventHub.$emit('openConfirmationModal', {
pipelineId: this.pipelineId,
endpoint: this.endpoint,
type: this.type,
2018-03-17 18:26:18 +05:30
});
},
2018-03-27 19:54:05 +05:30
setLoading(endpoint) {
if (endpoint === this.endpoint) {
this.isLoading = true;
}
2018-03-17 18:26:18 +05:30
},
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
};
2017-08-17 22:00:37 +05:30
</script>
<template>
<button
2017-09-10 17:25:29 +05:30
v-tooltip
2017-08-17 22:00:37 +05:30
type="button"
@click="onClick"
:class="buttonClass"
:title="title"
:aria-label="title"
data-container="body"
data-placement="top"
:disabled="isLoading">
2018-03-17 18:26:18 +05:30
<icon
:name="icon"
/>
2017-09-10 17:25:29 +05:30
<loading-icon v-if="isLoading" />
2017-08-17 22:00:37 +05:30
</button>
</template>