From fd2aa8a1bbb3bbd87534e3917d1bf10279914b14 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 13 Oct 2022 08:43:08 +0200 Subject: [PATCH] Cleanup & uid from AuthLib --- application/controllers/dashboard/Config.php | 82 ++---------------- application/controllers/dashboard/Widget.php | 89 -------------------- public/js/components/Dashboard/Dashboard.js | 6 +- 3 files changed, 6 insertions(+), 171 deletions(-) diff --git a/application/controllers/dashboard/Config.php b/application/controllers/dashboard/Config.php index ae177091e..f7736f329 100644 --- a/application/controllers/dashboard/Config.php +++ b/application/controllers/dashboard/Config.php @@ -22,13 +22,14 @@ class Config extends Auth_Controller ); $this->load->library('dashboard/DashboardLib', null, 'DashboardLib'); + $this->load->library('AuthLib', null, 'AuthLib'); } public function index() { $dashboard_kurzbz = $this->input->get('db'); - $uid = $this->input->get('uid'); - + $uid = $this->AuthLib->getAuthObj()->username; + $dashboard = $this->DashboardLib->getDashboardByKurzbz($dashboard_kurzbz); if(!$dashboard) { http_response_code(404); @@ -113,7 +114,7 @@ class Config extends Auth_Controller $input = json_decode($this->input->raw_input_stream); $dashboard_kurzbz = $input->db; $funktion_kurzbz = $input->funktion_kurzbz; - $uid = $input->uid; + $uid = $this->AuthLib->getAuthObj()->username; $override = $this->DashboardLib->getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $uid); @@ -138,7 +139,7 @@ class Config extends Auth_Controller $input = json_decode($this->input->raw_input_stream); $dashboard_kurzbz = $input->db; $funktion_kurzbz = $input->funktion_kurzbz; - $uid = $input->uid; + $uid = $this->AuthLib->getAuthObj()->username; $widgetid = $input->widgetid; $override = $this->DashboardLib->getOverride($dashboard_kurzbz, $uid); @@ -167,77 +168,4 @@ class Config extends Auth_Controller $this->outputJsonSuccess(array('msg' => 'override successfully updated.')); } - public function dummy() - { - $defaultconfig = array( - 'title' => 'CIS Dashboard', - 'widgets' => array( - 'nofunction' => array( - 'd39ba153ac9e60a21ed694cc3728f4dd' => array( - 'title' => 'test1', - 'type' => 'kpi', - 'config' => array(), - 'place' => array( - 'row' => 1, - 'col' => 3, - 'width' => 1, - 'height' => 1 - ) - ), - 'c6c526b78a0e4bc3a0b67e00f983fc33' => array( - 'title' => 'test2', - 'type' => 'url', - 'config' => array(), - 'place' => array( - 'row' => 3, - 'col' => 1, - 'width' => 1, - 'height' => 1 - ) - ), - ), - 'leitung' => array( - '3f1ebb24bdaa2b82fbdacf7d55977412' => array( - 'title' => 'test3', - 'type' => 'chart', - 'config' => array(), - 'place' => array( - 'row' => 2, - 'col' => 1, - 'width' => 3, - 'height' => 3 - ) - ) - ) - ) - ); - - $userconfig = array( - 'widgets' => array( - 'nofunction' => array( - 'd39ba153ac9e60a21ed694cc3728f4dd' => array( - 'modifier' => 'bold', - 'visible' => false, - 'place' => array( - 'width' => 2, - 'height' => 2 - ) - ), - 'c6c526b78a0e4bc3a0b67e00f983fc33' => array( - 'type' => 'test' - ) - ) - ) - ); - - $merged = array_replace_recursive($defaultconfig, $userconfig); - - $ret = array( - 'defaultconfig' => $defaultconfig, - 'userconfig' => $userconfig, - 'merged' => $merged - ); - - $this->outputJsonSuccess($ret); - } } diff --git a/application/controllers/dashboard/Widget.php b/application/controllers/dashboard/Widget.php index 6f5bd6a6c..6f900fcc9 100644 --- a/application/controllers/dashboard/Widget.php +++ b/application/controllers/dashboard/Widget.php @@ -76,93 +76,4 @@ class Widget extends Auth_Controller $this->outputJsonSuccess(getData($result)); } - public function addWidgetToUserOverride() - { - $input = json_decode($this->input->raw_input_stream); - $dashboard_kurzbz = $input->db; - $uid = $input->uid; - $funktion = $input->funktion; - - $override = $this->DashboardLib->getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $uid); - - $override_decoded = json_decode($override->override, true); - $widgetid = isset($input->widgetid) ? array('widgetid' => $input->widgetid) - : $this->DashboardLib->generateWidgetId($dashboard_kurzbz); - - $override_decoded[$funktion][$widgetid['widgetid']] = $input->widget; - - $override->override = json_encode($override_decoded); - - $result = $this->DashboardLib->insertOrUpdateOverride($override); - if( isError($result) ) { - http_response_code(500); - $this->terminateWithJsonError('override could not be saved'); - } - - $this->outputJsonSuccess($widgetid['widgetid']); - } - - public function updateWidgetsToUserOverride() - { - $input = json_decode($this->input->raw_input_stream, true); - $dashboard_kurzbz = $input['db']; - $uid = $input['uid']; - $funktion = $input['funktion']; - - $override = $this->DashboardLib->getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $uid); - - $override_decoded = json_decode($override->override, true); - if ($override_decoded[$funktion]) - $override_decoded[$funktion] = array_replace_recursive($override_decoded[$funktion], $input['widgets']); - else - $override_decoded[$funktion] = $input['widgets']; - - $override->override = json_encode($override_decoded); - - $result = $this->DashboardLib->insertOrUpdateOverride($override); - if( isError($result) ) { - http_response_code(500); - $this->terminateWithJsonError('override could not be saved'); - } - - $this->outputJsonSuccess(['msg' => 'override successfully updated.']); - } - - public function removeWidgetFromUserOverride() - { - $input = json_decode($this->input->raw_input_stream); - $dashboard_kurzbz = $input->db; - $uid = $input->uid; - $funktion = $input->funktion; - $widgetid = $input->widgetid; - - $override = $this->DashboardLib->getOverride($dashboard_kurzbz, $uid); - if( empty($override) ) { - http_response_code(404); - $this->terminateWithJsonError('userconfig for dashboard ' - . $dashboard_kurzbz . ' not found.'); - } - - $override_decoded = json_decode($override->override, true); - - if( array_key_exists($widgetid, $override_decoded[$funktion]) ) - { - unset($override_decoded[$funktion][$widgetid]); - } - else - { - http_response_code(404); - $this->terminateWithJsonError('widgetid ' . $widgetid . ' not found in funktion ' . $funktion); - } - - $override->override = json_encode($override_decoded); - $result = $this->DashboardLib->insertOrUpdateOverride($override, $uid); - if( isError($result) ) - { - http_response_code(500); - $this->terminateWithJsonError('failed to remove widget'); - } - $this->outputJsonSuccess(array('msg' => 'override successfully updated.')); - } - } diff --git a/public/js/components/Dashboard/Dashboard.js b/public/js/components/Dashboard/Dashboard.js index 1b7183576..7bc31be27 100644 --- a/public/js/components/Dashboard/Dashboard.js +++ b/public/js/components/Dashboard/Dashboard.js @@ -43,7 +43,6 @@ export default { this.tmpCreate.widget.widget = widget; axios.post(this.apiurl + '/Config/addWidgetsToUserOverride', { db: this.dashboard, - uid: 'ma0168', funktion_kurzbz: this.tmpCreate.section_name, widgets: [this.tmpCreate.widget] }).then(result => { @@ -84,7 +83,6 @@ export default { } axios.post(this.apiurl + '/Config/addWidgetsToUserOverride', { db: this.dashboard, - uid: 'ma0168', funktion_kurzbz: section_name, widgets: payload }).then(result => { @@ -107,7 +105,6 @@ export default { widgetRemove(section_name, id) { axios.post(this.apiurl + '/Config/removeWidgetFromUserOverride', { db: this.dashboard, - uid: 'ma0168', funktion_kurzbz: section_name, widgetid: id }).then(result => { @@ -124,8 +121,7 @@ export default { created() { CachedWidgetLoader.setPath(this.apiurl + '/Widget'); axios.get(this.apiurl + '/Config', {params:{ - db: this.dashboard, - uid: 'ma0168' + db: this.dashboard }}).then(res => { //console.log(res.data.retval); for (var name in res.data.retval.widgets) {