sidebar.vue 6.7 KB
Newer Older
1
<script>
2
import { __, sprintf } from '~/locale';
3 4
import _ from 'underscore';
import { mapActions, mapState } from 'vuex';
C
Clement Ho 已提交
5
import { GlLink, GlButton } from '@gitlab/ui';
6 7 8 9 10 11 12 13 14
import timeagoMixin from '~/vue_shared/mixins/timeago';
import { timeIntervalInWords } from '~/lib/utils/datetime_utility';
import Icon from '~/vue_shared/components/icon.vue';
import DetailRow from './sidebar_detail_row.vue';
import ArtifactsBlock from './artifacts_block.vue';
import TriggerBlock from './trigger_block.vue';
import CommitBlock from './commit_block.vue';
import StagesDropdown from './stages_dropdown.vue';
import JobsContainer from './jobs_container.vue';
15

16 17 18 19 20 21 22 23 24 25
export default {
  name: 'JobSidebar',
  components: {
    ArtifactsBlock,
    CommitBlock,
    DetailRow,
    Icon,
    TriggerBlock,
    StagesDropdown,
    JobsContainer,
26 27
    GlLink,
    GlButton,
28 29 30 31 32 33 34
  },
  mixins: [timeagoMixin],
  props: {
    runnerHelpUrl: {
      type: String,
      required: false,
      default: '',
35
    },
36 37
  },
  computed: {
38
    ...mapState(['job', 'stages', 'jobs', 'selectedStage']),
39 40 41 42 43 44 45 46 47 48 49 50 51
    coverage() {
      return `${this.job.coverage}%`;
    },
    duration() {
      return timeIntervalInWords(this.job.duration);
    },
    queued() {
      return timeIntervalInWords(this.job.queued);
    },
    runnerId() {
      return `${this.job.runner.description} (#${this.job.runner.id})`;
    },
    retryButtonClass() {
F
Fernando Arias 已提交
52
      let className = 'js-retry-button btn btn-retry';
53 54 55 56 57 58 59 60 61 62 63
      className +=
        this.job.status && this.job.recoverable ? ' btn-primary' : ' btn-inverted-secondary';
      return className;
    },
    hasTimeout() {
      return this.job.metadata != null && this.job.metadata.timeout_human_readable !== null;
    },
    timeout() {
      if (this.job.metadata == null) {
        return '';
      }
64

65 66
      let t = this.job.metadata.timeout_human_readable;
      if (this.job.metadata.timeout_source !== '') {
67 68 69
        t += sprintf(__(` (from %{timeoutSource})`), {
          timeoutSource: this.job.metadata.timeout_source,
        });
70
      }
71

72 73 74 75 76
      return t;
    },
    renderBlock() {
      return (
        this.job.duration ||
77
        this.job.finished_at ||
78 79
        this.job.erased_at ||
        this.job.queued ||
80
        this.hasTimeout ||
81 82
        this.job.runner ||
        this.job.coverage ||
83
        this.job.tags.length
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
      );
    },
    hasArtifact() {
      return !_.isEmpty(this.job.artifact);
    },
    hasTriggers() {
      return !_.isEmpty(this.job.trigger);
    },
    hasStages() {
      return (
        (this.job &&
          this.job.pipeline &&
          this.job.pipeline.stages &&
          this.job.pipeline.stages.length > 0) ||
        false
      );
100
    },
101
    commit() {
102
      return this.job.pipeline && this.job.pipeline.commit ? this.job.pipeline.commit : {};
103
    },
104 105
  },
  methods: {
106
    ...mapActions(['fetchJobsForStage', 'toggleSidebar']),
107 108
  },
};
109 110
</script>
<template>
M
Mike Greiling 已提交
111
  <aside class="right-sidebar build-sidebar" data-offset-top="101" data-spy="affix">
112 113
    <div class="sidebar-container">
      <div class="blocks-container">
F
Fernando Arias 已提交
114
        <div class="block d-flex flex-nowrap align-items-center">
115
          <h4 class="my-0 mr-2 text-break-word">{{ job.name }}</h4>
F
Fernando Arias 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
          <div class="flex-grow-1 flex-shrink-0 text-right">
            <gl-link
              v-if="job.retry_path"
              :class="retryButtonClass"
              :href="job.retry_path"
              data-method="post"
              rel="nofollow"
              >{{ __('Retry') }}</gl-link
            >
            <gl-link
              v-if="job.cancel_path"
              :href="job.cancel_path"
              class="js-cancel-job btn btn-default"
              data-method="post"
              rel="nofollow"
              >{{ __('Cancel') }}</gl-link
            >
          </div>

135
          <gl-button
136 137
            :aria-label="__('Toggle Sidebar')"
            type="button"
138
            class="btn btn-blank gutter-toggle float-right d-block d-md-none js-sidebar-build-toggle"
139 140
            @click="toggleSidebar"
          >
M
Mike Greiling 已提交
141
            <i aria-hidden="true" data-hidden="true" class="fa fa-angle-double-right"></i>
142
          </gl-button>
143
        </div>
F
Fernando Arias 已提交
144 145

        <div v-if="job.terminal_path || job.new_issue_path" class="block retry-link">
146
          <gl-link
147 148
            v-if="job.new_issue_path"
            :href="job.new_issue_path"
F
Fernando Arias 已提交
149
            class="js-new-issue btn btn-success btn-inverted float-left mr-2"
150
            >{{ __('New issue') }}</gl-link
151
          >
152
          <gl-link
F
Fernando Arias 已提交
153 154 155 156
            v-if="job.terminal_path"
            :href="job.terminal_path"
            class="js-terminal-link btn btn-primary btn-inverted visible-md-block visible-lg-block float-left"
            target="_blank"
157
          >
F
Fernando Arias 已提交
158 159
            {{ __('Debug') }} <icon name="external-link" :size="14" />
          </gl-link>
160
        </div>
F
Fernando Arias 已提交
161

162
        <div v-if="renderBlock" class="block">
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
          <detail-row
            v-if="job.duration"
            :value="duration"
            class="js-job-duration"
            title="Duration"
          />
          <detail-row
            v-if="job.finished_at"
            :value="timeFormated(job.finished_at)"
            class="js-job-finished"
            title="Finished"
          />
          <detail-row
            v-if="job.erased_at"
            :value="timeFormated(job.erased_at)"
            class="js-job-erased"
            title="Erased"
          />
M
Mike Greiling 已提交
181
          <detail-row v-if="job.queued" :value="queued" class="js-job-queued" title="Queued" />
182 183 184 185 186 187 188
          <detail-row
            v-if="hasTimeout"
            :help-url="runnerHelpUrl"
            :value="timeout"
            class="js-job-timeout"
            title="Timeout"
          />
M
Mike Greiling 已提交
189
          <detail-row v-if="job.runner" :value="runnerId" class="js-job-runner" title="Runner" />
190 191 192 193 194 195
          <detail-row
            v-if="job.coverage"
            :value="coverage"
            class="js-job-coverage"
            title="Coverage"
          />
M
Mike Greiling 已提交
196
          <p v-if="job.tags.length" class="build-detail-row js-job-tags">
197 198 199 200
            <span class="font-weight-bold">{{ __('Tags:') }}</span>
            <span v-for="(tag, i) in job.tags" :key="i" class="badge badge-primary mr-1">{{
              tag
            }}</span>
201 202
          </p>
        </div>
203

M
Mike Greiling 已提交
204 205
        <artifacts-block v-if="hasArtifact" :artifact="job.artifact" />
        <trigger-block v-if="hasTriggers" :trigger="job.trigger" />
206 207 208 209 210
        <commit-block
          :is-last-block="hasStages"
          :commit="commit"
          :merge-request="job.merge_request"
        />
211

212 213 214 215 216
        <stages-dropdown
          :stages="stages"
          :pipeline="job.pipeline"
          :selected-stage="selectedStage"
          @requestSidebarStageDropdown="fetchJobsForStage"
217 218 219
        />
      </div>

M
Mike Greiling 已提交
220
      <jobs-container v-if="jobs.length" :jobs="jobs" :job-id="job.id" />
221 222 223
    </div>
  </aside>
</template>