Browse Source

UI: Copy widget from right layout

pull/9735/head
Artem Dzhereleiko 3 years ago
parent
commit
b160f6e050
  1. 19
      ui-ngx/src/app/modules/home/components/dashboard-page/states/manage-dashboard-states-dialog.component.ts

19
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 { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
import { deepClone } from '@core/utils'; import { deepClone, isDefined } from '@core/utils';
import { import {
DashboardStateDialogComponent, DashboardStateDialogComponent,
DashboardStateDialogData DashboardStateDialogData
@ -251,7 +251,8 @@ export class ManageDashboardStatesDialogComponent
if (newStateName) { if (newStateName) {
const duplicatedStates = deepClone(originalState); const duplicatedStates = deepClone(originalState);
const duplicatedWidgets = deepClone(this.widgets); const duplicatedWidgets = deepClone(this.widgets);
const widgets = {}; const mainWidgets = {};
const rightWidgets = {};
duplicatedStates.id = newStateName.toLowerCase().replace(/\W/g, '_'); duplicatedStates.id = newStateName.toLowerCase().replace(/\W/g, '_');
duplicatedStates.name = newStateName; duplicatedStates.name = newStateName;
duplicatedStates.root = false; duplicatedStates.root = false;
@ -259,12 +260,22 @@ export class ManageDashboardStatesDialogComponent
for (const [key, value] of Object.entries(duplicatedStates.layouts.main.widgets)) { for (const [key, value] of Object.entries(duplicatedStates.layouts.main.widgets)) {
const guid = this.utils.guid(); const guid = this.utils.guid();
widgets[guid] = value; mainWidgets[guid] = value;
duplicatedWidgets[guid] = this.widgets[key]; duplicatedWidgets[guid] = this.widgets[key];
duplicatedWidgets[guid].id = guid; 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.states[duplicatedStates.id] = duplicatedStates;
this.widgets = duplicatedWidgets; this.widgets = duplicatedWidgets;
this.onStatesUpdated(); this.onStatesUpdated();

Loading…
Cancel
Save