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.

84 lines
2.2 KiB
Vue
Raw Normal View History

2021-12-11 22:18:48 +05:30
<script>
import { GlBadge, GlTooltipDirective } from '@gitlab/ui';
2022-01-26 12:08:38 +05:30
import { __, s__, sprintf } from '~/locale';
2021-12-11 22:18:48 +05:30
import { getTimeago } from '~/lib/utils/datetime_utility';
import {
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 {
variant: 'success',
label: s__('Runners|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 {
variant: 'muted',
2022-03-02 08:16:31 +05:30
label: s__('Runners|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 {
variant: 'muted',
label: s__('Runners|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-01-26 12:08:38 +05:30
variant: 'warning',
label: s__('Runners|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>
<gl-badge v-if="badge" v-gl-tooltip="badge.tooltip" :variant="badge.variant" v-bind="$attrs">
{{ badge.label }}
</gl-badge>
</template>