From 875bc7418bfd84dfc50c3ef5b8d560010bdf4fc0 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 19 Dec 2024 17:59:28 +0200 Subject: [PATCH] fix dashboard --- client/src/views/dashboard.js | 45 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/client/src/views/dashboard.js b/client/src/views/dashboard.js index ae8da55431..ad248f5578 100644 --- a/client/src/views/dashboard.js +++ b/client/src/views/dashboard.js @@ -48,6 +48,18 @@ class DashboardView extends View { WIDTH_MULTIPLIER = 3 HEIGHT_MULTIPLIER = 4 + /** + * @private + * @type {Object.|null} + */ + preservedDashletViews = null + + /** + * @private + * @type {Object.|null} + */ + preservedDashletElements = null + events = { /** @this DashboardView */ 'click button[data-action="selectTab"]': function (e) { @@ -225,24 +237,39 @@ class DashboardView extends View { this.preservedDashletViews[o.id] = view; - const $el = view.$el.children(0); + const element = view.element; - this.preservedDashletElements[o.id] = $el; + this.preservedDashletElements[o.id] = element; - $el.detach(); + const parent = element.parentNode; + parent.removeChild(element); }); } /** * @param {string} id */ - addPreservedDashlet(id) { + async addPreservedDashlet(id) { + /** @type {import('view').default} */ const view = this.preservedDashletViews[id]; - const $el = this.preservedDashletElements[id]; + /** @type {HTMLElement} */ + const element = this.preservedDashletElements[id]; - this.$el.find(`.dashlet-container[data-id="${id}"]`).append($el); + if (!element || !view) { + return; + } - this.setView(`dashlet-${id}`, view); + const container = this.element.querySelector(`.dashlet-container[data-id="${id}"]`); + + if (!container) { + return; + } + + container.append(...element.childNodes); + + view.element = undefined; + + await this.setView(`dashlet-${id}`, view); } clearPreservedDashlets() { @@ -279,8 +306,8 @@ class DashboardView extends View { return; } - if (!this.getMetadata().get(['dashlets', o.name])) { - console.error("Dashlet " + o.name + " doesn't exist or not available."); + if (!this.getMetadata().get(`dashlets.${o.name}`)) { + console.error(`Dashlet ${o.name} doesn't exist or not available.`); return; }