debian-mirror-gitlab/app/assets/javascripts/runner/components/runner_status_badge.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
2.5 KiB
Vue
Raw Normal View History

2021-12-11 22:18:48 +05:30
<script>
import { GlBadge, GlTooltipDirective } from '@gitlab/ui';
2022-10-11 01:57:18 +05:30
import { __, sprintf } from '~/locale';
2021-12-11 22:18:48 +05:30
import { getTimeago } from '~/lib/utils/datetime_utility';
import {
2022-10-11 01:57:18 +05:30
I18N_STATUS_ONLINE,
I18N_STATUS_NEVER_CONTACTED,
I18N_STATUS_OFFLINE,
I18N_STATUS_STALE,
2022-06-21 17:19:12 +05:30
I18N_ONLINE_TIMEAGO_TOOLTIP,
I18N_NEVER_CONTACTED_TOOLTIP,
I18N_OFFLINE_TIMEAGO_TOOLTIP,
I18N_STALE_TIMEAGO_TOOLTIP,
I18N_STALE_NEVER_CONTACTED_TOOLTIP,
2021-12-11 22:18:48 +05:30
STATUS_ONLINE,
2022-01-26 12:08:38 +05:30
STATUS_NEVER_CONTACTED,
STATUS_OFFLINE,
STATUS_STALE,
2021-12-11 22:18:48 +05:30
} from '../constants';
export default {
components: {
GlBadge,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
runner: {
required: true,
type: Object,
},
},
computed: {
contactedAtTimeAgo() {
if (this.runner.contactedAt) {
return getTimeago().format(this.runner.contactedAt);
}
2022-01-26 12:08:38 +05:30
// Prevent "just now" from being rendered, in case data is missing.
2022-06-21 17:19:12 +05:30
return __('never');
2021-12-11 22:18:48 +05:30
},
badge() {
2022-01-26 12:08:38 +05:30
switch (this.runner?.status) {
2021-12-11 22:18:48 +05:30
case STATUS_ONLINE:
return {
2022-10-11 01:57:18 +05:30
icon: 'status-active',
2021-12-11 22:18:48 +05:30
variant: 'success',
2022-10-11 01:57:18 +05:30
label: I18N_STATUS_ONLINE,
2022-06-21 17:19:12 +05:30
tooltip: this.timeAgoTooltip(I18N_ONLINE_TIMEAGO_TOOLTIP),
2021-12-11 22:18:48 +05:30
};
2022-01-26 12:08:38 +05:30
case STATUS_NEVER_CONTACTED:
return {
2022-10-11 01:57:18 +05:30
icon: 'time-out',
2022-01-26 12:08:38 +05:30
variant: 'muted',
2022-10-11 01:57:18 +05:30
label: I18N_STATUS_NEVER_CONTACTED,
2022-06-21 17:19:12 +05:30
tooltip: I18N_NEVER_CONTACTED_TOOLTIP,
2022-01-26 12:08:38 +05:30
};
2021-12-11 22:18:48 +05:30
case STATUS_OFFLINE:
return {
2022-10-11 01:57:18 +05:30
icon: 'time-out',
2021-12-11 22:18:48 +05:30
variant: 'muted',
2022-10-11 01:57:18 +05:30
label: I18N_STATUS_OFFLINE,
2022-06-21 17:19:12 +05:30
tooltip: this.timeAgoTooltip(I18N_OFFLINE_TIMEAGO_TOOLTIP),
2021-12-11 22:18:48 +05:30
};
2022-01-26 12:08:38 +05:30
case STATUS_STALE:
2021-12-11 22:18:48 +05:30
return {
2022-10-11 01:57:18 +05:30
icon: 'time-out',
2022-01-26 12:08:38 +05:30
variant: 'warning',
2022-10-11 01:57:18 +05:30
label: I18N_STATUS_STALE,
2022-06-21 17:19:12 +05:30
// runner may have contacted (or not) and be stale: consider both cases.
tooltip: this.runner.contactedAt
? this.timeAgoTooltip(I18N_STALE_TIMEAGO_TOOLTIP)
: I18N_STALE_NEVER_CONTACTED_TOOLTIP,
2021-12-11 22:18:48 +05:30
};
default:
return null;
}
},
},
2022-06-21 17:19:12 +05:30
methods: {
timeAgoTooltip(text) {
return sprintf(text, { timeAgo: this.contactedAtTimeAgo });
},
},
2021-12-11 22:18:48 +05:30
};
</script>
<template>
2022-10-11 01:57:18 +05:30
<gl-badge
v-if="badge"
v-gl-tooltip="badge.tooltip"
:variant="badge.variant"
:icon="badge.icon"
v-bind="$attrs"
>
2021-12-11 22:18:48 +05:30
{{ badge.label }}
</gl-badge>
</template>