summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/header.vue
blob: 1e7f4b2c3f7d711b00af52e5a2c6b876b21ec490 (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
<script>
import ciHeader from '../../vue_shared/components/header_ci_component.vue';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import callout from '../../vue_shared/components/callout.vue';

export default {
  name: 'JobHeaderSection',
  components: {
    ciHeader,
    loadingIcon,
    callout,
  },
  props: {
    job: {
      type: Object,
      required: true,
    },
    isLoading: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      actions: this.getActions(),
    };
  },
  computed: {
    status() {
      return this.job && this.job.status;
    },
    shouldRenderContent() {
      return !this.isLoading && Object.keys(this.job).length;
    },
    shouldRenderReason() {
      return !!(this.job.status && this.job.callout_message);
    },
    /**
     * When job has not started the key will be `false`
     * When job started the key will be a string with a date.
     */
    jobStarted() {
      return !this.job.started === false;
    },
    headerTime() {
      return this.jobStarted ? this.job.started : this.job.created_at;
    },
  },
  watch: {
    job() {
      this.actions = this.getActions();
    },
  },
  methods: {
    getActions() {
      const actions = [];

      if (this.job.new_issue_path) {
        actions.push({
          label: 'New issue',
          path: this.job.new_issue_path,
          cssClass: 'js-new-issue btn btn-new btn-inverted d-none d-md-block d-lg-block d-xl-block',
          type: 'link',
        });
      }
      return actions;
    },
  },
};
</script>
<template>
  <header>
    <div class="js-build-header build-header top-area">
      <ci-header
        v-if="shouldRenderContent"
        :status="status"
        :item-id="job.id"
        :time="headerTime"
        :user="job.user"
        :actions="actions"
        :has-sidebar-button="true"
        :should-render-triggered-label="jobStarted"
        item-name="Job"
      />
      <loading-icon
        v-if="isLoading"
        size="2"
        class="prepend-top-default append-bottom-default"
      />
    </div>

    <callout
      v-if="shouldRenderReason"
      :message="job.callout_message"
    />
  </header>
</template>