Feature/warehouse
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
axios.interceptors.response.use(function (response) {
|
||||
return response;
|
||||
}, function (error) {
|
||||
window.notify('error', error.response.data.message || 'Ein Fehler ist aufgetreten')
|
||||
return Promise.reject(error);
|
||||
});
|
||||
@@ -2,6 +2,10 @@
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tt-table {
|
||||
/*width: unset !important;*/
|
||||
}
|
||||
|
||||
.tt-table.loading tbody:after {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
@@ -151,4 +155,175 @@ input[type=number]::-webkit-outer-spin-button {
|
||||
|
||||
td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
}
|
||||
|
||||
/*TODO: export this classes somewhere else*/
|
||||
|
||||
.text-cyan {
|
||||
color: var(--cyan);
|
||||
}
|
||||
|
||||
.text-green {
|
||||
color: var(--green);
|
||||
}
|
||||
|
||||
.text-red {
|
||||
color: var(--red);
|
||||
}
|
||||
|
||||
.text-yellow {
|
||||
color: var(--yellow);
|
||||
}
|
||||
|
||||
.text-blue {
|
||||
color: var(--blue);
|
||||
}
|
||||
|
||||
.text-purple {
|
||||
color: var(--purple);
|
||||
}
|
||||
|
||||
.text-orange {
|
||||
color: var(--orange);
|
||||
}
|
||||
|
||||
.text-pink {
|
||||
color: var(--pink);
|
||||
}
|
||||
|
||||
.text-gray {
|
||||
color: var(--gray);
|
||||
}
|
||||
|
||||
.text-white {
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.text-light {
|
||||
color: var(--light);
|
||||
}
|
||||
|
||||
.text-dark {
|
||||
color: var(--dark);
|
||||
}
|
||||
|
||||
.width-40 {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.width-80 {
|
||||
width: 80px;
|
||||
}
|
||||
.width-120 {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.width-160 {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.width-200 {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.width-240 {
|
||||
width: 240px;
|
||||
}
|
||||
|
||||
.width-280 {
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
.width-320 {
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
.width-360 {
|
||||
width: 360px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*TODO: remove this*/
|
||||
/* Styles for the component */
|
||||
.tt-expandable-shopping-cart {
|
||||
position: fixed;
|
||||
bottom: 65px;
|
||||
right: 20px;
|
||||
background-color: #f8f9fa;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 5px;
|
||||
width: 50px; /* Initial width */
|
||||
height: 50px;
|
||||
transition: width 0.3s ease, height 0.3s ease;
|
||||
}
|
||||
|
||||
.expanded {
|
||||
width: 500px; /* Expanded width */
|
||||
height: 600px; /* Expanded height */
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.toggle-button {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 24px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.cart-content {
|
||||
padding: 15px;
|
||||
display: none; /* Initially hidden */
|
||||
}
|
||||
|
||||
.expanded .cart-content {
|
||||
display: block; /* Show when expanded */
|
||||
}
|
||||
|
||||
.cart-count {
|
||||
background-color: #dc3545; /* Red background */
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
padding: 0 6px;
|
||||
font-size: 12px;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 5px;
|
||||
}
|
||||
|
||||
.tt-expandable-shopping-cart.expanded {
|
||||
border-top-left-radius: 0.25rem;
|
||||
border-top-right-radius: 0.25rem;
|
||||
|
||||
}
|
||||
|
||||
.tt-expandable-shopping-cart.expanded .cart-content {
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
.tt-expandable-shopping-cart.expanded .cart-content h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
|
||||
.tt-expandable-shopping-cart.expanded .toggle-button {
|
||||
display: grid;
|
||||
grid-template-columns: 2fr 3fr auto auto;
|
||||
grid-gap: 10px;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: var(--gray)
|
||||
}
|
||||
|
||||
.tt-expandable-shopping-cart.expanded .toggle-button i {
|
||||
justify-self: left;
|
||||
}
|
||||
|
||||
.tt-expandable-shopping-cart.expanded .cart-count {
|
||||
position: unset !important;
|
||||
width: 21px;
|
||||
height: 21px;
|
||||
grid-column-start: 3;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
Vue.component('tt-autocomplete', {
|
||||
template: `
|
||||
<div class="form-group">
|
||||
<div class="form-group" :class="{'row': row}">
|
||||
<slot name="prepend"></slot>
|
||||
<label v-if="label" :for="label">{{ label }}</label>
|
||||
<div class="autocomplete position-relative">
|
||||
<label :class="{'col-form-label': row, 'col-sm-4': row, 'col-form-label-sm': sm && row}"
|
||||
v-if="label" :for="label">{{ label }}</label>
|
||||
<div class="autocomplete position-relative" :class="{'col-sm-8 p-0': row}">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control form-control-sm"
|
||||
:id="label"
|
||||
class="form-control"
|
||||
:class="{'form-control-sm': sm}"
|
||||
v-model="displayValue"
|
||||
@input="onInput"
|
||||
@focus="onFocus"
|
||||
@@ -50,18 +53,12 @@ Vue.component('tt-autocomplete', {
|
||||
// TODO: Implement giving the option without the need of an API || need to use computed property to filter the items
|
||||
// TODO: Fix the weirdness with timeout and selecting the suggestion
|
||||
props: {
|
||||
value: {
|
||||
type: [String, Number]
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
value: { type: [String, Number] },
|
||||
label: { type: String, required: false },
|
||||
apiUrl: String,
|
||||
items: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
}
|
||||
items: { type: Array, default: () => [] },
|
||||
sm: { type: Boolean, default: true },
|
||||
row: { type: Boolean, default: false },
|
||||
},
|
||||
async mounted() {
|
||||
if (this.value && this.apiUrl) {
|
||||
@@ -70,6 +67,8 @@ Vue.component('tt-autocomplete', {
|
||||
} else if (this.value) {
|
||||
const selectedItem = this.items.find(item => item.value === this.value);
|
||||
this.displayValue = selectedItem ? selectedItem.text : '';
|
||||
} else {
|
||||
this.displayValue = '';
|
||||
}
|
||||
|
||||
},
|
||||
@@ -86,6 +85,7 @@ Vue.component('tt-autocomplete', {
|
||||
watch: {
|
||||
value(newValue) {
|
||||
const selectedItem = this.displayingItems.find(item => item.value === newValue);
|
||||
console.log(selectedItem);
|
||||
this.displayValue = selectedItem ? selectedItem.text : '';
|
||||
},
|
||||
apiUrl() {
|
||||
@@ -95,7 +95,7 @@ Vue.component('tt-autocomplete', {
|
||||
methods: {
|
||||
onInput(event) {
|
||||
this.displayValue = event.target.value;
|
||||
this.$emit('input', undefined);
|
||||
this.$emit('input', '');
|
||||
this.fetchSuggestions();
|
||||
},
|
||||
onFocus() {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
Vue.component('tt-checkbox', {
|
||||
props: {
|
||||
label: String,
|
||||
required: Boolean,
|
||||
row: Boolean,
|
||||
value: [String, Number],
|
||||
hint: String,
|
||||
additionalProps: Object,
|
||||
sm: { type: Boolean, default: false },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
checkedValue: this.value,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(val) {
|
||||
this.checkedValue = val;
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="form-group" :class="{'row': row}">
|
||||
<slot name="prepend"></slot>
|
||||
<label
|
||||
:class="{'col-form-label': row, 'col-sm-4': row, 'col-form-label-sm': sm && row}"
|
||||
v-if="label"
|
||||
:for="label">{{ label }}</label>
|
||||
|
||||
<input type="checkbox"
|
||||
:id="label"
|
||||
:name="label"
|
||||
class="form-control float-left"
|
||||
:class="{'form-control-sm': sm, 'col-sm-8': row}"
|
||||
:required="required"
|
||||
v-bind="additionalProps"
|
||||
v-model="checkedValue"
|
||||
@input="$emit('input', $event.target.checked ? 1 : 0)"
|
||||
>
|
||||
<small v-if="hint" class="form-text text-muted">{{ hint }}</small>
|
||||
</div>
|
||||
`
|
||||
});
|
||||
@@ -4,6 +4,7 @@ Vue.component('tt-input', {
|
||||
type: String,
|
||||
placeholder: String,
|
||||
required: Boolean,
|
||||
row: Boolean,
|
||||
value: [String, Number],
|
||||
hint: String,
|
||||
additionalProps: Object,
|
||||
@@ -20,15 +21,17 @@ Vue.component('tt-input', {
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="form-group">
|
||||
<div class="form-group" :class="{'row': row}">
|
||||
<slot name="prepend"></slot>
|
||||
<label
|
||||
:class="{'col-form-label': row, 'col-sm-4': row, 'col-form-label-sm': sm && row}"
|
||||
v-if="label"
|
||||
:for="label">{{ label }}</label>
|
||||
<input :type="type"
|
||||
:id="label"
|
||||
:name="label"
|
||||
class="form-control"
|
||||
:class="{'form-control-sm': sm}"
|
||||
:class="{'form-control-sm': sm, 'col-sm-8': row}"
|
||||
:placeholder="placeholder"
|
||||
:required="required"
|
||||
v-bind="additionalProps"
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
Vue.component('tt-modal', {
|
||||
props: {
|
||||
show: { type: Boolean, default: false },
|
||||
title: { type: String, default: 'Modal Title' },
|
||||
delete: { type: Boolean, default: true },
|
||||
save: { type: Boolean, default: true },
|
||||
},
|
||||
watch: {
|
||||
show(newVal) {
|
||||
if (!newVal) {
|
||||
this.$emit('close')
|
||||
}
|
||||
},
|
||||
},
|
||||
//language=Vue
|
||||
template: `
|
||||
<div class="modal show d-block"
|
||||
role="dialog"
|
||||
tabindex="-1"
|
||||
style="background: rgba(0, 0, 0, 0.5);"
|
||||
ref="modal"
|
||||
@mousedown="$emit('update:show', false)"
|
||||
@keydown.esc="$emit('update:show', false)"
|
||||
v-if="show">
|
||||
<div class="modal-dialog modal-lg" role="document" @mousedown.stop>
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">{{title}}</h5>
|
||||
<button type="button" class="close" @click="$emit('update:show', false)">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<slot></slot>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<slot name="footer">
|
||||
<button v-if="save" class="btn btn-primary" @click="$emit('submit')">Save</button>
|
||||
<button v-if="$props.delete" class="btn btn-danger" @click="$emit('delete')">Delete</button>
|
||||
<button class="btn btn-secondary" @click="$emit('update:show', false)">Close</button>
|
||||
</slot>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
@@ -1,5 +1,13 @@
|
||||
Vue.component('tt-select', {
|
||||
props: ['options', 'label', 'required', 'value', 'suffix'],
|
||||
props: {
|
||||
options: {type: Array, required: true},
|
||||
label: {type: String, required: false},
|
||||
required: {type: Boolean, default: false},
|
||||
value: {type: [String, Number], required: false},
|
||||
suffix: {type: String, required: false},
|
||||
sm: {type: Boolean, default: false},
|
||||
row: {type: Boolean, default: false},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
selectedOption: undefined,
|
||||
@@ -14,9 +22,13 @@ Vue.component('tt-select', {
|
||||
},
|
||||
},
|
||||
template: `
|
||||
<div class="form-group">
|
||||
<label v-if="label" :for="label">{{ label }}</label>
|
||||
<select class="form-control form-control-sm" :required="required" v-model="selectedOption"
|
||||
<div class="form-group" :class="{'row': row}">
|
||||
<label v-if="label"
|
||||
:class="{'col-form-label': row, 'col-sm-4': row, 'col-form-label-sm': sm && row}"
|
||||
|
||||
:for="label">{{ label }}</label>
|
||||
<select class="form-control" :class="{'form-control-sm': sm, 'col-sm-8': row}"
|
||||
:required="required" v-model="selectedOption"
|
||||
@change="$emit('input', $event.target.value ? $event.target.value : undefined)">
|
||||
<template v-for="option of options">
|
||||
<option v-if="['string','number'].includes(typeof option)" :value="option">{{ option }}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
Vue.component('tt-table-crud', {
|
||||
//language=Vue
|
||||
template: `
|
||||
<div>
|
||||
<tt-table :fetch-url="window['TT_CONFIG']['TABLE_URL']" :config="tableConfig"
|
||||
small ssr ref="table">
|
||||
<template v-slot:top-buttons>
|
||||
<button type="button" class="btn btn-primary" @click="openCrudModal" v-if="crudConfig.createText !== false">
|
||||
<i class="fas fa-plus"></i>
|
||||
{{crudConfig.createText || 'Erstellen'}}
|
||||
</button>
|
||||
|
||||
<slot name="table-top-buttons"></slot>
|
||||
</template>
|
||||
|
||||
<template v-for="column in crudConfig.columns"
|
||||
:slot="column.key.toLowerCase()"
|
||||
slot-scope="{row}">
|
||||
<slot v-if="$scopedSlots[column.key.toLowerCase()] && column.modal?.type !== 'select'"
|
||||
:name="column.key.toLowerCase()" :row="row">
|
||||
|
||||
</slot>
|
||||
<span v-else-if="column.modal?.type === 'select' && column.modal.items.find(item => item.value + '' === row[column.key] + '')">{{column.modal.items.find(item => item.value == row[column.key]).text}}</span>
|
||||
<span v-else-if="column.modal?.type === 'select'"
|
||||
:data-all-items="JSON.stringify(column.modal.items)"
|
||||
>Select not found for column {{column.key}} and value {{row[column.key]}}</span>
|
||||
</template>
|
||||
|
||||
<template v-slot:actions="{ row }">
|
||||
<!-- calculate min width 1 + number of actions * 19 -->
|
||||
<div style="display: flex; justify-content: space-around; align-items: center;" :style="{minWidth: (1 + crudConfig?.additionalActions?.length || 0) * 19 + 'px'}">
|
||||
<a style="cursor: pointer;" @click="openCrudModal(row)"><i class="far fa-edit text-primary"
|
||||
title="Editieren"></i></a>
|
||||
|
||||
<!-- v-for action crudConfig.additionalActions -> v-if action.condition(row) || true , action.class for icon class, action.title for title, action.key for emitting event -->
|
||||
<a v-for="action in crudConfig.additionalActions"
|
||||
v-if="!action.condition || action.condition(row)"
|
||||
style="cursor: pointer;" @click="$emit(action.key, row)">
|
||||
<i :class="action.class" :title="action.title"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
</tt-table>
|
||||
|
||||
<tt-modal :show.sync="crudModal"
|
||||
:title="crudConfig.createText || 'Erstellen'"
|
||||
@submit="submitCrudModal"
|
||||
@delete="deleteCrudModal"
|
||||
@close="resetCrudModalData">
|
||||
|
||||
<template v-for="column in modalConfig.headers">
|
||||
<!-- @formatter:off -->
|
||||
<tt-input v-if="column.type === 'text'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
|
||||
<tt-input v-if="column.type === 'number'" v-model="crudModalData[column.key]" :label="column.text" type="number" sm row/>
|
||||
<tt-textarea v-if="column.type === 'textarea'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
|
||||
<tt-select v-if="column.type === 'select'" v-model="crudModalData[column.key]" :label="column.text" :options="column.items" sm row/>
|
||||
<tt-autocomplete v-if="column.type === 'autocomplete'" v-model="crudModalData[column.key]" :label="column.text" :items="column.items" sm row/>
|
||||
<tt-date-picker v-if="column.type === 'datepicker'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
|
||||
<tt-icon-select v-if="column.type === 'icon-select'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
|
||||
<tt-checkbox v-if="column.type === 'checkbox'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
|
||||
<!-- @formatter:on -->
|
||||
</template>
|
||||
|
||||
</tt-modal>
|
||||
</div>
|
||||
`, props: {
|
||||
crudConfig: {type: Object, required: false, default: () => (window['TT_CONFIG']['CRUD_CONFIG'])}
|
||||
}, data() {
|
||||
return {
|
||||
crudModal: false, crudModalData: {}, window: window
|
||||
|
||||
}
|
||||
}, methods: {
|
||||
openCrudModal(row = null) {
|
||||
this.crudModalData = row ? JSON.parse(JSON.stringify(row)) : {};
|
||||
this.crudModal = true;
|
||||
}, resetCrudModalData() {
|
||||
this.crudModalData = {};
|
||||
this.crudModal = false;
|
||||
}, async submitCrudModal() {
|
||||
delete this.crudModalData.isTrusted;
|
||||
const response = await axios.post(this.crudModalData.id ? window['TT_CONFIG']['UPDATE_URL'] : window['TT_CONFIG']['CREATE_URL'],
|
||||
this.crudModalData);
|
||||
if (response.data.success) {
|
||||
this.$refs.table.refreshTable();
|
||||
this.resetCrudModalData();
|
||||
this.window.notify('success', response.data.message || 'Erfolgreich gespeichert');
|
||||
} else {
|
||||
this.window.notify('error',
|
||||
response.data.errors ? Object.values(response.data.errors).join('<br>') : response.data.message ||
|
||||
'Ein Fehler ist aufgetreten');
|
||||
}
|
||||
}, async deleteCrudModal() {
|
||||
|
||||
const response = await axios.post(window['TT_CONFIG']['DELETE_URL'], {id: this.crudModalData.id});
|
||||
if (response.data.success) {
|
||||
this.$refs.table.refreshTable();
|
||||
this.resetCrudModalData();
|
||||
}
|
||||
this.window.notify(response.data.success ? 'success' : 'error', response.data.message);
|
||||
}
|
||||
}, computed: {
|
||||
tableConfig() {
|
||||
return {
|
||||
key: this.crudConfig.key,
|
||||
tableHeader: this.crudConfig.tableHeader,
|
||||
headers: this.crudConfig.columns.filter(column => column.table !== false).map(column => {
|
||||
return {text: column.text, key: column.key, ...column.table, filterOptions: column?.modal?.items}
|
||||
})
|
||||
}
|
||||
}, modalConfig() {
|
||||
return {
|
||||
key: this.crudConfig.key,
|
||||
headers: this.crudConfig.columns.filter(column => column.modal !== false).map(column => {
|
||||
const type = column.modal?.type || "text"
|
||||
return {text: column.text, key: column.key, type, ...column.modal}
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -32,11 +32,11 @@
|
||||
|
||||
|
||||
Vue.component('tt-table-pagination', {
|
||||
props: {
|
||||
props: {
|
||||
pagination: {
|
||||
type: Object,
|
||||
type: Object,
|
||||
required: true,
|
||||
default: () => ({page: 1, per_page: 10, total_rows: 0, filtered_available: 0, total_pages: 1})
|
||||
default: () => ({page: 1, per_page: 10, total_rows: 0, filtered_available: 0, total_pages: 1})
|
||||
}, reverse: {type: Boolean, default: false}
|
||||
}, computed: {
|
||||
pagesToDisplay() {
|
||||
@@ -49,233 +49,247 @@ Vue.component('tt-table-pagination', {
|
||||
}
|
||||
return pages.length === 0 ? [1] : pages;
|
||||
}, pageInfoText() {
|
||||
const start = Math.min(this.pagination.page * this.pagination.per_page - this.pagination.per_page + 1, this.pagination.total_rows);
|
||||
const start = Math.min(this.pagination.page * this.pagination.per_page - this.pagination.per_page + 1,
|
||||
this.pagination.total_rows);
|
||||
const end = Math.min(this.pagination.page * this.pagination.per_page, this.pagination.total_rows);
|
||||
const total = this.pagination.total_rows === this.pagination.filtered_available ? this.pagination.total_rows : `${this.pagination.filtered_available} (${this.pagination.total_rows})`;
|
||||
const total = this.pagination.total_rows ===
|
||||
this.pagination.filtered_available ? this.pagination.total_rows : `${this.pagination.filtered_available} (${this.pagination.total_rows})`;
|
||||
return `${start} bis ${end} von ${total}`;
|
||||
}
|
||||
}, methods: {
|
||||
}, methods: {
|
||||
fetchRows(page) {
|
||||
this.$emit('fetch-rows', page);
|
||||
}
|
||||
}, template: `
|
||||
<div class="tt-table-pagination-container">
|
||||
<div v-if="pagination && typeof pagination.total_rows === 'number'" class="tt-table-pagination-wrapper">
|
||||
<div class="tt-table-pagination-container">
|
||||
<div v-if="pagination && typeof pagination.total_rows === 'number'"
|
||||
class="tt-table-pagination-wrapper">
|
||||
<span class="tt-table-text-center" v-text="pageInfoText"
|
||||
:style="{ 'grid-row': reverse ? 2 : 1, 'grid-column': 1 }"></span>
|
||||
|
||||
|
||||
<ul class="pagination tt-table-pagination" :style="{ 'grid-row': reverse ? 1 : 2, 'grid-column': 1 }">
|
||||
<li class="page-item tt-table-page-item" v-bind:class="{ disabled: pagination.page === 1 }">
|
||||
<a class="page-link" href="#" v-on:click.prevent="fetchRows(1)" aria-label="First">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only">First</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="page-item tt-table-page-item" v-for="pageNumber in pagesToDisplay"
|
||||
v-bind:class="{ 'active': pageNumber === pagination.page, 'disabled': pageNumber === pagination.page }">
|
||||
<a class="page-link"
|
||||
v-bind:class="{ 'active': pageNumber === pagination.page, 'disabled': pageNumber === pagination.page }"
|
||||
href="#"
|
||||
v-on:click.prevent="fetchRows(pageNumber)">{{ pageNumber }}</a>
|
||||
</li>
|
||||
<li class="page-item tt-table-page-item"
|
||||
v-bind:class="{ disabled: pagination.page === pagination.total_pages }">
|
||||
<a class="page-link" href="#" v-on:click.prevent="fetchRows(pagination.total_pages)"
|
||||
aria-label="Last">
|
||||
<span aria-hidden="true">»</span>
|
||||
<span class="sr-only">Last</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="pagination tt-table-pagination"
|
||||
:style="{ 'grid-row': reverse ? 1 : 2, 'grid-column': 1 }">
|
||||
<li class="page-item tt-table-page-item" v-bind:class="{ disabled: pagination.page === 1 }">
|
||||
<a class="page-link" href="#" v-on:click.prevent="fetchRows(1)" aria-label="First">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only">First</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="page-item tt-table-page-item" v-for="pageNumber in pagesToDisplay"
|
||||
v-bind:class="{ 'active': pageNumber === pagination.page, 'disabled': pageNumber === pagination.page }">
|
||||
<a class="page-link"
|
||||
v-bind:class="{ 'active': pageNumber === pagination.page, 'disabled': pageNumber === pagination.page }"
|
||||
href="#"
|
||||
v-on:click.prevent="fetchRows(pageNumber)">{{ pageNumber }}</a>
|
||||
</li>
|
||||
<li class="page-item tt-table-page-item"
|
||||
v-bind:class="{ disabled: pagination.page === pagination.total_pages }">
|
||||
<a class="page-link" href="#" v-on:click.prevent="fetchRows(pagination.total_pages)"
|
||||
aria-label="Last">
|
||||
<span aria-hidden="true">»</span>
|
||||
<span class="sr-only">Last</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<span class="tt-table-text-center"
|
||||
:style="{ 'grid-row': reverse ? 2 : 1, 'grid-column': 2 }">Einträge pro Seite</span>
|
||||
<span class="tt-table-text-center"
|
||||
:style="{ 'grid-row': reverse ? 2 : 1, 'grid-column': 2 }">Einträge pro Seite</span>
|
||||
|
||||
|
||||
<select v-model="pagination.per_page" v-on:change="fetchRows(1)"
|
||||
class="form-control form-control-sm tt-table-select"
|
||||
:style="{ 'grid-row': reverse ? 1 : 2, 'grid-column': 2 }">
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
<select v-model="pagination.per_page" v-on:change="fetchRows(1)"
|
||||
class="form-control form-control-sm tt-table-select"
|
||||
:style="{ 'grid-row': reverse ? 1 : 2, 'grid-column': 2 }">
|
||||
<option value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
|
||||
|
||||
Vue.component('tt-table', {
|
||||
template: `
|
||||
<div class="tt-table-container" ref="tableContainer">
|
||||
<!-- Top Buttons -->
|
||||
<div class="tt-table-top-buttons-container">
|
||||
<slot name="top-buttons"></slot>
|
||||
</div>
|
||||
<!-- Pagination Controls -->
|
||||
<nav aria-label="Page navigation">
|
||||
<div class="tt-table-top-pagination-container">
|
||||
<!-- if excelExport is true, show the export button fontawesome icon excel -->
|
||||
<div style="display:flex;align-items: center;">
|
||||
<i v-if="!Object.values(columns).every(column => column.filter === false)" title="Filter zurücksetzen"
|
||||
@click="resetTable" class="fas fa-times cursor-pointer text-danger"
|
||||
style="font-size: 24px;margin-right: 6px;cursor: pointer; color: var(--orange)"></i>
|
||||
<i v-if="excelExport" title="EXCEL Export" @click="exportToExcel" class="fa fa-file-excel"
|
||||
style="font-size: 24px;margin-right: 6px;cursor: pointer; color: var(--success)"></i>
|
||||
<h4 style="margin: 0">{{ config.tableHeader }}</h4>
|
||||
</div>
|
||||
<div class="tt-table-container" ref="tableContainer">
|
||||
<!-- Top Buttons -->
|
||||
<div class="tt-table-top-buttons-container">
|
||||
<slot name="top-buttons"></slot>
|
||||
</div>
|
||||
<!-- Pagination Controls -->
|
||||
<nav aria-label="Page navigation">
|
||||
<div class="tt-table-top-pagination-container">
|
||||
<!-- if excelExport is true, show the export button fontawesome icon excel -->
|
||||
<div style="display:flex;align-items: center;">
|
||||
<i v-if="!Object.values(columns).every(column => column.filter === false)"
|
||||
title="Filter zurücksetzen"
|
||||
@click="resetTable" class="fas fa-times cursor-pointer text-danger"
|
||||
style="font-size: 24px;margin-right: 6px;cursor: pointer; color: var(--orange)"></i>
|
||||
<i v-if="excelExport" title="EXCEL Export" @click="exportToExcel" class="fa fa-file-excel"
|
||||
style="font-size: 24px;margin-right: 6px;cursor: pointer; color: var(--success)"></i>
|
||||
<h4 style="margin: 0">{{ config.tableHeader }}</h4>
|
||||
</div>
|
||||
|
||||
<tt-table-pagination :pagination="pagination" @fetch-rows="fetchRows"
|
||||
v-if="pagination"></tt-table-pagination>
|
||||
</div>
|
||||
</nav>
|
||||
<!-- Table -->
|
||||
<table
|
||||
ref="table"
|
||||
:class="['table','tt-table','table-condensed',{ 'loading': loading },{ 'table-striped': striped },{ 'table-bordered': bordered },{ 'table-hover': hover },{ 'table-sm': small }]">
|
||||
<thead style="border-width: 2px">
|
||||
<tr>
|
||||
<th scope="col" v-for="column in columns"
|
||||
:ref="'table_header_'+column.key"
|
||||
v-if="!hiddenColumns.includes(column.key)"
|
||||
:style="'vertical-align: top; text-align: center;' +
|
||||
<tt-table-pagination :pagination="pagination" @fetch-rows="fetchRows"
|
||||
v-if="pagination"></tt-table-pagination>
|
||||
</div>
|
||||
</nav>
|
||||
<!-- Table -->
|
||||
<table
|
||||
ref="table"
|
||||
:class="['table','tt-table','table-condensed',{ 'loading': loading },{ 'table-striped': striped },{ 'table-bordered': bordered },{ 'table-hover': hover },{ 'table-sm': small }]">
|
||||
<thead style="border-width: 2px">
|
||||
<tr>
|
||||
<th scope="col" v-for="column in columns"
|
||||
:ref="'table_header_'+column.key"
|
||||
v-if="!hiddenColumns.includes(column.key)"
|
||||
:style="'vertical-align: top; text-align: center;' +
|
||||
(column.filter === 'dateRange' ? 'min-width: 260px;' : '') +
|
||||
(originalColumnWidths[column.key] ? 'width: ' + originalColumnWidths[column.key] + 'px;' : '')"
|
||||
>
|
||||
<div style="text-align:center; white-space: nowrap;word-break: keep-all;user-select: none;"
|
||||
:style="{ 'cursor': column.sortable ? 'pointer' : 'default' }"
|
||||
@click="column.sortable ? setOrder(column.key) : undefined">
|
||||
{{ column.text }}
|
||||
<i
|
||||
v-if="column.sortable"
|
||||
:class="getSortIconClass(column.key)"></i>
|
||||
</div>
|
||||
<tt-input v-if="column.filter === 'search'" sm v-model="filters[column.key]"></tt-input>
|
||||
<tt-icon-select v-else-if="column.filter === 'iconSelect'" :options="column.filterOptions"
|
||||
v-model="filters[column.key]"></tt-icon-select>
|
||||
<tt-number-range v-else-if="column.filter === 'numberRange'" :returnText="!ssr"
|
||||
v-model="filters[column.key]"></tt-number-range>
|
||||
<tt-select v-else-if="column.filter === 'select'"
|
||||
:options="[{text: 'Alle', value: undefined}, ...column.filterOptions]"
|
||||
v-model="filters[column.key]"></tt-select>
|
||||
|
||||
<tt-autocomplete v-else-if="column.filter === 'autocomplete'"
|
||||
:items="[{text: 'Alle', value: undefined}, ...column.filterOptions]"
|
||||
v-model="filters[column.key]"></tt-autocomplete>
|
||||
<tt-date-picker v-else-if="column.filter === 'date'" v-model="filters[column.key]"></tt-date-picker>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="pagination?.filtered_available === 0" style="height: 150px">
|
||||
<td :colspan="Object.keys(columns).length" :rowspan="5" class="text-center">Keine Ergebnisse!</td>
|
||||
</tr>
|
||||
<tr v-else-if="(pagination === null && ssr === true) || rows === null"
|
||||
style="height: 150px">
|
||||
<td :colspan="Object.keys(columns).length" class="text-center">Laden...</td>
|
||||
</tr>
|
||||
<template v-for="(row, index) in (ssr === false ? computedRows : rows)">
|
||||
<tr :class="typeof config.customRowClass === 'function' ? config.customRowClass(row) : ''"
|
||||
@click="$emit('row-click', row)"
|
||||
>
|
||||
<template v-for="(column, key) in columns" v-if="!hiddenColumns.includes(column.key)">
|
||||
<td :class="{ 'text-center': column.filter === 'iconSelect',
|
||||
>
|
||||
<div style="text-align:center; white-space: nowrap;word-break: keep-all;user-select: none;"
|
||||
:style="{ 'cursor': column.sortable ? 'pointer' : 'default' }"
|
||||
@click="column.sortable ? setOrder(column.key) : undefined">
|
||||
{{ column.text }}
|
||||
<i
|
||||
v-if="column.sortable"
|
||||
:class="getSortIconClass(column.key)"></i>
|
||||
</div>
|
||||
<!-- @formatter:off -->
|
||||
<tt-input v-if="column.filter === 'search'" v-model="filters[column.key]" sm/>
|
||||
<tt-icon-select v-else-if="column.filter === 'iconSelect'" :options="column.filterOptions" v-model="filters[column.key]" sm/>
|
||||
<tt-number-range v-else-if="column.filter === 'numberRange'" :returnText="!ssr" v-model="filters[column.key]" sm/>
|
||||
<tt-select v-else-if="column.filter === 'select'" :options="[{text: 'Alle', value: undefined}, ...column.filterOptions]" v-model="filters[column.key]" sm/>
|
||||
<tt-autocomplete v-else-if="column.filter === 'autocomplete'" :items="[{text: 'Alle', value: undefined}, ...column.filterOptions]" v-model="filters[column.key]" sm/>
|
||||
<tt-date-picker v-else-if="column.filter === 'date'" v-model="filters[column.key]"/>
|
||||
<!-- @formatter:on -->
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="pagination?.filtered_available === 0" style="height: 150px">
|
||||
<td :colspan="Object.keys(columns).length" :rowspan="5" class="text-center">Keine Ergebnisse!</td>
|
||||
</tr>
|
||||
<tr v-else-if="(pagination === null && ssr === true) || rows === null"
|
||||
style="height: 150px">
|
||||
<td :colspan="Object.keys(columns).length" class="text-center">Laden...</td>
|
||||
</tr>
|
||||
<template v-for="(row, index) in (ssr === false ? computedRows : rows)">
|
||||
<tr :class="typeof config.customRowClass === 'function' ? config.customRowClass(row) : ''"
|
||||
@click="$emit('row-click', row)"
|
||||
>
|
||||
<template v-for="(column, key) in columns" v-if="!hiddenColumns.includes(column.key)">
|
||||
<td :class="{ 'text-center': column.filter === 'iconSelect',
|
||||
[columns[key].class]: true,
|
||||
//'text-nowrap': !originalColumnWidths[column.key]
|
||||
}">
|
||||
<!-- If td is first of row then check isExpanded and display fas.fa-chevron-right or fas.fa-chevron-down with cursor pointer -->
|
||||
<i v-if="key === Object.keys(columns)[0] &&
|
||||
}"
|
||||
>
|
||||
<!-- If td is first of row then check isExpanded and display fas.fa-chevron-right or fas.fa-chevron-down with cursor pointer -->
|
||||
<i v-if="key === Object.keys(columns)[0] &&
|
||||
($scopedSlots.expandedRow && (typeof config.expandCondition !== 'function' || config.expandCondition(row)) || hiddenColumns.length > 0)"
|
||||
|
||||
@click.stop="toggleExpand(index)"
|
||||
:class="isExpanded(index) ? 'fas fa-chevron-down' : 'fas fa-chevron-right'"
|
||||
style="cursor: pointer;font-size: 14px;padding-right: 8px;user-select: none"></i>
|
||||
<slot :name="key.toLowerCase()" :value="row[key]" :row="row">
|
||||
@click.stop="toggleExpand(index)"
|
||||
:class="isExpanded(index) ? 'fas fa-chevron-down' : 'fas fa-chevron-right'"
|
||||
style="cursor: pointer;font-size: 14px;padding-right: 8px;user-select: none"></i>
|
||||
<slot :name="key.toLowerCase()" :value="row[key]" :row="row">
|
||||
<span
|
||||
v-if="column.filter === 'date'">{{ row[key] ? (moment.unix(row[key]).isValid() ? moment.unix(row[key]).format('DD.MM.YYYY HH:mm') : moment(row[key]).format('DD.MM.YYYY HH:mm')) : '' }}</span>
|
||||
<i v-else-if="column.filter === 'iconSelect'"
|
||||
:title="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.text"
|
||||
:class="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.icon"></i>
|
||||
<span v-else
|
||||
v-html="(column.prefix) + (row[key] === null || typeof row[key] === 'undefined' ? '' : row[key]?.toString()?.replace('\\\\n', '<br>')) + (column.suffix )"></span>
|
||||
v-if="column.filter === 'date'">{{
|
||||
row[key] ? (moment.unix(row[key])
|
||||
.isValid() ? moment.unix(row[key]).format('DD.MM.YYYY HH:mm') : moment(row[key])
|
||||
.format('DD.MM.YYYY HH:mm')) : ''
|
||||
}}</span>
|
||||
<i v-else-if="column.filter === 'iconSelect'"
|
||||
:title="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.text"
|
||||
:class="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.icon"></i>
|
||||
<span v-else-if="column.filter === 'autocomplete'">{{
|
||||
columns[key].filterOptions.find(option => option.value.toString() ===
|
||||
row[key].toString())?.text
|
||||
}}</span>
|
||||
<span v-else-if="row[key] !== null"
|
||||
v-html="(column.prefix) + (row[key] === null || typeof row[key] === 'undefined' ? '' : row[key]?.toString()?.replace('\\\\n', '<br>')) + (column.suffix )"></span>
|
||||
|
||||
</slot>
|
||||
</td>
|
||||
</template>
|
||||
</tr>
|
||||
<tr v-if="isExpanded(index) && ($scopedSlots.expandedRow|| hiddenColumns.length > 0)">
|
||||
<td :colspan="Object.keys(columns).length">
|
||||
</slot>
|
||||
</td>
|
||||
</template>
|
||||
</tr>
|
||||
<tr v-if="isExpanded(index) && ($scopedSlots.expandedRow|| hiddenColumns.length > 0)">
|
||||
<td :colspan="Object.keys(columns).length">
|
||||
|
||||
<!-- display ul with li for each column in hiddenColumns with slot name key.toLowerCase() or span with value of row[key] -->
|
||||
<ul v-if="hiddenColumns.length > 0" style="list-style-type: none;padding: 0;margin: 0;">
|
||||
<li v-for="(column, key) in columns" :key="'hiddenColumn-'+key">
|
||||
<template v-if="hiddenColumns.includes(key)">
|
||||
<strong>{{ column.text }}:</strong>
|
||||
<slot :name="key.toLowerCase()" :value="row[key]" :row="row">
|
||||
<!-- display ul with li for each column in hiddenColumns with slot name key.toLowerCase() or span with value of row[key] -->
|
||||
<ul v-if="hiddenColumns.length > 0" style="list-style-type: none;padding: 0;margin: 0;">
|
||||
<li v-for="(column, key) in columns" :key="'hiddenColumn-'+key">
|
||||
<template v-if="hiddenColumns.includes(key)">
|
||||
<strong>{{ column.text }}:</strong>
|
||||
<slot :name="key.toLowerCase()" :value="row[key]" :row="row">
|
||||
|
||||
<span
|
||||
v-if="column.filter === 'date'">{{ row[key] ? (moment.unix(row[key]).isValid() ? moment.unix(row[key]).format('DD.MM.YYYY HH:mm') : moment(row[key]).format('DD.MM.YYYY HH:mm')) : '' }}</span>
|
||||
<i v-else-if="column.filter === 'iconSelect'"
|
||||
:title="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.text"
|
||||
:class="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.icon"></i>
|
||||
<span v-else
|
||||
v-html="(column.prefix) + (row[key] === null || typeof row[key] === 'undefined' ? '' : row[key]?.toString()?.replace('\\\\n', '<br>')) + (column.suffix )">
|
||||
v-if="column.filter === 'date'">{{
|
||||
row[key] ? (moment.unix(row[key])
|
||||
.isValid() ? moment.unix(row[key]).format('DD.MM.YYYY HH:mm') : moment(row[key])
|
||||
.format('DD.MM.YYYY HH:mm')) : ''
|
||||
}}</span>
|
||||
<i v-else-if="column.filter === 'iconSelect'"
|
||||
:title="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.text"
|
||||
:class="columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.icon"></i>
|
||||
<span v-else-if="row[key] !== null"
|
||||
v-html="(column.prefix) + (row[key] === null || typeof row[key] === 'undefined' ? '' : row[key]?.toString()?.replace('\\\\n', '<br>')) + (column.suffix )">
|
||||
</span>
|
||||
</slot>
|
||||
</template>
|
||||
</li>
|
||||
</ul>
|
||||
</slot>
|
||||
</template>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<slot name="expandedRow" :row="row"></slot>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Pagination Controls -->
|
||||
<nav aria-label="Page navigation">
|
||||
<tt-table-pagination :pagination="pagination" @fetch-rows="fetchRows"
|
||||
v-if="pagination"></tt-table-pagination>
|
||||
</nav>
|
||||
</div>
|
||||
`, props: {
|
||||
fetchUrl: String,
|
||||
data: Array,
|
||||
striped: {type: Boolean, default: true},
|
||||
bordered: {type: Boolean, default: true},
|
||||
hover: {type: Boolean, default: true},
|
||||
sticky: {type: Boolean, default: true},
|
||||
small: {type: Boolean, default: true},
|
||||
excelExport: {type: Boolean, default: false},
|
||||
config: {type: Object, default: () => ({}), required: true},
|
||||
ssr: {type: Boolean, default: false},
|
||||
<slot name="expandedRow" :row="row"></slot>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Pagination Controls -->
|
||||
<nav aria-label="Page navigation">
|
||||
<tt-table-pagination :pagination="pagination" @fetch-rows="fetchRows"
|
||||
v-if="pagination"></tt-table-pagination>
|
||||
</nav>
|
||||
</div>
|
||||
`, props: {
|
||||
fetchUrl: String,
|
||||
data: Array,
|
||||
striped: {type: Boolean, default: true},
|
||||
bordered: {type: Boolean, default: true},
|
||||
hover: {type: Boolean, default: true},
|
||||
sticky: {type: Boolean, default: true},
|
||||
small: {type: Boolean, default: true},
|
||||
excelExport: {type: Boolean, default: false},
|
||||
config: {type: Object, default: () => ({}), required: true},
|
||||
ssr: {type: Boolean, default: false},
|
||||
disableInitialFetch: {type: Boolean, default: false}
|
||||
}, data() {
|
||||
return {
|
||||
window: window,
|
||||
moment: window.moment,
|
||||
loading: false,
|
||||
rows: null,
|
||||
rawRows: null,
|
||||
pagination: {},
|
||||
filters: {},
|
||||
debounceTimeout: null,
|
||||
disableDebounce: false,
|
||||
window: window,
|
||||
moment: window.moment,
|
||||
loading: false,
|
||||
rows: null,
|
||||
rawRows: null,
|
||||
pagination: {},
|
||||
filters: {},
|
||||
debounceTimeout: null,
|
||||
disableDebounce: false,
|
||||
latestFetchTimestamp: null,
|
||||
order: {
|
||||
order: {
|
||||
key: null, order: 'asc' // default sort order
|
||||
},
|
||||
expandedRows: {},
|
||||
isInitialised: false,
|
||||
hiddenColumns: [],
|
||||
expandedRows: {},
|
||||
isInitialised: false,
|
||||
hiddenColumns: [],
|
||||
originalColumnWidths: {},
|
||||
originalTableWidth: null
|
||||
originalTableWidth: null,
|
||||
debouncedHandleResize: null
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
methods: {
|
||||
/**
|
||||
* Creates a debounced function that delays invoking `fn` until after `wait` milliseconds
|
||||
* have elapsed since the last time the debounced function was invoked.
|
||||
@@ -290,7 +304,12 @@ Vue.component('tt-table', {
|
||||
if (this.debounceTimeout) clearTimeout(this.debounceTimeout);
|
||||
this.debounceTimeout = setTimeout(() => fn.apply(context, args), wait);
|
||||
}
|
||||
}, /**
|
||||
},
|
||||
refreshTable() {
|
||||
this.loading = true;
|
||||
this.fetchData(this.pagination.page).then()
|
||||
},
|
||||
/**
|
||||
* Fetches and updates data for a specified page.
|
||||
*
|
||||
* @param {number} page The page number to fetch data for.
|
||||
@@ -310,10 +329,10 @@ Vue.component('tt-table', {
|
||||
}
|
||||
|
||||
this.pagination = {
|
||||
page: page++,
|
||||
per_page: this.pagination?.per_page ? parseInt(this.pagination.per_page) : 10,
|
||||
total_rows: this.rawRows.length || 0,
|
||||
total_pages: this.rawRows.length / this.pagination?.per_page,
|
||||
page: page++,
|
||||
per_page: this.pagination?.per_page ? parseInt(this.pagination.per_page) : 10,
|
||||
total_rows: this.rawRows.length || 0,
|
||||
total_pages: this.rawRows.length / this.pagination?.per_page,
|
||||
filtered_available: this.rawRows.length
|
||||
};
|
||||
this.loading = false;
|
||||
@@ -380,7 +399,7 @@ Vue.component('tt-table', {
|
||||
// filter filters with empty values or empty objects
|
||||
filters,
|
||||
paginationPerPage: this.pagination.per_page,
|
||||
order: this.order.key ? this.order : undefined,
|
||||
order: this.order.key ? this.order : undefined,
|
||||
}));
|
||||
}, parseSettingsFromLocalStorage() {
|
||||
const settings = JSON.parse(localStorage.getItem(`tt-table-${this.config.key}`) || '{}');
|
||||
@@ -428,7 +447,9 @@ Vue.component('tt-table', {
|
||||
if (!this.columns[key]) continue;
|
||||
|
||||
if (this.columns[key] && this.columns[key].filter === 'iconSelect') {
|
||||
parsedRow[this.columns[key].text] = this.columns[key].filterOptions.find(option => option.value.toString() === row[key].toString())?.text;
|
||||
parsedRow[this.columns[key].text] =
|
||||
this.columns[key].filterOptions.find(option => option.value.toString() ===
|
||||
row[key].toString())?.text;
|
||||
} else if (this.columns[key] && this.columns[key].filter === 'date') {
|
||||
parsedRow[this.columns[key].text] = this.moment(row[key]).format('DD.MM.YYYY HH:mm');
|
||||
} else {
|
||||
@@ -472,15 +493,19 @@ Vue.component('tt-table', {
|
||||
this.disableDebounce = true;
|
||||
window.notify('success', 'Filter zurückgesetzt');
|
||||
}, toggleExpand(index) {
|
||||
this.expandedRows[index] ? this.$delete(this.expandedRows, index) : this.$set(this.expandedRows, index, true);
|
||||
this.expandedRows[index] ? this.$delete(this.expandedRows, index) : this.$set(this.expandedRows,
|
||||
index,
|
||||
true);
|
||||
}, isExpanded(index) {
|
||||
return !!this.expandedRows[index];
|
||||
},
|
||||
async handleResponsiveColumns() {
|
||||
const tableContainerComputedStyle = window.getComputedStyle(this.$refs.tableContainer);
|
||||
let viewportWidth = this.$refs.tableContainer.offsetWidth -
|
||||
parseInt(tableContainerComputedStyle.paddingLeft) -
|
||||
parseInt(tableContainerComputedStyle.paddingRight);
|
||||
if (!this.$refs.tableContainer) return;
|
||||
const tableContainer = this.$refs.tableContainer;
|
||||
const {paddingLeft, paddingRight} = window.getComputedStyle(tableContainer);
|
||||
|
||||
let viewportWidth = tableContainer.offsetWidth - parseInt(paddingLeft) - parseInt(paddingRight);
|
||||
this.originalColumnWidths = {}
|
||||
this.hiddenColumns = []
|
||||
await this.$nextTick()
|
||||
|
||||
@@ -504,8 +529,8 @@ Vue.component('tt-table', {
|
||||
}
|
||||
}
|
||||
|
||||
}, watch: {
|
||||
filters: {
|
||||
}, watch: {
|
||||
filters: {
|
||||
handler: function () {
|
||||
if (!this.isInitialised) return;
|
||||
|
||||
@@ -521,7 +546,7 @@ Vue.component('tt-table', {
|
||||
|
||||
this.saveSettingsToLocalStorage();
|
||||
}, deep: true
|
||||
}, order: {
|
||||
}, order: {
|
||||
handler: function () {
|
||||
if (!this.isInitialised) return;
|
||||
|
||||
@@ -530,21 +555,21 @@ Vue.component('tt-table', {
|
||||
}
|
||||
this.saveSettingsToLocalStorage();
|
||||
}, deep: true
|
||||
}, expandedRows: {
|
||||
}, expandedRows: {
|
||||
handler: function () {
|
||||
if (!this.isInitialised) return;
|
||||
|
||||
this.saveSettingsToLocalStorage();
|
||||
}, deep: true
|
||||
},
|
||||
rows: {
|
||||
rows: {
|
||||
handler: async function () {
|
||||
this.$nextTick(() => {
|
||||
this.handleResponsiveColumns()
|
||||
})
|
||||
}, deep: true
|
||||
},
|
||||
computedRows: {
|
||||
computedRows: {
|
||||
handler: async function () {
|
||||
this.$nextTick(() => {
|
||||
this.handleResponsiveColumns()
|
||||
@@ -565,15 +590,15 @@ Vue.component('tt-table', {
|
||||
}
|
||||
|
||||
columns[column.key] = {
|
||||
text: column.text,
|
||||
key: column.key,
|
||||
filter: column.filter !== undefined ? column.filter : 'search',
|
||||
text: column.text,
|
||||
key: column.key,
|
||||
filter: column.filter !== undefined ? column.filter : 'search',
|
||||
filterOptions: column.filterOptions || undefined,
|
||||
sortable: column.sortable !== undefined ? column.sortable : true,
|
||||
class: column.class !== undefined ? column.class : '',
|
||||
prefix: column.prefix || '',
|
||||
suffix: column.suffix || '',
|
||||
priority: column.priority + 100 || i--
|
||||
sortable: column.sortable !== undefined ? column.sortable : true,
|
||||
class: column.class !== undefined ? column.class : '',
|
||||
prefix: column.prefix || '',
|
||||
suffix: column.suffix || '',
|
||||
priority: column.priority + 100 || i--
|
||||
};
|
||||
return columns;
|
||||
}, {});
|
||||
@@ -581,7 +606,9 @@ Vue.component('tt-table', {
|
||||
}, pagesToDisplay() {
|
||||
let range = 2; // Number of pages before and after the current page
|
||||
let start = (this.pagination.page < 4 ? 1 : this.pagination.page - range);
|
||||
let end = (this.pagination.page + range > this.pagination.total_pages ? this.pagination.total_pages : this.pagination.page + range);
|
||||
let end = (this.pagination.page +
|
||||
range >
|
||||
this.pagination.total_pages ? this.pagination.total_pages : this.pagination.page + range);
|
||||
if (end < 5) end = 5;
|
||||
|
||||
// Adjust start and end if they are out of bounds
|
||||
@@ -647,10 +674,13 @@ Vue.component('tt-table', {
|
||||
if (header.filter === 'search') {
|
||||
|
||||
const isNegated = filterValue.startsWith('!');
|
||||
const substrings = (isNegated ? filterValue.slice(1) : filterValue).split(' ').map(s => s.toLowerCase());
|
||||
const substrings = (isNegated ? filterValue.slice(1) : filterValue).split(' ')
|
||||
.map(s => s.toLowerCase());
|
||||
|
||||
const targetValue = !row[header.key] ? '' :
|
||||
typeof row[header.key] === 'object' ? Object.values(row[header.key]).join(' ').toLowerCase() : row[header.key].toString().toLowerCase();
|
||||
typeof row[header.key] === 'object' ? Object.values(row[header.key])
|
||||
.join(' ')
|
||||
.toLowerCase() : row[header.key].toString().toLowerCase();
|
||||
|
||||
let substringMatch = true;
|
||||
for (var k = 0, klen = substrings.length; k < klen; ++k) {
|
||||
@@ -673,7 +703,12 @@ Vue.component('tt-table', {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
} else if (header.filter === 'select' || header.filter === 'iconSelect' || header.filter === 'autocomplete') {
|
||||
} else if (header.filter ===
|
||||
'select' ||
|
||||
header.filter ===
|
||||
'iconSelect' ||
|
||||
header.filter ===
|
||||
'autocomplete') {
|
||||
if (filterValue === '') continue;
|
||||
if (filterValue !== row[header.key]?.toString()) {
|
||||
match = false;
|
||||
@@ -682,7 +717,8 @@ Vue.component('tt-table', {
|
||||
} else if (header.filter === 'date') {
|
||||
if (!filterValue.from || !filterValue.to) continue;
|
||||
|
||||
const dateInt = row[header.key].length === 10 ? parseInt(row[header.key]) * 1000 : parseInt(row[header.key]);
|
||||
const dateInt = row[header.key].length === 10 ? parseInt(row[header.key]) *
|
||||
1000 : parseInt(row[header.key]);
|
||||
let rowDate = new Date(dateInt).getTime() / 1000;
|
||||
|
||||
if (rowDate < filterValue.from || rowDate > filterValue.to) {
|
||||
@@ -708,10 +744,12 @@ Vue.component('tt-table', {
|
||||
|
||||
output.sort((a, b) => {
|
||||
let valueA = isDateColumn ?
|
||||
new Date(a[this.order.key].length === 10 ? parseInt(a[this.order.key]) * 1000 : parseInt(a[this.order.key])).getTime() :
|
||||
new Date(a[this.order.key].length === 10 ? parseInt(a[this.order.key]) *
|
||||
1000 : parseInt(a[this.order.key])).getTime() :
|
||||
a[this.order.key] || ''
|
||||
let valueB = isDateColumn ?
|
||||
new Date(b[this.order.key].length === 10 ? parseInt(b[this.order.key]) * 1000 : parseInt(b[this.order.key])).getTime() :
|
||||
new Date(b[this.order.key].length === 10 ? parseInt(b[this.order.key]) *
|
||||
1000 : parseInt(b[this.order.key])).getTime() :
|
||||
b[this.order.key] || ''
|
||||
|
||||
if (valueA === valueB) return 0;
|
||||
@@ -757,26 +795,28 @@ Vue.component('tt-table', {
|
||||
// use header#topnav as top to stick to but if window is resized then check if header#topnav height is changed
|
||||
|
||||
const headerHeight = document.querySelector('header#topnav')?.offsetHeight || 0;
|
||||
style.innerHTML = `table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
|
||||
style.innerHTML =
|
||||
`table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
|
||||
style.id = 'tt-table-sticky-header';
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
const headerHeight = document.querySelector('header#topnav')?.offsetHeight || 0;
|
||||
style.innerHTML = `table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
|
||||
style.innerHTML =
|
||||
`table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
|
||||
})
|
||||
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener('resize', this.debounce(this.handleResponsiveColumns, 100));
|
||||
this.debouncedHandleResize = this.debounce(this.handleResponsiveColumns, 100);
|
||||
window.addEventListener('resize', this.debouncedHandleResize);
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('resize', this.debounce(this.handleResponsiveColumns, 100));
|
||||
window.removeEventListener('resize', this.debouncedHandleResize);
|
||||
}
|
||||
})
|
||||
|
||||
Vue.config.errorHandler = function(err, vm, info) {
|
||||
Vue.config.errorHandler = function (err, vm, info) {
|
||||
// still log errors to the console
|
||||
console.error(info, err, vm);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user