store filters in url query
This commit is contained in:
parent
bfee56564c
commit
99107f4583
4 changed files with 31 additions and 12 deletions
|
@ -20,8 +20,9 @@
|
||||||
class="form-control"
|
class="form-control"
|
||||||
placeholder="filter"
|
placeholder="filter"
|
||||||
:value="filters[column]"
|
:value="filters[column]"
|
||||||
@input="setFilter(column, $event.target.value)"
|
@input="changeFilter(column, $event.target.value)"
|
||||||
>
|
>
|
||||||
|
<!-- <input @change="someHandler"> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,12 +40,27 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import DataContainer from '@/mixins/data-container';
|
import DataContainer from '@/mixins/data-container';
|
||||||
|
import router from '../router';
|
||||||
|
import {mapState} from 'vuex';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Cards',
|
name: 'Cards',
|
||||||
mixins: [DataContainer],
|
mixins: [DataContainer],
|
||||||
|
created() {
|
||||||
|
this.columns.map(e => ({k: e, v: this.$store.getters.getFilters[e]})).filter(e => e.v).forEach(e => this.setFilter(e.k, e.v));
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
random: () => Math.floor((Math.random() * 500) + 300)
|
changeFilter(col, val) {
|
||||||
}
|
console.log('filter:', col, val);
|
||||||
|
this.setFilter(col, val);
|
||||||
|
let newquery = Object.entries({...this.$store.getters.getFilters, [col]: val}).reduce((a,[k,v]) => (v ? {...a, [k]:v} : a), {});
|
||||||
|
console.log(this.$store.getters.getFilters);
|
||||||
|
console.log('query:', newquery);
|
||||||
|
router.push({query: newquery});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(['route'])
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -19,6 +19,7 @@ const store = new Vuex.Store({
|
||||||
getters: {
|
getters: {
|
||||||
getEventSlug: state => state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3',
|
getEventSlug: state => state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3',
|
||||||
getActiveView: state => state.route.name || 'items',
|
getActiveView: state => state.route.name || 'items',
|
||||||
|
getFilters: state => state.route.query,
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
replaceEvents(state, events) {
|
replaceEvents(state, events) {
|
||||||
|
@ -28,7 +29,7 @@ const store = new Vuex.Store({
|
||||||
router.push({path: `/${slug}/${view}`});
|
router.push({path: `/${slug}/${view}`});
|
||||||
},
|
},
|
||||||
replaceLoadedItems(state, newItems) {
|
replaceLoadedItems(state, newItems) {
|
||||||
state.loadedItems = newItems;
|
state.loadedItems = newItems.map(e => ({...e, description: e.bezeichnung, box: e.container, uid: e.item_uid}));
|
||||||
},
|
},
|
||||||
setLayout(state, layout) {
|
setLayout(state, layout) {
|
||||||
state.layout = layout;
|
state.layout = layout;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<Table
|
<Table
|
||||||
:columns="['cid', 'name']"
|
:columns="['cid', 'name']"
|
||||||
:items="loadedBoxes"
|
:items="loadedBoxes"
|
||||||
:keyName="'item_uid'"
|
:keyName="'cid'"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,27 +3,26 @@
|
||||||
<div class="row" v-if="layout === 'table'">
|
<div class="row" v-if="layout === 'table'">
|
||||||
<div class="col-xl-8 offset-xl-2">
|
<div class="col-xl-8 offset-xl-2">
|
||||||
<Table
|
<Table
|
||||||
:columns="['iid', 'item_uid', 'bezeichnung', 'container']"
|
:columns="['uid', 'description', 'box']"
|
||||||
:items="loadedItems"
|
:items="loadedItems"
|
||||||
:keyName="'item_uid'"
|
:keyName="'uid'"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Cards
|
<Cards
|
||||||
v-if="layout === 'cards'"
|
v-if="layout === 'cards'"
|
||||||
:columns="['iid', 'item_uid', 'bezeichnung', 'container']"
|
:columns="['uid', 'description', 'box']"
|
||||||
:items="loadedItems"
|
:items="loadedItems"
|
||||||
:keyName="'item_uid'"
|
:keyName="'uid'"
|
||||||
v-slot="{ item }"
|
v-slot="{ item }"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
:src="`https://c3lf.de/api/1/thumbs/${item.file}`"
|
:src="`https://c3lf.de/api/1/thumbs/${item.file}`"
|
||||||
alt="item"
|
|
||||||
class="card-img-top img-fluid"
|
class="card-img-top img-fluid"
|
||||||
>
|
>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h6 class="card-title">{{ item.bezeichnung }}</h6>
|
<h6 class="card-title">{{ item.description }}</h6>
|
||||||
<h6 class="card-subtitle text-secondary">uid: {{ item.item_uid }} box: {{ item.container }}</h6>
|
<h6 class="card-subtitle text-secondary">uid: {{ item.uid }} box: {{ item.box }}</h6>
|
||||||
</div>
|
</div>
|
||||||
</Cards>
|
</Cards>
|
||||||
</div>
|
</div>
|
||||||
|
@ -33,10 +32,13 @@
|
||||||
import Table from '@/components/Table';
|
import Table from '@/components/Table';
|
||||||
import Cards from '@/components/Cards';
|
import Cards from '@/components/Cards';
|
||||||
import { mapState } from 'vuex';
|
import { mapState } from 'vuex';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Items',
|
name: 'Items',
|
||||||
components: { Table, Cards },
|
components: { Table, Cards },
|
||||||
computed: mapState(['loadedItems', 'layout']),
|
computed: mapState(['loadedItems', 'layout']),
|
||||||
|
methods: {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue