summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/deploy_keys/components/action_btn.vue
blob: 3ff3a9d977e77c13d046805341bcaff503e19ccf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<script>
  import eventHub from '../eventhub';

  export default {
    data() {
      return {
        isLoading: false,
      };
    },
    props: {
      deployKey: {
        type: Object,
        required: true,
      },
      type: {
        type: String,
        required: true,
      },
      btnCssClass: {
        type: String,
        required: false,
        default: 'btn-default',
      },
    },
    methods: {
      doAction() {
        this.isLoading = true;

        eventHub.$emit(`${this.type}.key`, this.deployKey);
      },
    },
    computed: {
      text() {
        return `${this.type.charAt(0).toUpperCase()}${this.type.slice(1)}`;
      },
    },
  };
</script>

<template>
  <button
    class="btn btn-sm prepend-left-10"
    :class="[{ disabled: isLoading }, btnCssClass]"
    :disabled="isLoading"
    @click="doAction">
    {{ text }}
    <i
      v-if="isLoading"
      class="fa fa-spinner fa-spin"
      aria-hidden="true"
      aria-label="Loading">
    </i>
  </button>
</template>