2021-02-15 15:17:54 +01:00
|
|
|
<template>
|
2024-02-24 14:33:11 +01:00
|
|
|
<BListGroup
|
2024-02-24 18:25:12 +01:00
|
|
|
v-bind="$attrs"
|
|
|
|
flush
|
|
|
|
:class="{ 'fixed-height': fixedHeight, bordered: bordered }"
|
2021-10-01 17:14:50 +02:00
|
|
|
@scroll="onScroll"
|
2021-02-15 15:17:54 +01:00
|
|
|
>
|
2024-02-24 16:05:31 +01:00
|
|
|
<YListGroupItem
|
2021-10-01 17:14:50 +02:00
|
|
|
v-if="limit && messages.length > limit"
|
2024-02-24 18:25:12 +01:00
|
|
|
variant="info"
|
|
|
|
v-t="'api.partial_logs'"
|
2021-10-01 17:14:50 +02:00
|
|
|
/>
|
|
|
|
|
2024-02-24 16:05:31 +01:00
|
|
|
<YListGroupItem
|
2024-02-24 18:25:12 +01:00
|
|
|
v-for="({ color, text }, i) in reducedMessages"
|
|
|
|
:key="i"
|
|
|
|
:variant="color"
|
|
|
|
size="xs"
|
2022-10-28 21:01:11 +02:00
|
|
|
>
|
2021-02-15 15:17:54 +01:00
|
|
|
<span v-html="text" />
|
2024-02-24 16:05:31 +01:00
|
|
|
</YListGroupItem>
|
2024-02-24 14:33:11 +01:00
|
|
|
</BListGroup>
|
2021-02-15 15:17:54 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'MessageListGroup',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
messages: { type: Array, required: true },
|
|
|
|
fixedHeight: { type: Boolean, default: false },
|
|
|
|
bordered: { type: Boolean, default: false },
|
2021-10-01 17:14:50 +02:00
|
|
|
autoScroll: { type: Boolean, default: false },
|
2024-02-24 18:25:12 +01:00
|
|
|
limit: { type: Number, default: null },
|
2021-10-01 17:14:50 +02:00
|
|
|
},
|
|
|
|
|
2024-02-24 18:25:12 +01:00
|
|
|
data() {
|
2021-10-01 17:14:50 +02:00
|
|
|
return {
|
2024-02-24 18:25:12 +01:00
|
|
|
auto: true,
|
2021-10-01 17:14:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2024-02-24 18:25:12 +01:00
|
|
|
reducedMessages() {
|
2021-10-01 17:14:50 +02:00
|
|
|
const len = this.messages.length
|
|
|
|
if (!this.limit || len <= this.limit) {
|
|
|
|
return this.messages
|
|
|
|
}
|
|
|
|
return this.messages.slice(len - this.limit)
|
2024-02-24 18:25:12 +01:00
|
|
|
},
|
2021-02-15 15:17:54 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2024-02-24 18:25:12 +01:00
|
|
|
scrollToEnd() {
|
2021-10-01 17:14:50 +02:00
|
|
|
if (!this.auto) return
|
2021-02-15 15:17:54 +01:00
|
|
|
this.$nextTick(() => {
|
2021-10-01 17:14:50 +02:00
|
|
|
this.$el.scrollTo(0, this.$el.lastElementChild.offsetTop)
|
2021-02-15 15:17:54 +01:00
|
|
|
})
|
2021-10-01 17:14:50 +02:00
|
|
|
},
|
|
|
|
|
2024-02-24 18:25:12 +01:00
|
|
|
onScroll({ target }) {
|
2021-10-01 17:14:50 +02:00
|
|
|
this.auto = target.scrollHeight === target.scrollTop + target.clientHeight
|
2024-02-24 18:25:12 +01:00
|
|
|
},
|
2021-02-15 15:17:54 +01:00
|
|
|
},
|
|
|
|
|
2024-02-24 18:25:12 +01:00
|
|
|
created() {
|
2021-02-15 15:17:54 +01:00
|
|
|
if (this.autoScroll) {
|
2024-03-11 14:44:55 +01:00
|
|
|
this.$watch('messages', this.scrollToEnd, { deep: true })
|
2021-02-15 15:17:54 +01:00
|
|
|
}
|
2024-02-24 18:25:12 +01:00
|
|
|
},
|
2021-02-15 15:17:54 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.fixed-height {
|
|
|
|
max-height: 20vh;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.bordered {
|
|
|
|
border: $card-border-width solid $card-border-color;
|
|
|
|
@include border-radius($card-border-radius);
|
|
|
|
}
|
|
|
|
</style>
|