From a71ead0a851161d2235892045c91eae411d2aab0 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 13 Oct 2022 14:38:03 +0200 Subject: [PATCH] Ajax update: better data consistency --- public/js/components/Dashboard/Dashboard.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/public/js/components/Dashboard/Dashboard.js b/public/js/components/Dashboard/Dashboard.js index 7bc31be27..8cd234812 100644 --- a/public/js/components/Dashboard/Dashboard.js +++ b/public/js/components/Dashboard/Dashboard.js @@ -73,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; } } @@ -90,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); });