2021-02-15 15:17:54 +01:00
|
|
|
<template>
|
|
|
|
<b-list-group
|
2021-10-01 17:14:50 +02:00
|
|
|
v-bind="$attrs" flush
|
|
|
|
:class="{ 'fixed-height': fixedHeight, 'bordered': bordered }"
|
|
|
|
@scroll="onScroll"
|
2021-02-15 15:17:54 +01:00
|
|
|
>
|
2022-10-28 21:01:11 +02:00
|
|
|
<yuno-list-group-item
|
2021-10-01 17:14:50 +02:00
|
|
|
v-if="limit && messages.length > limit"
|
|
|
|
variant="info" v-t="'api.partial_logs'"
|
|
|
|
/>
|
|
|
|
|
2022-10-28 21:01:11 +02:00
|
|
|
<yuno-list-group-item
|
|
|
|
v-for="({ color, text }, i) in reducedMessages" :key="i"
|
|
|
|
:variant="color" size="xs"
|
|
|
|
>
|
2021-02-15 15:17:54 +01:00
|
|
|
<span v-html="text" />
|
2022-10-28 21:01:11 +02:00
|
|
|
</yuno-list-group-item>
|
2021-02-15 15:17:54 +01:00
|
|
|
</b-list-group>
|
|
|
|
</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 },
|
|
|
|
limit: { type: Number, default: null }
|
|
|
|
},
|
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
auto: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
reducedMessages () {
|
|
|
|
const len = this.messages.length
|
|
|
|
if (!this.limit || len <= this.limit) {
|
|
|
|
return this.messages
|
|
|
|
}
|
|
|
|
return this.messages.slice(len - this.limit)
|
|
|
|
}
|
2021-02-15 15:17:54 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
onScroll ({ target }) {
|
|
|
|
this.auto = target.scrollHeight === target.scrollTop + target.clientHeight
|
2021-02-15 15:17:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created () {
|
|
|
|
if (this.autoScroll) {
|
|
|
|
this.$watch('messages', this.scrollToEnd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</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>
|