2018-01-15 11:31:03 +00:00
|
|
|
<script>
|
2020-04-15 09:09:46 +00:00
|
|
|
import { __ } from '~/locale';
|
2018-07-23 09:40:47 +00:00
|
|
|
import { roundOffFloat } from '~/lib/utils/common_utils';
|
2018-01-15 11:31:03 +00:00
|
|
|
import tooltip from '~/vue_shared/directives/tooltip';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
directives: {
|
|
|
|
tooltip,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
cssClass: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
successLabel: {
|
|
|
|
type: String,
|
2020-04-06 21:09:19 +00:00
|
|
|
required: false,
|
|
|
|
default: 'successful',
|
2018-01-15 11:31:03 +00:00
|
|
|
},
|
|
|
|
failureLabel: {
|
|
|
|
type: String,
|
2020-04-06 21:09:19 +00:00
|
|
|
required: false,
|
|
|
|
default: 'failed',
|
2018-01-15 11:31:03 +00:00
|
|
|
},
|
|
|
|
neutralLabel: {
|
|
|
|
type: String,
|
2020-04-06 21:09:19 +00:00
|
|
|
required: false,
|
|
|
|
default: 'neutral',
|
2018-01-15 11:31:03 +00:00
|
|
|
},
|
2020-04-15 09:09:46 +00:00
|
|
|
unavailableLabel: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: __('Not available'),
|
|
|
|
},
|
2018-01-15 11:31:03 +00:00
|
|
|
successCount: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
failureCount: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
totalCount: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-06 21:09:19 +00:00
|
|
|
hideTooltips: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-01-15 11:31:03 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
neutralCount() {
|
|
|
|
return this.totalCount - this.successCount - this.failureCount;
|
|
|
|
},
|
|
|
|
successPercent() {
|
|
|
|
return this.getPercent(this.successCount);
|
|
|
|
},
|
|
|
|
successBarStyle() {
|
|
|
|
return this.barStyle(this.successPercent);
|
|
|
|
},
|
|
|
|
successTooltip() {
|
|
|
|
return this.getTooltip(this.successLabel, this.successCount);
|
|
|
|
},
|
|
|
|
failurePercent() {
|
|
|
|
return this.getPercent(this.failureCount);
|
|
|
|
},
|
|
|
|
failureBarStyle() {
|
|
|
|
return this.barStyle(this.failurePercent);
|
|
|
|
},
|
|
|
|
failureTooltip() {
|
|
|
|
return this.getTooltip(this.failureLabel, this.failureCount);
|
|
|
|
},
|
|
|
|
neutralPercent() {
|
|
|
|
return this.getPercent(this.neutralCount);
|
|
|
|
},
|
|
|
|
neutralBarStyle() {
|
|
|
|
return this.barStyle(this.neutralPercent);
|
|
|
|
},
|
|
|
|
neutralTooltip() {
|
|
|
|
return this.getTooltip(this.neutralLabel, this.neutralCount);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getPercent(count) {
|
2019-12-11 21:08:17 +00:00
|
|
|
if (!this.totalCount) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-20 13:00:24 +00:00
|
|
|
const percent = roundOffFloat((count / this.totalCount) * 100, 1);
|
|
|
|
if (percent > 0 && percent < 1) {
|
|
|
|
return '< 1';
|
|
|
|
}
|
|
|
|
return percent;
|
2018-01-15 11:31:03 +00:00
|
|
|
},
|
|
|
|
barStyle(percent) {
|
2019-08-08 06:29:24 +00:00
|
|
|
// False positive i18n lint: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26
|
2020-03-18 15:09:45 +00:00
|
|
|
// eslint-disable-next-line @gitlab/require-i18n-strings
|
2018-01-15 11:31:03 +00:00
|
|
|
return `width: ${percent}%;`;
|
|
|
|
},
|
|
|
|
getTooltip(label, count) {
|
2020-04-06 21:09:19 +00:00
|
|
|
return this.hideTooltips ? '' : `${label}: ${count}`;
|
2018-01-15 11:31:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2018-11-16 20:07:38 +00:00
|
|
|
<div :class="cssClass" class="stacked-progress-bar">
|
2020-04-15 09:09:46 +00:00
|
|
|
<span v-if="!totalCount" class="status-unavailable">{{ unavailableLabel }}</span>
|
2018-01-15 11:31:03 +00:00
|
|
|
<span
|
|
|
|
v-if="successPercent"
|
2018-09-20 06:13:50 +00:00
|
|
|
v-tooltip
|
2018-01-15 11:31:03 +00:00
|
|
|
:title="successTooltip"
|
|
|
|
:style="successBarStyle"
|
2018-06-11 09:49:47 +00:00
|
|
|
class="status-green"
|
|
|
|
data-placement="bottom"
|
2018-01-15 11:31:03 +00:00
|
|
|
>
|
|
|
|
{{ successPercent }}%
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
v-if="neutralPercent"
|
2018-09-20 06:13:50 +00:00
|
|
|
v-tooltip
|
2018-01-15 11:31:03 +00:00
|
|
|
:title="neutralTooltip"
|
|
|
|
:style="neutralBarStyle"
|
2018-06-11 09:49:47 +00:00
|
|
|
class="status-neutral"
|
|
|
|
data-placement="bottom"
|
2018-01-15 11:31:03 +00:00
|
|
|
>
|
|
|
|
{{ neutralPercent }}%
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
v-if="failurePercent"
|
2018-09-20 06:13:50 +00:00
|
|
|
v-tooltip
|
2018-01-15 11:31:03 +00:00
|
|
|
:title="failureTooltip"
|
|
|
|
:style="failureBarStyle"
|
2018-06-11 09:49:47 +00:00
|
|
|
class="status-red"
|
|
|
|
data-placement="bottom"
|
2018-01-15 11:31:03 +00:00
|
|
|
>
|
|
|
|
{{ failurePercent }}%
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|