Commit 3aec8a11 authored by Marc Mautz's avatar Marc Mautz

updated filter presets handling

parent cd41ba61
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<multiselect <multiselect
:id="index" :id="index"
:ref="index" :ref="index"
:value="filterBy[index]" :value="selectedFilters[index]"
:options="getOptions(item.options)" :options="getOptions(item.options)"
:multiple="true" :multiple="true"
:hideSelected="true" :hideSelected="true"
...@@ -86,7 +86,6 @@ ...@@ -86,7 +86,6 @@
], ],
data () { data () {
return { return {
filterBy: [],
filtered: [], filtered: [],
checked: (this.filterMode === Shuffle.FilterMode.ALL), checked: (this.filterMode === Shuffle.FilterMode.ALL),
searchBy: null, searchBy: null,
...@@ -104,29 +103,43 @@ ...@@ -104,29 +103,43 @@
selectedFilters: {} selectedFilters: {}
} }
}, },
created () {},
mounted () { mounted () {
const qs = window.location.hash.split('?')[1] this.checkUrlQueryParams()
this.queryStrings = this.parseQueryString(qs) },
console.log('queryStrings', this.queryStrings) methods: {
/**
setTimeout(() => { * Check if url query params set & update filter selection
*/
checkUrlQueryParams () {
if (window.location.hash.length && window.location.hash.indexOf('?') !== -1) {
const qs = window.location.hash.split('?')[1]
this.queryStrings = this.parseQueryString(qs)
setTimeout(() => {
this.updateFilters()
}, 1500)
}
},
/**
* Set filter presets & change filter selection
*/
updateFilters () {
const refs = this.$refs const refs = this.$refs
for (const prop in refs) { for (const prop in refs) {
this.setSelectedFilters(prop, refs[prop][0], this.queryStrings[prop]) this.setFilterPresets(prop, refs[prop][0], this.queryStrings[prop])
} }
console.log('selectedFilters', this.selectedFilters) for (const key in this.selectedFilters) {
}, 500) if (this.selectedFilters.hasOwnProperty(key)) {
}, this.filterChange(this.selectedFilters[key], key)
computed: {}, }
methods: { }
},
/** /**
* Set selected filters from url query * Set filter presets
* @param {String} key * @param {String} key
* @param {String} ref * @param {String} ref
* @param {String} qs * @param {String} qs
*/ */
setSelectedFilters (key, ref, qs) { setFilterPresets (key, ref, qs) {
let filters = [] let filters = []
for (const prop in qs) { for (const prop in qs) {
if (qs.hasOwnProperty(prop)) { if (qs.hasOwnProperty(prop)) {
...@@ -137,8 +150,7 @@ ...@@ -137,8 +150,7 @@
filters.push(found) filters.push(found)
} }
} }
console.log('filters', filters) this.$set(this.selectedFilters, key, filters)
this.selectedFilters[key] = filters
}, },
/** /**
* Parse query string and return as array * Parse query string and return as array
...@@ -177,7 +189,7 @@ ...@@ -177,7 +189,7 @@
return result return result
}, },
/** /**
* Get filter options * Get available filter options
* @param options * @param options
*/ */
getOptions (options) { getOptions (options) {
...@@ -193,10 +205,7 @@ ...@@ -193,10 +205,7 @@
* @param id * @param id
*/ */
filterChange (value, id) { filterChange (value, id) {
// this.filtered[id] = value.map(a => a.label)
this.filtered[id] = value this.filtered[id] = value
console.log('filtered', this.filtered)
console.log('$refs', this.$refs)
this.$emit('filterChange', this.filtered) this.$emit('filterChange', this.filtered)
}, },
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment