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..8cd234812 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 => { @@ -74,6 +73,10 @@ export default { for (var wid in this.sections[i].widgets) { if (this.sections[i].widgets[wid].id == k) { payload[k] = ObjectUtils.mergeDeep(this.sections[i].widgets[wid], payload[k]); + // NOTE(chris): remove internal props + for (var prop in {_x:1,_y:1,_w:1,_h:1,index:1,id:1}) + if (payload[k][prop]) + delete payload[k][prop]; break; } } @@ -84,7 +87,6 @@ export default { } axios.post(this.apiurl + '/Config/addWidgetsToUserOverride', { db: this.dashboard, - uid: 'ma0168', funktion_kurzbz: section_name, widgets: payload }).then(result => { @@ -92,14 +94,15 @@ export default { if (section.name == section_name) { section.widgets.forEach((widget, i) => { if (payload[widget.id]) { - // TODO(chris): revert placement on failure - delete payload[widget.id].place; // TODO(chris): find out why overwriting place bugs out - section.widgets[i] = {...widget, ...payload[widget.id]}; + payload[widget.id].id = widget.id; + payload[widget.id].index = widget.index; + section.widgets[i] = payload[widget.id]; } }); } }); }).catch(error => { + // TODO(chris): revert placement on failure console.error('ERROR: ', error); alert('ERROR: ' + error.response.data.retval); }); @@ -107,7 +110,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 +126,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) { diff --git a/public/js/components/Dashboard/Section.js b/public/js/components/Dashboard/Section.js index 382c83c7a..27ac148d4 100644 --- a/public/js/components/Dashboard/Section.js +++ b/public/js/components/Dashboard/Section.js @@ -11,6 +11,7 @@ export default { editMode: 0, gridXLast: 0, gridYLast: 0, + dataTransfer: {} }), props: [ "name", @@ -161,10 +162,12 @@ export default { evt.dataTransfer.dropEffect = 'move'; evt.dataTransfer.effectAllowed = 'move'; - evt.dataTransfer.setData('itemAction', 'm'); - evt.dataTransfer.setData('itemId', item.index); - evt.dataTransfer.setData('itemW', this.itemCoords[item.index].w); - evt.dataTransfer.setData('itemH', this.itemCoords[item.index].h); + this.dataTransfer = { + action: 'm', + id: item.index, + w: this.itemCoords[item.index].w, + h: this.itemCoords[item.index].h + } }, startResize(evt, item) { this.gridXLast = -1; @@ -175,10 +178,12 @@ export default { evt.dataTransfer.setDragImage(evt.target, -99999, -99999); evt.dataTransfer.dropEffect = 'move'; evt.dataTransfer.effectAllowed = 'move'; - evt.dataTransfer.setData('itemAction', 'r'); - evt.dataTransfer.setData('itemId', item.index); - evt.dataTransfer.setData('itemX', this.itemCoords[item.index].x); - evt.dataTransfer.setData('itemY', this.itemCoords[item.index].y); + this.dataTransfer = { + action: 'r', + id: item.index, + x: this.itemCoords[item.index].x, + y: this.itemCoords[item.index].y + } }, occupyFields(id, x, y, w, h) { var c; @@ -225,7 +230,7 @@ export default { }, onDragOver(evt) { let id, x, y, w, h; - const action = evt.dataTransfer.getData('itemAction'); + const action = this.dataTransfer.action; const rect = this.containerRect; const gridX = Math.floor(this.gridWidth * (evt.clientX - rect.left) / this.$refs.container.clientWidth); const gridY = Math.floor(this.gridHeight * (evt.clientY - rect.top) / this.$refs.container.clientHeight); @@ -236,22 +241,22 @@ export default { this.gridYLast = gridY; if (action == 'm') { - x = gridX + 1; - y = gridY + 1; - w = parseInt(evt.dataTransfer.getData('itemW')); - h = parseInt(evt.dataTransfer.getData('itemH')); + x = Math.max(gridX + 1, 1); + y = Math.max(gridY + 1, 1); + w = parseInt(this.dataTransfer.w); + h = parseInt(this.dataTransfer.h); if (x + w > this.gridWidth + 1) x = this.gridWidth + 1 - w; - id = evt.dataTransfer.getData('itemID'); + id = this.dataTransfer.id; this.occupyFields(id, x, y, w, h); this.itemCoords[id].x = x; this.itemCoords[id].y = y; } else if (action == 'r') { - x = parseInt(evt.dataTransfer.getData('itemX')); - y = parseInt(evt.dataTransfer.getData('itemY')); + x = parseInt(this.dataTransfer.x); + y = parseInt(this.dataTransfer.y); w = gridX + 2 - x; h = gridY + 2 - y; w = Math.max(1, w); @@ -260,7 +265,7 @@ export default { if (x + w > this.gridWidth + 1) w = this.gridWidth + 1 - x; - id = evt.dataTransfer.getData('itemID'); + id = this.dataTransfer.id; let widget = CachedWidgetLoader.getWidget(this.items[id].widget); if (widget) { let minmaxW = widget.setup.width; @@ -303,9 +308,9 @@ export default { } } - id = evt.dataTransfer.getData('itemId'); + id = this.dataTransfer.id; - const action = evt.dataTransfer.getData('itemAction'); + const action = this.dataTransfer.action; update[this.items[id].id] = {place:{}}; update[this.items[id].id].place[this.gridWidth] = {};