Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | 1x 1x 1x 1x 1x 1x 11x 11x 11x 4x 11x 11x 4x 4x 4x 8x 11x 11x 4x 11x 22x 4x 4x 4x 4x 4x 2x 1x 1x 3x 3x 8x 2x 2x 3x | <template>
<div class="int-table">
<!-- header slot -->
<slot name="header"></slot>
<!-- no columns -> show as list -->
<div :class="listClass"
v-if="tableData && ! hasColumns"
>
<div :class="listRowClass"
v-for="(row, i) in tableData"
:key="i"
>
<slot
name="list"
:tableData="tableData"
:data="row"
:index="i"
>
<template v-if="typeof row === 'object'">
<div class="int-table__list-cell"
v-for="(item, key) in row"
:key="key"
>
<span class="int-table__list-name">{{ key }} : </span>
<span class="int-table__list-value">{{item}}</span>
</div>
</template>
<template v-else>
{{ row }}
</template>
</slot>
</div>
</div>
<!-- table -->
<div class="int-table__overflow">
<table
v-if="tableData && hasColumns"
class="int-table__table"
>
<thead>
<tr>
<th v-for="({ label, sort }, i) in columnsHead" :key="i">
<tb-sort-button
v-if="sort"
v-bind="sort"
>
{{ label }}
</tb-sort-button>
<template v-else>{{ label }}</template>
</th>
<th v-if="hiddenOptions && hiddenOptions.length"></th>
</tr>
</thead>
<tbody>
<template v-for="(rowData, i) in tableData">
<tb-row
:key="i + '-row'"
:tableOptions="shownOptions"
:data="rowData"
:index="i"
:active="activeItem === i"
:url="rowUrl"
:matchedMedia="matchedMedia"
:showToggler="!!hiddenColumnData"
@setActive="setActiveItem"
@click="rowClick"
ref="tbRows"
></tb-row>
<tr class="int-table__hidden"
v-if="hiddenColumnData"
v-show="activeItem === i"
:key="i + '-hidden-row'">
<td :colspan="shownOptions.length + 1">
<slot
name="hidden"
:data="rowData"
:hiddenData="hiddenColumnData[i]"
:matchedMedia="matchedMedia"
:index="i"
>
<tb-hidden-items
:hiddenOptions="hiddenOptions"
:data="rowData"
:index="i"
:active="activeItem === i"
:matchedMedia="matchedMedia"
>
</tb-hidden-items>
</slot>
</td>
</tr>
</template>
</tbody>
</table>
</div>
<!-- footer slot -->
<slot name="footer"></slot>
</div>
</template>
<script>
import { ucFirst, trimStr } from '../js/modules/fp.js'
import mediaQueriesMixin from '../js/mixins/media-queries.js'
import configMixin from '../js/mixins/config.js'
import tbRow from './tb-row.vue'
import tbHiddenItems from './tb-hidden-items.vue'
import tbSortButton from './tb-sort-button.vue'
export default {
name: 'table-builder',
mixins: [ mediaQueriesMixin, configMixin ],
components: { tbRow, tbHiddenItems, tbSortButton },
props: {
default: [Array, Object],
listClass: {
type: String,
default: 'int-table__list'
},
listRowClass: {
type: String,
default: 'int-table__list-row'
},
rowUrl: String,
rowClick: {
type: Function,
default(data) {
if ( data && data.url ) {
window.location.href = AWEMA.utils.urlFromTemplate(data.url, data.data)
}
}
}
},
data() {
return {
activeItem: null
}
},
computed: {
tableData() {
return Array.isArray(this.default) ? this.default : [this.default]
},
columns() {
return this.$slots.default && this.$slots.default.filter( item => {
return item.componentOptions && item.componentOptions.tag === 'tb-column'
})
},
hasColumns() {
return this.columns && !! this.columns.length
},
tableOptions() {
return this.columns && this.columns.map(item => {
return Object.assign({}, item.componentOptions.propsData, {
className: item.data.staticClass,
scopedSlots: item.data.scopedSlots && item.data.scopedSlots.default ?
item.data.scopedSlots.default :
null
});
});
},
shownOptions() {
return this.tableOptions && this.tableOptions.filter( item => {
E if ( ! item.media || item.media && this._checkMediaMatch(item.media) ) return true
})
},
hiddenOptions() {
return this.tableOptions && this.tableOptions.filter( item => {
if ( item.media && ! this._checkMediaMatch(item.media) ) return true
})/*.map( item => item.name )*/
},
hiddenOptionsNames() {
return this.hiddenOptions && this.hiddenOptions.map( item => item.name )
},
hiddenColumnData() {
if ( ! this.hiddenOptions || ! this.hiddenOptions.length ) return false
return this.tableData.map( row => {
if ( ! row ) return
let hiddenData = {}
Object.keys(row)
.filter( key => this.hiddenOptionsNames.includes(key) )
.forEach( key => { hiddenData[key] = row[key] })
return hiddenData
})
},
columnsHead() {
return this.shownOptions.map( option => {
let label = ucFirst( typeof option.label !== 'undefined' ? option.label : option.name )
let sort = typeof option.sort === 'string' ? this._getSortParams( option.name, option.sort ) : false
return { label, sort }
})
}
},
watch: {
hiddenColumnData( data ) {
if ( data === false ) this.activeItem = null
}
},
methods: {
setActiveItem(index, val) {
if (val) {
this.activeItem = index;
} else {
this.activeItem = null
}
},
_getSortParams(label, sort) {
let asc = this.$get(this._config, 'sort.ascTemplate').replace('%s', label)
let desc = this.$get(this._config, 'sort.descTemplate').replace('%s', label)
if ( sort !== '' ) {
let [_asc, _desc] = sort.split('|').map(trimStr)
asc = _asc || ''
desc = _desc || ''
}
return { asc, desc }
}
}
}
</script> |