From 20619311e374335d79d49336918a083644ebc827 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 08:50:27 +0100 Subject: [PATCH] Use fhcApi in Searchbar --- .../controllers/api/frontend/v1/Searchbar.php | 51 +++++++++++++++++++ application/views/system/logs/testSearch.php | 2 + public/js/api/search.js | 18 +++---- public/js/apps/TestSearch.js | 6 ++- 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Searchbar.php diff --git a/application/controllers/api/frontend/v1/Searchbar.php b/application/controllers/api/frontend/v1/Searchbar.php new file mode 100644 index 000000000..526de927c --- /dev/null +++ b/application/controllers/api/frontend/v1/Searchbar.php @@ -0,0 +1,51 @@ + self::PERM_LOGGED + ]); + + // Load the library SearchBarLib + $this->load->library('SearchBarLib'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function search() + { + $this->load->library('form_validation'); + + // Checks if the searchstr and the types parameters are in the POSTed JSON + $this->form_validation->set_rules(self::SEARCHSTR_PARAM, null, 'required'); + $this->form_validation->set_rules(self::TYPES_PARAM . '[]', null, 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithError(SearchBarLib::ERROR_WRONG_JSON, self::ERROR_TYPE_GENERAL); + + // Convert to json the result from searchbarlib->search + $result = $this->searchbarlib->search($this->input->post(self::SEARCHSTR_PARAM), $this->input->post(self::TYPES_PARAM)); + if (property_exists($result, 'error')) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->terminateWithSuccess($result); + } +} + diff --git a/application/views/system/logs/testSearch.php b/application/views/system/logs/testSearch.php index 6f33a11cb..57ed0d48a 100644 --- a/application/views/system/logs/testSearch.php +++ b/application/views/system/logs/testSearch.php @@ -4,6 +4,7 @@ 'bootstrap5' => true, 'fontawesome6' => true, 'tabulator5' => true, + 'primevue3' => true, 'axios027' => true, 'vue3' => true, 'filtercomponent' => true, @@ -15,6 +16,7 @@ 'customCSSs' => array( 'public/css/components/verticalsplit.css', 'public/css/components/searchbar.css', + 'public/css/components/primevue.css', ), 'customJSModules' => array('public/js/apps/TestSearch.js') ); diff --git a/public/js/api/search.js b/public/js/api/search.js index 8544d9fe3..e75ad9832 100644 --- a/public/js/api/search.js +++ b/public/js/api/search.js @@ -1,12 +1,10 @@ export default { - search: function(searchsettings) { - const url = FHC_JS_DATA_STORAGE_OBJECT.app_root - + 'index.ci.php/components/SearchBar/search'; - return axios.post(url, searchsettings); - }, - searchdummy: function(searchsettings) { - const url = FHC_JS_DATA_STORAGE_OBJECT.app_root - + 'public/js/apps/api/dummyapi.php/Search'; - return axios.post(url, searchsettings); - } + search(searchsettings) { + const url = '/api/frontend/v1/searchbar/search'; + return this.$fhcApi.post(url, searchsettings); + }, + searchdummy(searchsettings) { + const url = 'public/js/apps/api/dummyapi.php/Search'; + return this.$fhcApi.post(url, searchsettings); + } }; \ No newline at end of file diff --git a/public/js/apps/TestSearch.js b/public/js/apps/TestSearch.js index f2696d008..469aaeb09 100644 --- a/public/js/apps/TestSearch.js +++ b/public/js/apps/TestSearch.js @@ -2,6 +2,7 @@ import {CoreFilterCmpt} from '../components/filter/Filter.js'; import {CoreNavigationCmpt} from '../components/navigation/Navigation.js'; import CoreVerticalsplit from "../components/verticalsplit/verticalsplit.js"; import CoreSearchbar from "../components/searchbar/searchbar.js"; +import FhcApi from "../plugin/FhcApi.js"; const app = Vue.createApp({ components: { @@ -183,11 +184,12 @@ const app = Vue.createApp({ this.appSideMenuEntries = payload; }, searchfunction(searchsettings) { - return Vue.$fhcapi.Search.search(searchsettings); + return this.$fhcApi.factory.search.search(searchsettings); }, searchfunctiondummy(searchsettings) { - return Vue.$fhcapi.Search.searchdummy(searchsettings); + return this.$fhcApi.factory.search.searchdummy(searchsettings); } } }); +app.use(FhcApi) app.mount('#main');