yunohost-admin/app/src/components/QueryHeader.vue

142 lines
2.8 KiB
Vue
Raw Normal View History

<template>
2024-03-11 14:40:44 +01:00
<div v-bind="$attrs" class="query-header w-100">
<!-- STATUS -->
2024-02-24 18:25:12 +01:00
<span
class="status"
:class="['bg-' + color, statusSize]"
:aria-label="$t('api.query_status.' + request.status)"
/>
<!-- REQUEST DESCRIPTION -->
<strong class="request-desc">
{{ request.humanRoute }}
</strong>
<div v-if="request.errors || request.warnings">
<!-- WEBSOCKET ERRORS COUNT -->
<span class="count" v-if="request.errors">
{{ request.errors }}<YIcon iname="bug" class="text-danger ml-1" />
</span>
<!-- WEBSOCKET WARNINGS COUNT -->
<span class="count" v-if="request.warnings">
2024-02-24 18:25:12 +01:00
{{ request.warnings
}}<YIcon iname="warning" class="text-warning ml-1" />
</span>
</div>
<!-- VIEW ERROR BUTTON -->
2024-02-24 14:33:11 +01:00
<BButton
v-if="showError && request.error"
2024-02-24 18:25:12 +01:00
size="sm"
pill
class="error-btn ml-auto py-0"
variant="danger"
@click="reviewError"
>
<small v-t="'api_error.view_error'" />
2024-02-24 14:33:11 +01:00
</BButton>
<!-- TIME DISPLAY -->
2024-02-24 18:25:12 +01:00
<time
v-if="showTime"
:datetime="hour(request.date)"
:class="request.error ? 'ml-2' : 'ml-auto'"
>
{{ hour(request.date) }}
</time>
</div>
</template>
<script>
export default {
name: 'QueryHeader',
props: {
request: { type: Object, required: true },
statusSize: { type: String, default: '' },
showTime: { type: Boolean, default: false },
2024-02-24 18:25:12 +01:00
showError: { type: Boolean, default: false },
},
computed: {
2024-02-24 18:25:12 +01:00
color() {
const statuses = {
pending: 'primary',
success: 'success',
warning: 'warning',
2024-02-24 18:25:12 +01:00
error: 'danger',
}
return statuses[this.request.status]
},
2024-02-24 18:25:12 +01:00
errorsCount() {
return this.request.messages.filter(({ type }) => type === 'danger')
.length
},
2024-02-24 18:25:12 +01:00
warningsCount() {
return this.request.messages.filter(({ type }) => type === 'warning')
.length
},
},
methods: {
2024-02-24 18:25:12 +01:00
reviewError() {
this.$store.dispatch('REVIEW_ERROR', this.request)
},
2024-02-24 18:25:12 +01:00
hour(date) {
return new Date(date).toLocaleTimeString()
2024-02-24 18:25:12 +01:00
},
},
}
</script>
<style lang="scss" scoped>
div {
display: flex;
align-items: center;
font-size: $font-size-sm;
}
.error-btn {
height: 1.25rem;
display: flex;
align-items: center;
justify-content: center;
min-width: 70px;
}
.status {
display: inline-block;
border-radius: 50%;
2024-02-24 18:25:12 +01:00
width: 0.75rem;
min-width: 0.75rem;
height: 0.75rem;
margin-right: 0.25rem;
&.lg {
width: 1rem;
height: 1rem;
2024-02-24 18:25:12 +01:00
margin-right: 0.5rem;
}
}
time {
min-width: 3.5rem;
text-align: right;
}
.count {
display: flex;
align-items: center;
2024-02-24 18:25:12 +01:00
margin-left: 0.5rem;
}
@include media-breakpoint-down(xs) {
.xs-hide .request-desc {
display: none;
}
}
</style>