github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/web/src/components/HookButton.vue (about)

     1  <template>
     2    <v-btn :loading="loading" color="accent" small @click="activate">
     3      <v-icon class="mr-1">{{icon}}</v-icon>activate
     4    </v-btn>
     5  </template>
     6  
     7  <script lang="ts">
     8  import { Component } from 'vue-property-decorator';
     9  import Vue from '@/vue';
    10  
    11  @Component({
    12    name: 'hook-button'
    13  })
    14  export default class HookButton extends Vue {
    15    private loading = false;
    16    private icon = '';
    17  
    18    get repo(): Repository | undefined {
    19      return this.$store.state.repository.current;
    20    }
    21  
    22    activate() {
    23      const base = this.$store.state.base;
    24      if (this.repo) {
    25        this.loading = true;
    26        const { NameSpace: space, Name: name, SCM: scm } = this.repo;
    27        this.$http
    28          .post(`${base}/api/v1/repos/${scm}/${space}/${name}/hook/create`)
    29          .then(() => {
    30            this.icon = 'mdi-check';
    31          })
    32          .catch(() => {
    33            this.icon = 'mdi-close';
    34          })
    35          .finally(() => {
    36            this.loading = false;
    37            setTimeout(() => {
    38              this.icon = '';
    39            }, 5000);
    40          });
    41      }
    42    }
    43  }
    44  </script>