Browse Source

#1906, click on header menu base reset search

bach 1 year ago
parent
commit
40b7e75d44

+ 1 - 1
web/modules/custom/materio_sapi/src/Controller/Base.php

@@ -95,7 +95,7 @@ class Base extends ControllerBase {
     }
     
     // in case of term id provided restrict the keys to taxo fields
-    if ($this->terms && count($this->terms)) {
+    if ($this->terms && is_array($this->terms) && count($this->terms)) {
       $term_conditions = $this->and_query->createConditionGroup('OR');
       // $term = (int) $this->term;
       foreach ($this->terms as $term) {

File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/main.js


BIN
web/themes/custom/materiotheme/assets/dist/main.js.gz


File diff suppressed because it is too large
+ 0 - 0
web/themes/custom/materiotheme/assets/dist/module-base.caf964cb87814d5d91ab.bundle.js


BIN
web/themes/custom/materiotheme/assets/dist/module-base.caf964cb87814d5d91ab.bundle.js.gz


BIN
web/themes/custom/materiotheme/assets/dist/module-base.e079ad7538d0d2d307c8.bundle.js.gz


+ 8 - 1
web/themes/custom/materiotheme/vuejs/components/Content/HeaderMenu.vue

@@ -54,7 +54,14 @@ export default {
       // console.log("Clicked on header menu link", event)
       const href = event.target.getAttribute('href')
       // this.openCloseHamMenu(false)
-      this.$router.push(href)
+      // this.$router.push({name:'base', query:{
+      //   keys:this.typed,
+      //   // terms:this.autocomplete.join(','),
+      //   terms: JSON.stringify(this.autocomplete),
+      //   filters:filters.join(',')
+      // }})
+      
+      this.$router.push({path: href, query: {}})
     }
   },
   render(h) {

+ 14 - 7
web/themes/custom/materiotheme/vuejs/components/Form/SearchForm.vue

@@ -123,9 +123,16 @@ export default {
   },
   watch: {
     typed(n, o){
-      console.log('watch typed changed o:' + o + ' n:' +n)
+      console.log(`watch typed changed o:(${typeof o})${o} | n:(${typeof n})${n}`, o, n)
+      // if (typeof n === 'string') {
+      //   // remove terms from autocomplete if removed from typed
+      //   const r = /,\s?$/ // remove last comma space
+      //   let tag_list = n.replace(r,'').split(', ')
+      // }else{
+      //   let tag_list = n
+      // }
       // remove terms from autocomplete if removed from typed
-      const r = /,\s?$/
+      const r = /,\s?$/ // remove last comma space
       let tag_list = n.replace(r,'').split(', ')
       console.log('watch typed tag_list', tag_list)
       console.log('watch typed autocomplete before', this.autocomplete)
@@ -136,11 +143,11 @@ export default {
         }
       });
       console.log('watch typed autocomplete after', this.autocomplete)
-    }
-    // keys(n, o){
-    //   console.log('watch keys changed', o, n)
-    //   this.typed = n
-    // },
+    },
+    keys(n, o){
+      console.log('watch keys changed', o, n)
+      this.typed = n ? n.join(', ') + ', ' : ''
+    },
     // terms(n, o){
     //   // if term change from store
     //   console.log('watch terms changed', o, n)

+ 23 - 12
web/themes/custom/materiotheme/vuejs/components/Pages/Base.vue

@@ -72,7 +72,7 @@ export default {
       this.$store.commit('Search/setKeys', keys)
       this.pagetitle = keys.join(', ') //params.get('keys')
     } else {
-      this.$store.commit('Search/setKeys', '')
+      this.$store.commit('Search/reSetKeys')
       this.pagetitle = 'Base'
     }
 
@@ -81,13 +81,13 @@ export default {
       // this.$store.commit('Search/setTerms', params.get('terms').split(','))
       this.$store.commit('Search/setTerms', JSON.parse(params.get('terms')))
     } else {
-      this.$store.commit('Search/setTerms', [])
+      this.$store.commit('Search/reSetTerms')
     }
 
     if (params.has('filters')) {
       this.$store.commit('Search/setFilters', params.get('filters').split(','))
     } else {
-      this.$store.commit('Search/setFilters', [])
+      this.$store.commit('Search/reSetFilters')
     }
 
     this.newSearch()
@@ -95,16 +95,27 @@ export default {
   beforeRouteUpdate (to, from, next) {
     // when query change launch a new search
     console.log('Base beforeRouteUpdate', to, from, next)
-
+    // todo text field of search form is not emptying on clicking on base after a search
     // this.$store.commit('Search/setKeys', to.query.keys)
-    const r = /,\s?$/
-    let keys = to.query.keys.replace(r,'').split(', ')
-    console.log('Base created, keys', keys)
-    this.$store.commit('Search/setKeys', keys)
-
-    this.$store.commit('Search/setTerms', to.query.terms)
-    this.$store.commit('Search/setFilters', to.query.filters)
-    this.pagetitle = to.query.keys
+    if (to.query.hasOwnProperty('terms')) {
+      this.$store.commit('Search/setTerms', to.query.terms)
+    }else{
+      this.$store.commit('Search/reSetTerms')
+    }
+    if (to.query.hasOwnProperty('filters')) {
+      this.$store.commit('Search/setFilters', to.query.filters)
+    }else{
+      this.$store.commit('Search/reSetFilters')
+    }
+    if (to.query.hasOwnProperty('keys')) {
+      const r = /,\s?$/
+      let keys = to.query.keys.replace(r,'').split(', ')
+      console.log('Base created, keys', keys)
+      this.$store.commit('Search/setKeys', keys)
+      this.pagetitle = to.query.keys
+    }else{
+      this.$store.commit('Search/reSetKeys')
+    }
     this.newSearch()
     next()
   },

+ 9 - 0
web/themes/custom/materiotheme/vuejs/store/modules/search.js

@@ -64,14 +64,23 @@ export default {
     setKeys (state, keys) {
       state.keys = keys
     },
+    reSetKeys (state) {
+      state.keys = ''
+    },
     setTerms (state, terms) {
       state.terms = terms
       console.log('search store setTerms', terms)
     },
+    reSetTerms (state) {
+      state.terms = []
+    },
     setFilters (state, filters) {
       console.log('store search setFilters', filters)
       state.filters = typeof filters === 'string' ? filters.split(',') : filters
     },
+    reSetFilters (state) {
+      state.filters = []
+    },
     setInfos (state, infos) {
       state.infos = infos
     },

Some files were not shown because too many files changed in this diff