diff --git a/application/controllers/dashboard/Widget.php b/application/controllers/dashboard/Widget.php index 0da6fe8da..9966ddc12 100644 --- a/application/controllers/dashboard/Widget.php +++ b/application/controllers/dashboard/Widget.php @@ -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() diff --git a/public/js/components/Dashboard/Dashboard.js b/public/js/components/Dashboard/Dashboard.js index 3d781ac72..652a2778e 100644 --- a/public/js/components/Dashboard/Dashboard.js +++ b/public/js/components/Dashboard/Dashboard.js @@ -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)); diff --git a/public/js/components/Dashboard/Item.js b/public/js/components/Dashboard/Item.js index d2ad4ae75..06a03ae3a 100644 --- a/public/js/components/Dashboard/Item.js +++ b/public/js/components/Dashboard/Item.js @@ -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 }; diff --git a/public/js/composables/Dashboard/CachedWidgetLoader.js b/public/js/composables/Dashboard/CachedWidgetLoader.js index 3ebe6ddcb..a92e3e557 100644 --- a/public/js/composables/Dashboard/CachedWidgetLoader.js +++ b/public/js/composables/Dashboard/CachedWidgetLoader.js @@ -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]);