mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
refactor dashboards Preset->addWidgets to (single) Preset->addWidget
This commit is contained in:
@@ -30,7 +30,7 @@ class Preset extends FHCAPI_Controller
|
|||||||
parent::__construct([
|
parent::__construct([
|
||||||
'list' => 'dashboard/admin:r',
|
'list' => 'dashboard/admin:r',
|
||||||
'getBatch' => 'dashboard/admin:r',
|
'getBatch' => 'dashboard/admin:r',
|
||||||
'addWidgets' => 'dashboard/admin:rw',
|
'addWidget' => 'dashboard/admin:rw',
|
||||||
'removeWidget' => 'dashboard/admin:rw'
|
'removeWidget' => 'dashboard/admin:rw'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -132,25 +132,29 @@ class Preset extends FHCAPI_Controller
|
|||||||
return $this->terminateWithSuccess($result);
|
return $this->terminateWithSuccess($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addWidgets()
|
public function addWidget()
|
||||||
{
|
{
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
|
|
||||||
$this->form_validation->set_rules('db', 'Dashboard', 'required');
|
$this->form_validation->set_rules('dashboard', 'Dashboard', 'required');
|
||||||
$this->form_validation->set_rules('funktion_kurzbz', 'Funktion', 'required');
|
$this->form_validation->set_rules('funktion_kurzbz', 'Funktion', 'required');
|
||||||
|
$this->form_validation->set_rules('widget[widget]', 'Widget', 'required');
|
||||||
|
|
||||||
if (!$this->form_validation->run())
|
if (!$this->form_validation->run())
|
||||||
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||||
|
|
||||||
$dashboard_kurzbz = $this->input->post('db');
|
$dashboard_kurzbz = $this->input->post('dashboard');
|
||||||
$funktion_kurzbz = $this->input->post('funktion_kurzbz');
|
$funktion_kurzbz = $this->input->post('funktion_kurzbz');
|
||||||
$widgets = $this->input->post('widgets') ?: [];
|
$widget = $this->input->post('widget');
|
||||||
|
|
||||||
|
if (!isset($widget['widgetid']))
|
||||||
|
$widget['widgetid'] = $this->dashboardlib->generateWidgetId($dashboard_kurzbz);
|
||||||
|
|
||||||
$preset = $this->dashboardlib->getPresetOrCreateEmptyPreset($dashboard_kurzbz, $funktion_kurzbz);
|
$preset = $this->dashboardlib->getPresetOrCreateEmptyPreset($dashboard_kurzbz, $funktion_kurzbz);
|
||||||
|
|
||||||
$preset_decoded = json_decode($preset->preset, true);
|
$preset_decoded = json_decode($preset->preset, true);
|
||||||
|
|
||||||
$this->dashboardlib->addWidgetsToWidgets($preset_decoded, $dashboard_kurzbz, $funktion_kurzbz, $widgets);
|
$this->dashboardlib->addWidgetsToWidgets($preset_decoded, $dashboard_kurzbz, $funktion_kurzbz, [$widget]);
|
||||||
|
|
||||||
$preset->preset = json_encode($preset_decoded);
|
$preset->preset = json_encode($preset_decoded);
|
||||||
|
|
||||||
@@ -158,7 +162,7 @@ class Preset extends FHCAPI_Controller
|
|||||||
|
|
||||||
$this->getDataOrTerminateWithError($result);
|
$this->getDataOrTerminateWithError($result);
|
||||||
|
|
||||||
$this->terminateWithSuccess($preset_decoded);
|
$this->terminateWithSuccess($widget['widgetid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeWidget()
|
public function removeWidget()
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export default {
|
|||||||
addWidgetsToPreset(params) {
|
addWidgetsToPreset(params) {
|
||||||
return {
|
return {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: 'api/frontend/v1/dashboard/admin/preset/addWidgets',
|
url: 'api/frontend/v1/dashboard/admin/preset/addWidget',
|
||||||
params
|
params
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export default {
|
|||||||
widgetAdd(section_name, widget) {
|
widgetAdd(section_name, widget) {
|
||||||
this.$refs.widgetpicker.getWidget().then(widget_id => {
|
this.$refs.widgetpicker.getWidget().then(widget_id => {
|
||||||
widget.widget = widget_id;
|
widget.widget = widget_id;
|
||||||
|
widget.id = 'loading_' + String((new Date()).valueOf());
|
||||||
delete widget.custom;
|
delete widget.custom;
|
||||||
widget.preset = 1;
|
widget.preset = 1;
|
||||||
let loading = {...widget};
|
let loading = {...widget};
|
||||||
@@ -36,15 +37,15 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
db: this.dashboard,
|
dashboard: this.dashboard,
|
||||||
funktion_kurzbz: section_name,
|
funktion_kurzbz: section_name,
|
||||||
widgets: [widget]
|
widget
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.$api
|
return this.$api
|
||||||
.call(ApiDashboardAdmin.addWidgetsToPreset(params))
|
.call(ApiDashboardAdmin.addWidgetsToPreset(params))
|
||||||
.then(result => {
|
.then(result => {
|
||||||
let newId = Object.keys(result.data[section_name].widgets).pop();
|
let newId = result.data;
|
||||||
widget.id = newId;
|
widget.id = newId;
|
||||||
widget.custom = 1;
|
widget.custom = 1;
|
||||||
this.sections.forEach(section => {
|
this.sections.forEach(section => {
|
||||||
@@ -66,34 +67,29 @@ export default {
|
|||||||
widgetUpdate(section_name, payload) {
|
widgetUpdate(section_name, payload) {
|
||||||
payload = payload[section_name];
|
payload = payload[section_name];
|
||||||
for (var k in payload) {
|
for (var k in payload) {
|
||||||
for (var i in this.sections) {
|
const section = this.sections.find(section => section.name == section_name);
|
||||||
if (this.sections[i].name == section_name) {
|
for (var wid in section.widgets) {
|
||||||
for (var wid in this.sections[i].widgets) {
|
if (section.widgets[wid].id == k) {
|
||||||
if (this.sections[i].widgets[wid].id == k) {
|
payload[k] = ObjectUtils.mergeDeep(section.widgets[wid], payload[k]);
|
||||||
payload[k] = ObjectUtils.mergeDeep(this.sections[i].widgets[wid], payload[k]);
|
// NOTE(chris): remove internal props
|
||||||
// NOTE(chris): remove internal props
|
for (var prop of ['_x', '_y', '_w', '_h', 'index', 'id'])
|
||||||
for (var prop in {_x:1,_y:1,_w:1,_h:1,index:1,id:1})
|
if (payload[k][prop])
|
||||||
if (payload[k][prop])
|
delete payload[k][prop];
|
||||||
delete payload[k][prop];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
payload[k].widgetid = k;
|
payload[k].widgetid = k;
|
||||||
delete payload[k].custom;
|
delete payload[k].custom;
|
||||||
}
|
}
|
||||||
|
this.$api
|
||||||
//TODO(manu) test
|
.call(Object.entries(payload).map(([key, widget]) => [
|
||||||
const params = {
|
key,
|
||||||
db: this.dashboard,
|
ApiDashboardAdmin.addWidgetsToPreset({
|
||||||
funktion_kurzbz: section_name,
|
dashboard: this.dashboard,
|
||||||
widgets: payload
|
funktion_kurzbz: section_name,
|
||||||
};
|
widget
|
||||||
|
})
|
||||||
return this.$api
|
]))
|
||||||
.call(ApiDashboardAdmin.addWidgetsToPreset(params))
|
|
||||||
.then(result => {
|
.then(result => {
|
||||||
this.sections.forEach(section => {
|
this.sections.forEach(section => {
|
||||||
if (section.name == section_name) {
|
if (section.name == section_name) {
|
||||||
|
|||||||
@@ -80,7 +80,10 @@ export default {
|
|||||||
payload[k].widgetid = k;
|
payload[k].widgetid = k;
|
||||||
}
|
}
|
||||||
this.$api
|
this.$api
|
||||||
.call(Object.entries(payload).map(([key, widget]) => [key, ApiDashboardUser.addWidget(this.dashboard, widget)]))
|
.call(Object.entries(payload).map(([key, widget]) => [
|
||||||
|
key,
|
||||||
|
ApiDashboardUser.addWidget(this.dashboard, widget)
|
||||||
|
]))
|
||||||
.then(result => {
|
.then(result => {
|
||||||
const failed = result
|
const failed = result
|
||||||
.filter(o => o.status == 'rejected')
|
.filter(o => o.status == 'rejected')
|
||||||
|
|||||||
Reference in New Issue
Block a user