Cleanup & uid from AuthLib

This commit is contained in:
cgfhtw
2022-10-13 08:43:08 +02:00
parent 6570c958b3
commit fd2aa8a1bb
3 changed files with 6 additions and 171 deletions
+5 -77
View File
@@ -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);
}
}
@@ -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.'));
}
}
+1 -5
View File
@@ -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) {