summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/projects/labels/components/promote_label_modal.vue
blob: dadb20e511b6c4f0942e103c51bbe2895392549d (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
84
85
86
87
88
89
90
91
92
93
94
95
96
<script>
import { escape as esc } from 'lodash';
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue';
import { s__, sprintf } from '~/locale';
import { visitUrl } from '~/lib/utils/url_utility';
import eventHub from '../event_hub';

export default {
  components: {
    GlModal: DeprecatedModal2,
  },
  props: {
    url: {
      type: String,
      required: true,
    },
    labelTitle: {
      type: String,
      required: true,
    },
    labelColor: {
      type: String,
      required: true,
    },
    labelTextColor: {
      type: String,
      required: true,
    },
    groupName: {
      type: String,
      required: true,
    },
  },
  computed: {
    text() {
      return sprintf(
        s__(`Labels|Promoting %{labelTitle} will make it available for all projects inside %{groupName}.
        Existing project labels with the same title will be merged. This action cannot be reversed.`),
        {
          labelTitle: this.labelTitle,
          groupName: this.groupName,
        },
      );
    },
    title() {
      const label = `<span
          class="label color-label"
          style="background-color: ${this.labelColor}; color: ${this.labelTextColor};"
        >${esc(this.labelTitle)}</span>`;

      return sprintf(
        s__('Labels|<span>Promote label</span> %{labelTitle} <span>to Group Label?</span>'),
        {
          labelTitle: label,
        },
        false,
      );
    },
  },
  methods: {
    onSubmit() {
      eventHub.$emit('promoteLabelModal.requestStarted', this.url);
      return axios
        .post(this.url, { params: { format: 'json' } })
        .then(response => {
          eventHub.$emit('promoteLabelModal.requestFinished', {
            labelUrl: this.url,
            successful: true,
          });
          visitUrl(response.data.url);
        })
        .catch(error => {
          eventHub.$emit('promoteLabelModal.requestFinished', {
            labelUrl: this.url,
            successful: false,
          });
          createFlash(error);
        });
    },
  },
};
</script>
<template>
  <gl-modal
    id="promote-label-modal"
    :footer-primary-button-text="s__('Labels|Promote Label')"
    footer-primary-button-variant="warning"
    @submit="onSubmit"
  >
    <div slot="title" class="modal-title-with-label" v-html="title">{{ title }}</div>

    {{ text }}
  </gl-modal>
</template>