summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/graph/job_component.vue
blob: b01c799643c37f4d5cb1c55feb0ed9e4d78ab9eb (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
140
141
142
143
144
<script>
  import actionComponent from './action_component.vue';
  import dropdownActionComponent from './dropdown_action_component.vue';
  import jobNameComponent from './job_name_component.vue';
  import tooltip from '../../../vue_shared/directives/tooltip';

  /**
   * Renders the badge for the pipeline graph and the job's dropdown.
   *
   * The following object should be provided as `job`:
   *
   * {
   *   "id": 4256,
   *   "name": "test",
   *   "status": {
   *     "icon": "icon_status_success",
   *     "text": "passed",
   *     "label": "passed",
   *     "group": "success",
   *     "details_path": "/root/ci-mock/builds/4256",
   *     "action": {
   *       "icon": "retry",
   *       "title": "Retry",
   *       "path": "/root/ci-mock/builds/4256/retry",
   *       "method": "post"
   *     }
   *   }
   * }
   */

  export default {
    props: {
      job: {
        type: Object,
        required: true,
      },

      cssClassJobName: {
        type: String,
        required: false,
        default: '',
      },

      isDropdown: {
        type: Boolean,
        required: false,
        default: false,
      },
    },

    components: {
      actionComponent,
      dropdownActionComponent,
      jobNameComponent,
    },

    directives: {
      tooltip,
    },

    computed: {
      status() {
        return this.job && this.job.status ? this.job.status : {};
      },

      tooltipText() {
        const textBuilder = [];

        if (this.job.name) {
          textBuilder.push(this.job.name);
        }

        if (this.job.name && this.status.label) {
          textBuilder.push('-');
        }

        if (this.status.label) {
          textBuilder.push(`${this.job.status.label}`);
        }

        return textBuilder.join(' ');
      },

      /**
       * Verifies if the provided job has an action path
       *
       * @return {Boolean}
       */
      hasAction() {
        return this.job.status && this.job.status.action && this.job.status.action.path;
      },
    },
  };
</script>
<template>
  <div class="ci-job-component">
    <a
      v-tooltip
      v-if="status.has_details"
      :href="status.details_path"
      :title="tooltipText"
      :class="cssClassJobName"
      data-container="body"
      class="js-pipeline-graph-job-link"
      >

      <job-name-component
        :name="job.name"
        :status="job.status"
        />
    </a>

    <div
      v-else
      v-tooltip
      class="js-job-component-tooltip"
      :title="tooltipText"
      :class="cssClassJobName"
      data-container="body"
      >

      <job-name-component
        :name="job.name"
        :status="job.status"
        />
    </div>

    <action-component
      v-if="hasAction && !isDropdown"
      :tooltip-text="status.action.title"
      :link="status.action.path"
      :action-icon="status.action.icon"
      :action-method="status.action.method"
      />

    <dropdown-action-component
      v-if="hasAction && isDropdown"
      :tooltip-text="status.action.title"
      :link="status.action.path"
      :action-icon="status.action.icon"
      :action-method="status.action.method"
      />
  </div>
</template>