From 707a05f6cde09e9d677078dad7720952004ffec7 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Fri, 20 Jun 2025 12:41:20 +0200 Subject: [PATCH] Adding changes from merge_c4 branch to searchbar component --- public/js/components/searchbar/searchbar.js | 30 ++++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/public/js/components/searchbar/searchbar.js b/public/js/components/searchbar/searchbar.js index 8e1711e90..38e07388d 100644 --- a/public/js/components/searchbar/searchbar.js +++ b/public/js/components/searchbar/searchbar.js @@ -34,14 +34,14 @@ export default { template: /*html*/`
-
- +
+ - +
0){ return this.searchsettings.types.join(' / '); @@ -105,8 +106,8 @@ export default { this.searchsettings.types = this.allSearchTypes(); } // stores the search types in the localstorage, only if the newValue is also an array - if(Array.isArray(newValue)){ - localStorage.setItem('searchtypes', JSON.stringify(newValue)); + if(Array.isArray(newValue) && this.searchoptions.origin){ + localStorage.setItem(`${this.searchoptions.origin}_searchtypes`, JSON.stringify(newValue)); } this.search(); }); @@ -115,6 +116,10 @@ export default { this.settingsDropdown = new bootstrap.Collapse(this.$refs.settings, { toggle: false }); + + if (!this.searchoptions.origin){ + console.warn("No origin defined in the searchoptions for the searchbar, please define the origin property in the searchbaroptions to allow reliable storage of searchstr and searchtypes accross applications."); + } }, updated() { if(this.showresult) { @@ -126,8 +131,11 @@ export default { methods: { getSearchTypes: function () { let result = this.allSearchTypes(); - if (localStorage.getItem('searchtypes')) { - result = JSON.parse(localStorage.getItem('searchtypes')); + if (this.searchoptions.origin) { + let localStorageValue = localStorage.getItem(`${this.searchoptions.origin}_searchtypes`); + if (localStorageValue) { + result = JSON.parse(localStorageValue); + } } return result; }, @@ -139,7 +147,9 @@ export default { return allTypes; }, getSearchStr: function(){ - return sessionStorage.getItem('searchstr') ?? ''; + if (!this.searchoptions.origin) + return ''; + return sessionStorage.getItem(`${this.searchoptions.origin}_searchstr`) ?? ''; }, checkSettingsVisibility: function(event) { // hides the settings collapsible if the user clicks somewhere else