diff --git a/application/controllers/api/frontend/v1/stv/Favorites.php b/application/controllers/api/frontend/v1/Favorites.php similarity index 78% rename from application/controllers/api/frontend/v1/stv/Favorites.php rename to application/controllers/api/frontend/v1/Favorites.php index 951eb01a4..787163abb 100644 --- a/application/controllers/api/frontend/v1/stv/Favorites.php +++ b/application/controllers/api/frontend/v1/Favorites.php @@ -20,8 +20,8 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** * This controller operates between (interface) the JS (GUI) and the back-end - * Provides data to the ajax get calls about favorite verbände - * Listens to ajax post calls to change the favorite verbände data + * Provides data to the ajax get calls about favorite treemenu entries + * Listens to ajax post calls to change the favorite treemenu entries * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON */ class Favorites extends FHCAPI_Controller @@ -29,7 +29,7 @@ class Favorites extends FHCAPI_Controller public function __construct() { parent::__construct([ - 'index' => self::PERM_LOGGED, + 'get' => self::PERM_LOGGED, 'set' => self::PERM_LOGGED ]); @@ -37,19 +37,19 @@ class Favorites extends FHCAPI_Controller $this->load->model('system/Variable_model', 'VariableModel'); } - public function index() + public function get($app) { - $result = $this->VariableModel->getVariables(getAuthUID(), ['stv_favorites']); + $result = $this->VariableModel->getVariables(getAuthUID(), [$app . '_favorites']); $data = $this->getDataOrTerminateWithError($result); if (!$data) $this->terminateWithSuccess(null); else - $this->terminateWithSuccess($data['stv_favorites'] ?? null); + $this->terminateWithSuccess($data[$app . '_favorites'] ?? null); } - public function set() + public function set($app) { $this->load->library('form_validation'); @@ -60,7 +60,7 @@ class Favorites extends FHCAPI_Controller $favorites = $this->input->post('favorites'); - $result = $this->VariableModel->setVariable(getAuthUID(), 'stv_favorites', $favorites); + $result = $this->VariableModel->setVariable(getAuthUID(), $app . '_favorites', $favorites); $this->getDataOrTerminateWithError($result); diff --git a/public/js/api/factory/treemenu.js b/public/js/api/factory/treemenu.js index da5ce8a55..d8b0c1072 100644 --- a/public/js/api/factory/treemenu.js +++ b/public/js/api/factory/treemenu.js @@ -30,16 +30,16 @@ export default { }, // TODO(chris): handle favorites per config favorites: { - get() { + get(config) { return { method: 'get', - url: 'api/frontend/v1/stv/favorites' + url: 'api/frontend/v1/favorites/get/' + config }; }, - set(favorites) { + set(config, favorites) { return { method: 'post', - url: 'api/frontend/v1/stv/favorites/set', + url: 'api/frontend/v1/favorites/set/' + config, params: { favorites } }; } diff --git a/public/js/components/Base/Treemenu.js b/public/js/components/Base/Treemenu.js index 7347260e0..5fe46606c 100644 --- a/public/js/components/Base/Treemenu.js +++ b/public/js/components/Base/Treemenu.js @@ -224,6 +224,7 @@ export default { this.favorites.on = !this.favorites.on; this.$api .call(ApiTreemenu.favorites.set( + this.config, JSON.stringify(this.favorites) )); }, @@ -238,6 +239,7 @@ export default { this.$api .call(ApiTreemenu.favorites.set( + this.config, JSON.stringify(this.favorites) )); }, @@ -272,7 +274,7 @@ export default { .catch(this.$fhcAlert.handleSystemError); this.$api - .call(ApiTreemenu.favorites.get()) + .call(ApiTreemenu.favorites.get(this.config)) .then(result => { if (result.data) { this.favorites = JSON.parse(result.data);