2024-01-17 19:08:28 +00:00
|
|
|
<template>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-3 col-xl-2">
|
|
|
|
</div>
|
|
|
|
<div class="col-lg-9 col-xl-8">
|
|
|
|
<div class="w-100"
|
|
|
|
v-for="(group, index) in grouped_items"
|
|
|
|
:key="index">
|
|
|
|
<div v-if="group.length>0" class="card card-list-item bg-dark w-100 mb-3">
|
|
|
|
<div class="card-header" :class="'bg-'+sections[index].color" @click="toggle(index)">
|
|
|
|
<font-awesome-icon icon="angle-right" style="width: 1em;" v-if="collapsed[index]"/>
|
|
|
|
<font-awesome-icon icon="angle-down" style="width: 1em;" v-else/>
|
|
|
|
<slot name="section_header" :index="index" :section="sections[index]" :count="group.length"/>
|
|
|
|
</div>
|
|
|
|
<table class="card-body collapse table table-striped table-dark" :class="{show: !collapsed[index]}">
|
|
|
|
<slot class="row" v-for="item in group" name="section_body" :item="item"/>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2024-06-18 18:10:10 +00:00
|
|
|
import {mapGetters} from "vuex";
|
|
|
|
|
2024-01-17 19:08:28 +00:00
|
|
|
export default {
|
|
|
|
name: 'CollapsableCards',
|
|
|
|
props: {
|
|
|
|
columns: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
sections: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
keyName: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
collapsed: [],
|
|
|
|
symbols: ['▲', '▼', '▶', '◀'],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
2024-06-18 18:10:10 +00:00
|
|
|
const query = this.$router.currentRoute ? (this.$router.currentRoute.query ? this.$router.currentRoute.query.collapsed : null) : null;
|
2024-01-23 18:04:07 +00:00
|
|
|
if (query !== null && query !== undefined) {
|
|
|
|
this.collapsed = this.unpackInt(parseInt(query), this.sections.length);
|
|
|
|
} else {
|
|
|
|
this.collapsed = this.sections.map(() => true);
|
|
|
|
}
|
2024-01-17 19:08:28 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
grouped_items() {
|
|
|
|
return this.sections.map(section => this.items.filter(item => item[this.keyName] === section.slug));
|
2024-01-23 18:04:07 +00:00
|
|
|
},
|
2024-06-18 18:10:10 +00:00
|
|
|
...mapGetters(['route']),
|
2024-01-17 19:08:28 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2024-01-23 18:04:07 +00:00
|
|
|
packInt(arr) {
|
|
|
|
return arr.reduce((a, e, i) => a + (e ? 0 : 2 ** i), 0);
|
|
|
|
},
|
|
|
|
unpackInt(n, l) {
|
|
|
|
return [...Array(l)].map((e, i) => (n & 2 ** i) === 0);
|
|
|
|
},
|
2024-01-17 19:08:28 +00:00
|
|
|
toggle(index) {
|
2024-01-23 18:04:07 +00:00
|
|
|
const collapsed = [...this.collapsed]
|
|
|
|
collapsed[index] = !collapsed[index];
|
|
|
|
this.collapsed = collapsed;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
collapsed: {
|
|
|
|
handler() {
|
|
|
|
const encoded = this.packInt(this.collapsed).toString()
|
2024-06-18 18:10:10 +00:00
|
|
|
if (this.route.query.collapsed !== encoded)
|
|
|
|
this.$router.push({
|
|
|
|
...this.$router.currentRoute,
|
|
|
|
query: {...this.$router.currentRoute.query, collapsed: encoded}
|
|
|
|
});
|
2024-01-23 18:04:07 +00:00
|
|
|
},
|
|
|
|
deep: true,
|
2024-01-17 19:08:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|