summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_merge_request_widget/components/states/mr_widget_failed_to_merge.js
blob: 76b0235af1b7c14064c4c8e9f81c3303ea4b020d (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
import statusIcon from '../mr_widget_status_icon.vue';
import eventHub from '../../event_hub';

export default {
  name: 'MRWidgetFailedToMerge',
  props: {
    mr: { type: Object, required: true },
  },
  data() {
    return {
      timer: 10,
      isRefreshing: false,
    };
  },
  mounted() {
    setInterval(() => {
      this.updateTimer();
    }, 1000);
  },
  created() {
    eventHub.$emit('DisablePolling');
  },
  computed: {
    timerText() {
      return this.timer > 1 ? `${this.timer} seconds` : 'a second';
    },
  },
  methods: {
    refresh() {
      this.isRefreshing = true;
      eventHub.$emit('MRWidgetUpdateRequested');
      eventHub.$emit('EnablePolling');
    },
    updateTimer() {
      this.timer = this.timer - 1;

      if (this.timer === 0) {
        this.refresh();
      }
    },
  },
  components: {
    statusIcon,
  },
  template: `
    <div class="mr-widget-body media">
      <template v-if="isRefreshing">
        <status-icon status="loading" />
        <span class="media-body bold js-refresh-label">
          Refreshing now
        </span>
      </template>
      <template v-else>
        <status-icon status="warning" :show-disabled-button="true" />
        <div class="media-body space-children">
          <span class="bold">
            <span
              class="has-error-message"
              v-if="mr.mergeError">
              {{mr.mergeError}}.
            </span>
            <span v-else>Merge failed.</span>
            <span
              :class="{ 'has-custom-error': mr.mergeError }">
              Refreshing in {{timerText}} to show the updated status...
            </span>
          </span>
          <button
            @click="refresh"
            class="btn btn-default btn-xs js-refresh-button"
            type="button">
            Refresh now
          </button>
        </div>
      </template>
    </div>
  `,
};