summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/pipelines_table.vue
blob: c9028952ddd31d4b208d2b9d14ce59dfae224516 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<script>
  import modal from '~/vue_shared/components/modal.vue';
  import { s__, sprintf } from '~/locale';
  import pipelinesTableRowComponent from './pipelines_table_row.vue';
  import eventHub from '../event_hub';

  /**
   * Pipelines Table Component.
   *
   * Given an array of objects, renders a table.
   */
  export default {
    components: {
      pipelinesTableRowComponent,
      modal,
    },
    props: {
      pipelines: {
        type: Array,
        required: true,
      },
      updateGraphDropdown: {
        type: Boolean,
        required: false,
        default: false,
      },
      autoDevopsHelpPath: {
        type: String,
        required: true,
      },
      viewType: {
        type: String,
        required: true,
      },
    },
    data() {
      return {
        pipelineId: '',
        endpoint: '',
        type: '',
      };
    },
    computed: {
      modalTitle() {
        return this.type === 'stop' ?
          sprintf(s__('Pipeline|Stop pipeline #%{pipelineId}?'), {
            pipelineId: `'${this.pipelineId}'`,
          }, false) :
          sprintf(s__('Pipeline|Retry pipeline #%{pipelineId}?'), {
            pipelineId: `'${this.pipelineId}'`,
          }, false);
      },
      modalText() {
        return this.type === 'stop' ?
          sprintf(s__('Pipeline|You’re about to stop pipeline %{pipelineId}.'), {
            pipelineId: `<strong>#${this.pipelineId}</strong>`,
          }, false) :
          sprintf(s__('Pipeline|You’re about to retry pipeline %{pipelineId}.'), {
            pipelineId: `<strong>#${this.pipelineId}</strong>`,
          }, false);
      },
      primaryButtonLabel() {
        return this.type === 'stop' ? s__('Pipeline|Stop pipeline') : s__('Pipeline|Retry pipeline');
      },
    },
    created() {
      eventHub.$on('openConfirmationModal', this.setModalData);
    },
    beforeDestroy() {
      eventHub.$off('openConfirmationModal', this.setModalData);
    },
    methods: {
      setModalData(data) {
        this.pipelineId = data.pipelineId;
        this.endpoint = data.endpoint;
        this.type = data.type;
      },
      onSubmit() {
        eventHub.$emit('postAction', this.endpoint);
      },
    },
  };
</script>
<template>
  <div class="ci-table">
    <div
      class="gl-responsive-table-row table-row-header"
      role="row"
    >
      <div
        class="table-section section-10 js-pipeline-status pipeline-status"
        role="rowheader"
      >
        Status
      </div>
      <div
        class="table-section section-15 js-pipeline-info pipeline-info"
        role="rowheader"
      >
        Pipeline
      </div>
      <div
        class="table-section section-20 js-pipeline-commit pipeline-commit"
        role="rowheader"
      >
        Commit
      </div>
      <div
        class="table-section section-20 js-pipeline-stages pipeline-stages"
        role="rowheader"
      >
        Stages
      </div>
    </div>
    <pipelines-table-row-component
      v-for="model in pipelines"
      :key="model.id"
      :pipeline="model"
      :update-graph-dropdown="updateGraphDropdown"
      :auto-devops-help-path="autoDevopsHelpPath"
      :view-type="viewType"
    />
    <modal
      id="confirmation-modal"
      :title="modalTitle"
      :text="modalText"
      kind="danger"
      :primary-button-label="primaryButtonLabel"
      @submit="onSubmit"
    >
      <template
        slot="body"
        slot-scope="props"
      >
        <p v-html="props.text"></p>
      </template>
    </modal>
  </div>
</template>