From b160f6e050df3bf5b6e856b9615b4dee2bfa700a Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Tue, 5 Dec 2023 12:02:38 +0200 Subject: [PATCH] UI: Copy widget from right layout --- ...anage-dashboard-states-dialog.component.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/states/manage-dashboard-states-dialog.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/states/manage-dashboard-states-dialog.component.ts index 8aab3e1297..99bf024c0e 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/states/manage-dashboard-states-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/states/manage-dashboard-states-dialog.component.ts @@ -35,7 +35,7 @@ import { fromEvent, merge } from 'rxjs'; import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators'; import { TranslateService } from '@ngx-translate/core'; import { DialogService } from '@core/services/dialog.service'; -import { deepClone } from '@core/utils'; +import { deepClone, isDefined } from '@core/utils'; import { DashboardStateDialogComponent, DashboardStateDialogData @@ -251,7 +251,8 @@ export class ManageDashboardStatesDialogComponent if (newStateName) { const duplicatedStates = deepClone(originalState); const duplicatedWidgets = deepClone(this.widgets); - const widgets = {}; + const mainWidgets = {}; + const rightWidgets = {}; duplicatedStates.id = newStateName.toLowerCase().replace(/\W/g, '_'); duplicatedStates.name = newStateName; duplicatedStates.root = false; @@ -259,12 +260,22 @@ export class ManageDashboardStatesDialogComponent for (const [key, value] of Object.entries(duplicatedStates.layouts.main.widgets)) { const guid = this.utils.guid(); - widgets[guid] = value; + mainWidgets[guid] = value; duplicatedWidgets[guid] = this.widgets[key]; duplicatedWidgets[guid].id = guid; } + duplicatedStates.layouts.main.widgets = mainWidgets; + + if (isDefined(duplicatedStates.layouts?.right)) { + for (const [key, value] of Object.entries(duplicatedStates.layouts.right.widgets)) { + const guid = this.utils.guid(); + rightWidgets[guid] = value; + duplicatedWidgets[guid] = this.widgets[key]; + duplicatedWidgets[guid].id = guid; + } + duplicatedStates.layouts.right.widgets = rightWidgets; + } - duplicatedStates.layouts.main.widgets = widgets; this.states[duplicatedStates.id] = duplicatedStates; this.widgets = duplicatedWidgets; this.onStatesUpdated();