diff --git a/public/js/components/searchbar/searchbar.js b/public/js/components/searchbar/searchbar.js index fd19a22ab..86602bec2 100644 --- a/public/js/components/searchbar/searchbar.js +++ b/public/js/components/searchbar/searchbar.js @@ -10,6 +10,18 @@ import mergedStudent from "./result/mergedstudent.js"; import mergedPerson from "./result/mergedperson.js"; export default { + components: { + person, + room, + employee, + organisationunit, + student, + prestudent, + dms, + cms, + mergedStudent, + mergedPerson + }, props: [ "searchoptions", "searchfunction" ], provide() { return { @@ -22,7 +34,7 @@ export default { hidetimer: null, searchsettings: { searchstr: this.getSearchStr(), - types: this.getSearchTypes(), + types: this.getInitiallySelectedTypes(), }, searchresult: [], searchmode: '', @@ -34,17 +46,31 @@ export default { lastQuery: '' }; }, - components: { - person, - room, - employee, - organisationunit, - student, - prestudent, - dms, - cms, - mergedStudent, - mergedPerson + computed:{ + searchTypesPlaceholder() { + if (!this.searchsettings.types.length) { + return Object.values(this.typeLabels).join(' / '); + } + return this.searchsettings.types.map(type => this.typeLabels[type]).join(' / '); + }, + types() { + if (!this.searchoptions.types) + return []; + if (Array.isArray(this.searchoptions.types)) + return this.searchoptions.types; + return Object.keys(this.searchoptions.types); + }, + typeLabels() { + if (!this.searchoptions.types) + return {}; + if (Array.isArray(this.searchoptions.types)) { + return this.searchoptions.types.reduce((res, type) => { + res[type] = type; + return res + }, {}); + } + return this.searchoptions.types; + } }, template: /*html*/`
-
-
- {{ $p.t('search/applyfilter_label') }} - -
+ class="top-100 end-0 searchbar_settings text-white collapse" + tabindex="-1" + > +
+ + {{ $p.t('search/applyfilter_label') }} + + +
- - + `, watch:{ 'searchsettings.searchstr': function (newSearchValue) { @@ -146,28 +195,16 @@ export default { sessionStorage.setItem(`${this.searchoptions.origin}_searchstr`,newSearchValue); } }, - }, - computed:{ - search_types_string(){ - if (Array.isArray(this.searchsettings.types) && this.searchsettings.types.length > 0){ - return this.searchsettings.types.join(' / '); - }else{ - return JSON.stringify(this.searchsettings.types); - } - }, - - }, - beforeMount: function() { - this.$watch('searchsettings.types', newValue => { - if (Array.isArray(newValue) && newValue.length === 0){ - this.searchsettings.types = this.allSearchTypes(); + 'searchsettings.types'(newValue) { + if (Array.isArray(newValue) && newValue.length === 0) { + this.searchsettings.types = [...this.types]; } // stores the search types in the localstorage, only if the newValue is also an array - if(Array.isArray(newValue) && this.searchoptions.origin){ + if (Array.isArray(newValue) && this.searchoptions.origin) { localStorage.setItem(`${this.searchoptions.origin}_searchtypes`, JSON.stringify(newValue)); } this.search(); - }); + } }, mounted(){ this.settingsDropdown = new bootstrap.Collapse(this.$refs.settings, { @@ -191,22 +228,21 @@ export default { this.hideresult(); this.$refs.input.focus() }, - getSearchTypes: function () { - let result = this.allSearchTypes(); + getInitiallySelectedTypes() { + let result = false; if (this.searchoptions.origin) { let localStorageValue = localStorage.getItem(`${this.searchoptions.origin}_searchtypes`); if (localStorageValue) { result = JSON.parse(localStorageValue); } } - return result; - }, - allSearchTypes() { - let allTypes = []; - for (const idx in this.searchoptions.types) { - allTypes.push(this.searchoptions.types[idx]); - }; - return allTypes; + if (result) + return result; + if (!this.searchoptions.types) + return []; + if (Array.isArray(this.searchoptions.types)) + return [...this.searchoptions.types]; + return Object.keys(this.searchoptions.types); }, getSearchStr: function(){ if (!this.searchoptions.origin)