Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deployment_stop_button.vue « deployment « components « vue_merge_request_widget « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 29e38648573555cdb6fb471704d4ac7f80926231 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<script>
import { __ } from '~/locale';
import { GlTooltipDirective } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import LoadingButton from '~/vue_shared/components/loading_button.vue';
import { visitUrl } from '~/lib/utils/url_utility';
import createFlash from '~/flash';
import MRWidgetService from '../../services/mr_widget_service';

export default {
  name: 'DeploymentStopButton',
  components: {
    LoadingButton,
    Icon,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    isDeployInProgress: {
      type: Boolean,
      required: true,
    },
    stopUrl: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      isStopping: false,
    };
  },
  computed: {
    deployInProgressTooltip() {
      return this.isDeployInProgress
        ? __('Stopping this environment is currently not possible as a deployment is in progress')
        : '';
    },
  },
  methods: {
    stopEnvironment() {
      const msg = __('Are you sure you want to stop this environment?');
      const isConfirmed = confirm(msg); // eslint-disable-line

      if (isConfirmed) {
        this.isStopping = true;

        MRWidgetService.stopEnvironment(this.stopUrl)
          .then(res => res.data)
          .then(data => {
            if (data.redirect_url) {
              visitUrl(data.redirect_url);
            }

            this.isStopping = false;
          })
          .catch(() => {
            createFlash(
              __('Something went wrong while stopping this environment. Please try again.'),
            );
            this.isStopping = false;
          });
      }
    },
  },
};
</script>

<template>
  <span v-gl-tooltip :title="deployInProgressTooltip" class="d-inline-block" tabindex="0">
    <loading-button
      v-gl-tooltip
      :loading="isStopping"
      :disabled="isDeployInProgress"
      :title="__('Stop environment')"
      container-class="js-stop-env btn btn-default btn-sm inline prepend-left-4"
      @click="stopEnvironment"
    >
      <icon name="stop" />
    </loading-button>
  </span>
</template>