summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/pipelines_list/time_ago.vue
blob: 543bdf9430786a22246f97da6a703017a66213f9 (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
<script>
import { GlIcon, GlTooltipDirective } from '@gitlab/ui';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import timeagoMixin from '~/vue_shared/mixins/timeago';

export default {
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  components: { GlIcon },
  mixins: [timeagoMixin, glFeatureFlagMixin()],
  props: {
    pipeline: {
      type: Object,
      required: true,
    },
  },
  computed: {
    duration() {
      return this.pipeline?.details?.duration;
    },
    finishedTime() {
      return this.pipeline?.details?.finished_at;
    },
    durationFormatted() {
      const date = new Date(this.duration * 1000);

      let hh = date.getUTCHours();
      let mm = date.getUTCMinutes();
      let ss = date.getSeconds();

      // left pad
      if (hh < 10) {
        hh = `0${hh}`;
      }
      if (mm < 10) {
        mm = `0${mm}`;
      }
      if (ss < 10) {
        ss = `0${ss}`;
      }

      return `${hh}:${mm}:${ss}`;
    },
    legacySectionClass() {
      return !this.glFeatures.newPipelinesTable ? 'table-section section-15' : '';
    },
    legacyTableMobileClass() {
      return !this.glFeatures.newPipelinesTable ? 'table-mobile-content' : '';
    },
    showInProgress() {
      return !this.duration && !this.finishedTime;
    },
  },
};
</script>
<template>
  <div :class="legacySectionClass">
    <div v-if="!glFeatures.newPipelinesTable" class="table-mobile-header" role="rowheader">
      {{ s__('Pipeline|Duration') }}
    </div>
    <div :class="legacyTableMobileClass">
      <span v-if="showInProgress" data-testid="pipeline-in-progress">
        <gl-icon name="hourglass" class="gl-vertical-align-baseline! gl-mr-2" :size="12" />
        {{ s__('Pipeline|In progress') }}
      </span>

      <p v-if="duration" class="duration">
        <gl-icon name="timer" class="gl-vertical-align-baseline!" :size="12" />
        {{ durationFormatted }}
      </p>

      <p v-if="finishedTime" class="finished-at d-none d-md-block">
        <gl-icon name="calendar" class="gl-vertical-align-baseline!" :size="12" />

        <time
          v-gl-tooltip
          :title="tooltipTitle(finishedTime)"
          data-placement="top"
          data-container="body"
        >
          {{ timeFormatted(finishedTime) }}
        </time>
      </p>
    </div>
  </div>
</template>