mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
use absoluteJsImportUrl in Dashboard Widget Api Endpoints, send widget setup and arguments column values as json to frontend, remove JSON.parse from frontend dashboard code
This commit is contained in:
@@ -33,19 +33,26 @@ class Widget extends Auth_Controller
|
||||
return $this->outputJsonSuccess([
|
||||
"widget_id" => 0,
|
||||
"widget_kurzbz" => "notfound",
|
||||
"arguments" => json_encode([
|
||||
"arguments" => [
|
||||
"className" => 'alert-danger',
|
||||
"title" => 'Widget Not Found',
|
||||
"msg" => 'The widget with the id ' . $widget_id . ' could not be found'
|
||||
]),
|
||||
"setup" => json_encode([
|
||||
],
|
||||
"setup" => [
|
||||
"name" => 'Widget Not Found',
|
||||
"file" => 'DashboardWidget/Default.js',
|
||||
"file" => absoluteJsImportUrl('public/js/components/DashboardWidget/Default.js'),
|
||||
"width" => 1,
|
||||
"height" => 1
|
||||
])
|
||||
]
|
||||
]);
|
||||
return $this->outputJsonSuccess(current(getData($widget)));
|
||||
|
||||
$widget = current(getData($widget));
|
||||
$widget->arguments = json_decode($widget->arguments);
|
||||
$tmpsetup = json_decode($widget->setup);
|
||||
$tmpsetup->file = absoluteJsImportUrl($tmpsetup->file);
|
||||
$widget->setup = $tmpsetup;
|
||||
|
||||
return $this->outputJsonSuccess($widget);
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
@@ -56,7 +63,16 @@ class Widget extends Auth_Controller
|
||||
if (isError($result))
|
||||
return $this->outputJsonError(getError($result));
|
||||
|
||||
$this->outputJsonSuccess(getData($result) ?: []);
|
||||
$tmpwidgets = getData($result) ?: [];
|
||||
$widgets = array_map(function($widget) {
|
||||
$widget->arguments = json_decode($widget->arguments);
|
||||
$tmpsetup = json_decode($widget->setup);
|
||||
$tmpsetup->file = absoluteJsImportUrl($tmpsetup->file);
|
||||
$widget->setup = $tmpsetup;
|
||||
return $widget;
|
||||
}, $tmpwidgets);
|
||||
|
||||
$this->outputJsonSuccess($widgets);
|
||||
}
|
||||
|
||||
public function getWidgetsForDashboard()
|
||||
@@ -71,7 +87,16 @@ class Widget extends Auth_Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$this->outputJsonSuccess(getData($result) ?: []);
|
||||
$tmpwidgets = getData($result) ?: [];
|
||||
$widgets = array_map(function($widget) {
|
||||
$widget->arguments = json_decode($widget->arguments);
|
||||
$tmpsetup = json_decode($widget->setup);
|
||||
$tmpsetup->file = absoluteJsImportUrl($tmpsetup->file);
|
||||
$widget->setup = $tmpsetup;
|
||||
return $widget;
|
||||
}, $tmpwidgets);
|
||||
|
||||
$this->outputJsonSuccess($widgets);
|
||||
}
|
||||
|
||||
public function setAllowed()
|
||||
|
||||
@@ -151,10 +151,6 @@ export default {
|
||||
db: this.dashboard
|
||||
}
|
||||
}).then(res => {
|
||||
res.data.retval.forEach(widget => {
|
||||
widget.arguments = JSON.parse(widget.arguments);
|
||||
widget.setup = JSON.parse(widget.setup);
|
||||
});
|
||||
this.widgets = res.data.retval;
|
||||
}).catch(err => console.error('ERROR:', err));
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ export default {
|
||||
},
|
||||
async created() {
|
||||
this.widget = await CachedWidgetLoader.loadWidget(this.id);
|
||||
let component = (await import("../" + this.widget.setup.file)).default;
|
||||
let component = (await import(this.widget.setup.file)).default;
|
||||
this.$options.components["widget" + this.widget.widget_id] = component;
|
||||
this.component = "widget" + this.widget.widget_id;
|
||||
this.arguments = { ...this.widget.arguments, ...this.config };
|
||||
|
||||
@@ -16,8 +16,6 @@ export default {
|
||||
|
||||
__widgetsStarted[id] = new Promise((resolve, reject) => {
|
||||
axios.get(__path, {params:{id}}).then(res => {
|
||||
res.data.retval.arguments = JSON.parse(res.data.retval.arguments);
|
||||
res.data.retval.setup = JSON.parse(res.data.retval.setup);
|
||||
__widgets[id] = res.data.retval;
|
||||
__widgetsStarted[id] = undefined;
|
||||
resolve(__widgets[id]);
|
||||
|
||||
Reference in New Issue
Block a user