From d6bdad27b2a61d3d48d90f3571de6ca8e6c289ea Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Tue, 19 Nov 2024 10:17:10 +0100 Subject: [PATCH] move room specific stuff to searchconfig, add renderif method to be able to render actions conditionally via config, remove additional prop selectedtypes --- application/views/templates/CISVUE-Header.php | 1 - public/js/apps/Cis.js | 49 ++++++++++------- public/js/components/Cis/Menu.js | 2 +- public/js/components/searchbar/action.js | 22 ++++++-- public/js/components/searchbar/actions.js | 13 ++++- public/js/components/searchbar/raum.js | 9 --- public/js/components/searchbar/searchbar.js | 55 ++++++------------- 7 files changed, 74 insertions(+), 77 deletions(-) diff --git a/application/views/templates/CISVUE-Header.php b/application/views/templates/CISVUE-Header.php index 855d10b37..9b2b27ebf 100644 --- a/application/views/templates/CISVUE-Header.php +++ b/application/views/templates/CISVUE-Header.php @@ -36,7 +36,6 @@ if (!isset($menu)) { logo-url="" avatar-url="" logout-url="" - :selectedtypes="selectedtypes" :searchbaroptions="searchbaroptions" :searchfunction="searchfunction" :menu="" diff --git a/public/js/apps/Cis.js b/public/js/apps/Cis.js index e044c8ae4..fbb83ab57 100644 --- a/public/js/apps/Cis.js +++ b/public/js/apps/Cis.js @@ -13,12 +13,8 @@ const app = Vue.createApp({ }, data: function() { return { - selectedtypes:[ - "mitarbeiter", - "raum", - "organisationunit" - ], searchbaroptions: { + cssclass: "", types: [ "mitarbeiter", "raum", @@ -38,26 +34,41 @@ const app = Vue.createApp({ }, raum: { defaultaction: { - type: "function", + type: "link", action: function(data) { - alert('raum defaultaction ' + JSON.stringify(data)); + const link= FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + '/CisVue/Cms/content/' + data.content_id; + return link; } }, childactions: [ { - label: "Raumübersicht", - icon: "fas fa-info-circle", - type: "link", - action: function(data) { - return data.infolink; - } - }, - { - label: "Raumreservierung", + label: "LV-Plan", icon: "fas fa-bookmark", type: "link", action: function(data) { - return data.booklink; + const link = FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + '/CisVue/Cms/getRoomInformation/' + data.ort_kurzbz; + return link; + } + }, + { + label: "Rauminformation", + icon: "fas fa-info-circle", + type: "link", + renderif: function(data) { + if(data.content_id === "N/A"){ + return false; + } + return true; + }, + action: function(data) { + const link= FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + '/CisVue/Cms/content/' + data.content_id; + return link; } }, ] @@ -79,10 +90,6 @@ const app = Vue.createApp({ searchfunction: function(searchsettings) { return Vue.$fhcapi.Search.search(searchsettings); }, - updatesearchtypes: function(newValues){ - this.selectedtypes= newValues; - - }, } }); app.use(FhcApi); diff --git a/public/js/components/Cis/Menu.js b/public/js/components/Cis/Menu.js index 8bb49a9bd..632967085 100644 --- a/public/js/components/Cis/Menu.js +++ b/public/js/components/Cis/Menu.js @@ -123,7 +123,7 @@ export default { - + diff --git a/public/js/components/searchbar/action.js b/public/js/components/searchbar/action.js index 699d5f8c7..f4745a08e 100644 --- a/public/js/components/searchbar/action.js +++ b/public/js/components/searchbar/action.js @@ -13,10 +13,15 @@ export default { }, emits: [ 'actionexecuted' ], template: ` - - Action - + + `, methods: { getactionhref: function() { @@ -26,6 +31,13 @@ export default { execaction: function() { this.action.action(this.res); this.$emit('actionexecuted'); - } + }, + renderif: function() { + if(this.action?.renderif === undefined) { + return true; + } + + return this.action.renderif(this.res); + } } }; \ No newline at end of file diff --git a/public/js/components/searchbar/actions.js b/public/js/components/searchbar/actions.js index ff9e25e12..0fd164cea 100644 --- a/public/js/components/searchbar/actions.js +++ b/public/js/components/searchbar/actions.js @@ -8,12 +8,14 @@ export default { emits: [ 'actionexecuted' ], template: `
`, @@ -23,6 +25,13 @@ export default { }, geticonclass: function(index) { return this.actions[index].icon; - } + }, + renderif: function(action) { + if(action?.renderif === undefined) { + return true; + } + + return action.renderif(this.res); + } } }; \ No newline at end of file diff --git a/public/js/components/searchbar/raum.js b/public/js/components/searchbar/raum.js index a1fc300fb..a0e0e464d 100644 --- a/public/js/components/searchbar/raum.js +++ b/public/js/components/searchbar/raum.js @@ -7,15 +7,6 @@ export default { action: action, actions: actions }, - created(){ - //! this should be the default action for a raum - this.actions.defaultaction = { - type: "link", - action: function(data) { - return FHC_JS_DATA_STORAGE_OBJECT.app_root+'cms/content.php?content_id='+data.content_id; - } - }; - }, emits: [ 'actionexecuted' ], template: /*html*/`
diff --git a/public/js/components/searchbar/searchbar.js b/public/js/components/searchbar/searchbar.js index a828b2cfd..de408fa77 100644 --- a/public/js/components/searchbar/searchbar.js +++ b/public/js/components/searchbar/searchbar.js @@ -6,7 +6,7 @@ import student from "./student.js"; import prestudent from "./prestudent.js"; export default { - props: [ "searchoptions", "searchfunction","selectedtypes" ], + props: [ "searchoptions", "searchfunction" ], emits: ['showSettings'], data: function() { return { @@ -33,7 +33,7 @@ export default { prestudent: prestudent }, template: /*html*/` -
@@ -55,9 +55,9 @@ export default { - + - +
Unbekannter Ergebnistyp: '{{ res.type }}'.
@@ -78,7 +78,7 @@ export default {
`, watch:{ - 'searchsettings.types'(newValue){ + 'searchsettings.types': function (newValue){ this.search(); }, }, @@ -92,36 +92,10 @@ export default { }); }, methods: { - getActionsForRoom: function(res){ - res.booklink= FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/CisVue/Cms/getRoomInformation/${res.ort_kurzbz}`; - - if(res.content_id !=="N/A"){ - res.infolink= FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/CisVue/Cms/content/${res.content_id}`; - } - - let child = this.searchoptions.actions.raum.childactions.filter((child)=>{ - if(child.label =="Rauminformation" && res.content_id =="N/A"){ - return false; - } - return true; - }); - - let computedActions = { - childactions:child, - defaultaction:this.searchoptions.actions.raum.defaultaction - } - return computedActions; - - - }, updateSearchOptions: function() { this.searchsettings.types = []; - for( const idx in this.selectedtypes ) { - this.searchsettings.types.push(this.selectedtypes[idx]); + for( const idx in this.searchoptions.types ) { + this.searchsettings.types.push(this.searchoptions.types[idx]); } }, calcSearchResultExtent: function() { @@ -135,7 +109,7 @@ export default { if( this.searchtimer !== null ) { clearTimeout(this.searchtimer); } - if( this.searchsettings.searchstr.length >= 3 ) { + if( this.searchsettings.searchstr.length >= 2 ) { this.calcSearchResultExtent(); this.searchtimer = setTimeout( this.callsearchapi, @@ -145,11 +119,16 @@ export default { this.showresult = false; } }, - callsearchapi: function() { + callsearchapi: function() { this.error = null; - this.searchresult.splice(0,this.searchresult.length); + this.searchresult.splice(0, this.searchresult.length); this.searching = true; - this.showsearchresult(); + this.showsearchresult(); + if(this.searchsettings.types.length === 0) { + this.error = 'Kein Ergebnistyp ausgewählt. Bitte mindestens einen Ergebnistyp auswählen.'; + this.searching = false; + return; + } this.searchfunction(this.searchsettings) .then(response=>{ if( response.data?.error === 1 ) { @@ -177,7 +156,7 @@ export default { window.removeEventListener('resize', this.calcSearchResultExtent); }, showsearchresult: function() { - if( this.searchsettings.searchstr.length >= 3 ) { + if( this.searchsettings.searchstr.length >= 2 ) { this.showresult = true; window.addEventListener('resize', this.calcSearchResultExtent); }