summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_merge_request_widget/components/states/mr_widget_wip.js
blob: b4b0f00445c38b3f649b788d6969b5860fbb5473 (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
import statusIcon from '../mr_widget_status_icon';
import tooltip from '../../../vue_shared/directives/tooltip';
import eventHub from '../../event_hub';

export default {
  name: 'MRWidgetWIP',
  props: {
    mr: { type: Object, required: true },
    service: { type: Object, required: true },
  },
  directives: {
    tooltip,
  },
  data() {
    return {
      isMakingRequest: false,
    };
  },
  components: {
    statusIcon,
  },
  methods: {
    removeWIP() {
      this.isMakingRequest = true;
      this.service.removeWIP()
        .then(res => res.data)
        .then((data) => {
          eventHub.$emit('UpdateWidgetData', data);
          new window.Flash('The merge request can now be merged.', 'notice'); // eslint-disable-line
          $('.merge-request .detail-page-description .title').text(this.mr.title);
        })
        .catch(() => {
          this.isMakingRequest = false;
          new window.Flash('Something went wrong. Please try again.'); // eslint-disable-line
        });
    },
  },
  template: `
    <div class="mr-widget-body media">
      <status-icon status="warning" :show-disabled-button="Boolean(mr.removeWIPPath)" />
      <div class="media-body space-children">
        <span class="bold">
          This is a Work in Progress
          <i
            v-tooltip
            class="fa fa-question-circle"
            title="When this merge request is ready, remove the WIP: prefix from the title to allow it to be merged"
            aria-label="When this merge request is ready, remove the WIP: prefix from the title to allow it to be merged">
           </i>
        </span>
        <button
          v-if="mr.removeWIPPath"
          @click="removeWIP"
          :disabled="isMakingRequest"
          type="button"
          class="btn btn-default btn-xs js-remove-wip">
          <i
            v-if="isMakingRequest"
            class="fa fa-spinner fa-spin"
            aria-hidden="true" />
            Resolve WIP status
        </button>
      </div>
    </div>
  `,
};