diff --git a/application/controllers/api/frontend/v1/dashboard/Board.php b/application/controllers/api/frontend/v1/dashboard/Board.php new file mode 100644 index 000000000..c50fec128 --- /dev/null +++ b/application/controllers/api/frontend/v1/dashboard/Board.php @@ -0,0 +1,121 @@ +. + */ + +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 addresses + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Board extends FHCAPI_Controller +{ + public function __construct() + { + parent::__construct([ + 'list' => 'dashboard/admin:r', + 'create' => 'dashboard/admin:rw', + 'update' => 'dashboard/admin:rw', + 'delete' => 'dashboard/admin:rw' + ]); + + // Models + $this->load->model('dashboard/Dashboard_model', 'DashboardModel'); + } + + public function list() + { + $result = $this->DashboardModel->load(); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($result); + } + + public function create() + { + $dashboard_kurzbz = $this->input->post('dashboard_kurzbz'); + + $result = $this->DashboardModel->insert([ + 'dashboard_kurzbz' => $dashboard_kurzbz + ]); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function update() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('dashboard_id', 'Dashboard ID', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $dashboard_id = $this->input->post('dashboard_id'); + $dashboard_kurzbz = $this->input->post('dashboard_kurzbz'); + $beschreibung = $this->input->post('beschreibung'); + + $result = $this->DashboardModel->update([ + 'dashboard_id' => $dashboard_id + ], [ + 'dashboard_kurzbz' => $dashboard_kurzbz, + 'beschreibung' => $beschreibung + ]); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($result); + } + + public function delete() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('dashboard_id', 'Dashboard ID', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $dashboard_id = $this->input->post('dashboard_id'); + + //delete all presets + $this->load->model('dashboard/Dashboard_Preset_model', 'DashboardPresetModel'); + + $result = $this->DashboardPresetModel->delete([ + 'dashboard_id' => $dashboard_id + ]); + $this->getDataOrTerminateWithError($result); + + //delete all widgets + $this->load->model('dashboard/Dashboard_Widget_model', 'DashboardWidgetModel'); + + $result = $this->DashboardWidgetModel->delete([ + 'dashboard_id' => $dashboard_id + ]); + $this->getDataOrTerminateWithError($result); + + $result = $this->DashboardModel->delete($dashboard_id); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($result); + } +} diff --git a/application/controllers/api/frontend/v1/dashboard/DashboardAdmin.php b/application/controllers/api/frontend/v1/dashboard/DashboardAdmin.php deleted file mode 100644 index 414475aba..000000000 --- a/application/controllers/api/frontend/v1/dashboard/DashboardAdmin.php +++ /dev/null @@ -1,143 +0,0 @@ -. - */ - -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 addresses - * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON - */ -class DashboardAdmin extends FHCAPI_Controller -{ - public function __construct() - { - parent::__construct([ - 'getAllDashboards' => 'dashboard/admin:r', - 'createDashboard' => 'dashboard/admin:rw', - 'updateDashboard' => 'dashboard/admin:rw', - 'deleteDashboard' => 'dashboard/admin:rw' - ]); - - // Load language phrases - $this->loadPhrases([ - 'ui' - ]); - - $this->load->library('dashboard/DashboardLib', null, 'DashboardLib'); - - $this->load->model('dashboard/Dashboard_model', 'DashboardModel'); - $this->load->model('dashboard/Widget_model', 'WidgetModel'); - $this->load->model('dashboard/Dashboard_Widget_model', 'DashboardWidgetModel'); - $this->load->model('ressource/Funktion_model', 'FunktionModel'); - } - - public function getAllDashboards() - { - $result = $this->DashboardModel->load(); - - if (isError($result)) - { - return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess($result); - } - - public function createDashboard() - { - $dashboard_kurzbz = $this->input->post('dashboard_kurzbz'); - $result = $this->DashboardModel->insert( - [ - 'dashboard_kurzbz' => $dashboard_kurzbz - ] - ); - - if (isError($result)) - { - $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess((getData($result) ?: [])); - } - - public function updateDashboard() - { - $dashboard_id = $this->input->post('dashboard_id'); - $dashboard_kurzbz = $this->input->post('dashboard_kurzbz'); - $beschreibung = $this->input->post('beschreibung'); - if(!$dashboard_id) - { - $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Dashboard ID']), self::ERROR_TYPE_GENERAL); - } - - $result = $this->DashboardModel->update( - [ - 'dashboard_id' => $dashboard_id, - ], - [ - 'dashboard_kurzbz' => $dashboard_kurzbz, - 'beschreibung' => $beschreibung, - ] - ); - - if (isError($result)) - { - $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess($result); - } - - public function deleteDashboard() - { - $dashboard_id = $this->input->post('dashboard_id'); - if(!$dashboard_id) - { - return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Dashboard ID']), self::ERROR_TYPE_GENERAL); - } - - //delete all presets - $this->load->model('dashboard/Dashboard_Preset_model', 'DashboardPresetModel'); - $resultPresets = $this->DashboardPresetModel->delete( - array('dashboard_id' => $dashboard_id) - ); - if ($resultPresets === false) - { - return $this->terminateWithError($resultPresets, self::ERROR_TYPE_GENERAL); - } - - //delete all widgets - $this->load->model('dashboard/Dashboard_Widget_model', 'DashboardWidgetModel'); - - $resultWidgets = $this->DashboardWidgetModel->delete( - array('dashboard_id' => $dashboard_id) - ); - if ($resultWidgets === false) - { - return $this->terminateWithError($resultWidgets, self::ERROR_TYPE_GENERAL); - } - - $result = $this->DashboardModel->delete( - array('dashboard_id' => $dashboard_id) - ); - - if (isError($result)) - { - return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess($result); - } -} diff --git a/application/controllers/api/frontend/v1/dashboard/admin/Preset.php b/application/controllers/api/frontend/v1/dashboard/Preset.php similarity index 100% rename from application/controllers/api/frontend/v1/dashboard/admin/Preset.php rename to application/controllers/api/frontend/v1/dashboard/Preset.php diff --git a/public/js/api/factory/dashboard/dashboardAdmin.js b/public/js/api/factory/dashboard/dashboardAdmin.js index f685df485..edc53ff02 100644 --- a/public/js/api/factory/dashboard/dashboardAdmin.js +++ b/public/js/api/factory/dashboard/dashboardAdmin.js @@ -14,58 +14,58 @@ */ export default { + getAllDashboards() { + return { + method: 'get', + url: 'api/frontend/v1/dashboard/board/list' + }; + }, addDashboard(params) { return { method: 'post', - url: 'api/frontend/v1/dashboard/DashboardAdmin/createDashboard', + url: 'api/frontend/v1/dashboard/board/create', params }; }, updateDashboard(params) { return { method: 'post', - url: 'api/frontend/v1/dashboard/DashboardAdmin/updateDashboard', + url: 'api/frontend/v1/dashboard/board/update', params }; }, deleteDashboard(dashboard_id) { return { method: 'post', - url: 'api/frontend/v1/dashboard/DashboardAdmin/deleteDashboard', + url: 'api/frontend/v1/dashboard/board/delete', params: { dashboard_id } }; }, - getAllDashboards(){ - return { - method: 'get', - url: 'api/frontend/v1/dashboard/DashboardAdmin/getAllDashboards' - }; - }, loadFunktionen(dashboard_kurzbz) { return { method: 'get', - url: 'api/frontend/v1/dashboard/admin/preset/list/' + url: 'api/frontend/v1/dashboard/preset/list/' + encodeURIComponent(dashboard_kurzbz) }; }, presetBatch(params) { return { method: 'post', - url: 'api/frontend/v1/dashboard/admin/preset/getBatch', + url: 'api/frontend/v1/dashboard/preset/getBatch', params }; }, addWidgetsToPreset(params) { return { method: 'post', - url: 'api/frontend/v1/dashboard/admin/preset/addWidget', + url: 'api/frontend/v1/dashboard/preset/addWidget', params }; }, removeWidgetFromPreset(params) { return { method: 'post', - url: 'api/frontend/v1/dashboard/admin/preset/removeWidget', + url: 'api/frontend/v1/dashboard/preset/removeWidget', params }; }