summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/jobs/stage.vue
blob: 2f8b898652b8c45d702e0a7e63d13c4e756a0e21 (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
<script>
import { mapActions } from 'vuex';
import tooltip from '../../../vue_shared/directives/tooltip';
import Icon from '../../../vue_shared/components/icon.vue';
import CiIcon from '../../../vue_shared/components/ci_icon.vue';
import LoadingIcon from '../../../vue_shared/components/loading_icon.vue';
import Item from './item.vue';

export default {
  directives: {
    tooltip,
  },
  components: {
    Icon,
    CiIcon,
    LoadingIcon,
    Item,
  },
  props: {
    stage: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      showTooltip: false,
    };
  },
  computed: {
    collapseIcon() {
      return this.stage.isCollapsed ? 'angle-left' : 'angle-down';
    },
    showLoadingIcon() {
      return this.stage.isLoading && !this.stage.jobs.length;
    },
    jobsCount() {
      return this.stage.jobs.length;
    },
  },
  created() {
    this.fetchJobs(this.stage);
  },
  mounted() {
    const { stageTitle } = this.$refs;

    this.showTooltip = stageTitle.scrollWidth > stageTitle.offsetWidth;
  },
  methods: {
    ...mapActions('pipelines', ['fetchJobs', 'toggleStageCollapsed']),
  },
};
</script>

<template>
  <div
    class="card prepend-top-default"
  >
    <div
      class="card-header"
      :class="{
        'border-bottom-0': stage.isCollapsed
      }"
      @click="toggleStageCollapsed(stage.id)"
    >
      <ci-icon
        :status="stage.status"
        :size="24"
      />
      <strong
        v-tooltip="showTooltip"
        :title="showTooltip ? stage.name : null"
        data-container="body"
        class="prepend-left-8 ide-stage-title"
        ref="stageTitle"
      >
        {{ stage.name }}
      </strong>
      <div
        v-if="!stage.isLoading || stage.jobs.length"
        class="append-right-8 prepend-left-4"
      >
        <span class="badge badge-pill">
          {{ jobsCount }}
        </span>
      </div>
      <icon
        :name="collapseIcon"
        css-classes="pull-right"
      />
    </div>
    <div
      class="card-body"
      v-show="!stage.isCollapsed"
    >
      <loading-icon
        v-if="showLoadingIcon"
      />
      <template v-else>
        <item
          v-for="job in stage.jobs"
          :key="job.id"
          :job="job"
        />
      </template>
    </div>
  </div>
</template>

<style scoped>
.card-header {
  display: flex;
  cursor: pointer;
}
.card-header .ci-status-icon {
  display: flex;
  align-items: center;
}

.card-header .pull-right {
  margin: auto 0 auto auto;
}

.card-body {
  padding: 0;
}

.ide-stage-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>