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-01-26 12:08:38 +05:30
|
|
|
I18N_ONLINE_RUNNER_TIMEAGO_DESCRIPTION,
|
2022-03-02 08:16:31 +05:30
|
|
|
I18N_NEVER_CONTACTED_RUNNER_DESCRIPTION,
|
2022-01-26 12:08:38 +05:30
|
|
|
I18N_OFFLINE_RUNNER_TIMEAGO_DESCRIPTION,
|
|
|
|
I18N_STALE_RUNNER_DESCRIPTION,
|
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.
|
|
|
|
return __('n/a');
|
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-01-26 12:08:38 +05:30
|
|
|
tooltip: sprintf(I18N_ONLINE_RUNNER_TIMEAGO_DESCRIPTION, {
|
2021-12-11 22:18:48 +05:30
|
|
|
timeAgo: this.contactedAtTimeAgo,
|
|
|
|
}),
|
|
|
|
};
|
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'),
|
|
|
|
tooltip: I18N_NEVER_CONTACTED_RUNNER_DESCRIPTION,
|
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-01-26 12:08:38 +05:30
|
|
|
tooltip: sprintf(I18N_OFFLINE_RUNNER_TIMEAGO_DESCRIPTION, {
|
2021-12-11 22:18:48 +05:30
|
|
|
timeAgo: this.contactedAtTimeAgo,
|
|
|
|
}),
|
|
|
|
};
|
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'),
|
|
|
|
tooltip: I18N_STALE_RUNNER_DESCRIPTION,
|
2021-12-11 22:18:48 +05:30
|
|
|
};
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<gl-badge v-if="badge" v-gl-tooltip="badge.tooltip" :variant="badge.variant" v-bind="$attrs">
|
|
|
|
{{ badge.label }}
|
|
|
|
</gl-badge>
|
|
|
|
</template>
|