Use fhcApi in Searchbar

This commit is contained in:
cgfhtw
2024-03-07 08:50:27 +01:00
parent 4ac46d19e9
commit 20619311e3
4 changed files with 65 additions and 12 deletions
@@ -0,0 +1,51 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
*
*/
class Searchbar extends FHCAPI_Controller
{
const SEARCHSTR_PARAM = 'searchstr';
const TYPES_PARAM = 'types';
/**
* Object initialization
*/
public function __construct()
{
// NOTE(chris): additional permission checks will be done in SearchBarLib
parent::__construct([
'search' => 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);
}
}
@@ -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')
);
+8 -10
View File
@@ -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);
}
};
+4 -2
View File
@@ -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');