From 4753455941e838dadfebef2391688fd096da2cb9 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Wed, 28 Aug 2024 11:17:10 +0300 Subject: [PATCH] UI: Improved move all widget action - fixed overlap and add support dashboard layout --- .../core/services/dashboard-utils.service.ts | 19 +++++++++++++++++-- .../dashboard-page.component.ts | 7 ++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ui-ngx/src/app/core/services/dashboard-utils.service.ts b/ui-ngx/src/app/core/services/dashboard-utils.service.ts index 8d599ad925..5b98c7cb7b 100644 --- a/ui-ngx/src/app/core/services/dashboard-utils.service.ts +++ b/ui-ngx/src/app/core/services/dashboard-utils.service.ts @@ -752,10 +752,25 @@ export class DashboardUtilsService { public moveWidgets(layout: DashboardLayout, cols: number, rows: number) { cols = isDefinedAndNotNull(cols) ? Math.round(cols) : 0; rows = isDefinedAndNotNull(rows) ? Math.round(rows) : 0; + if (cols < 0 || rows < 0) { + let widgetMinCol = Infinity; + let widgetMinRow = Infinity; + for (const w of Object.keys(layout.widgets)) { + const widget = layout.widgets[w]; + widgetMinCol = Math.min(widgetMinCol, widget.col); + widgetMinRow = Math.min(widgetMinRow, widget.row); + } + if ((cols + widgetMinCol) < 0 ){ + cols = -widgetMinCol; + } + if ((rows + widgetMinRow) < 0 ){ + rows = -widgetMinRow; + } + } for (const w of Object.keys(layout.widgets)) { const widget = layout.widgets[w]; - widget.col = Math.max(0, widget.col + cols); - widget.row = Math.max(0, widget.row + rows); + widget.col += cols; + widget.row += rows; } } diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts index 0d379b1623..ee29dffb59 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts @@ -988,7 +988,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC }); } - private moveWidgets($event: Event, layoutId: DashboardLayoutId) { + private moveWidgets($event: Event, layoutId: DashboardLayoutId, breakpointId: BreakpointId) { if ($event) { $event.stopPropagation(); } @@ -1001,7 +1001,8 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC }).afterClosed().subscribe((result) => { this.layouts[layoutId].layoutCtx.displayGrid = 'onDrag&Resize'; if (result) { - const targetLayout = this.dashboardConfiguration.states[this.dashboardCtx.state].layouts[layoutId]; + const dashboardLayout = this.dashboardConfiguration.states[this.dashboardCtx.state].layouts[layoutId]; + const targetLayout = this.dashboardUtils.getDashboardLayoutConfig(dashboardLayout, breakpointId); this.dashboardUtils.moveWidgets(targetLayout, result.cols, result.rows); this.updateLayouts(); } else { @@ -1582,7 +1583,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC dashboardContextActions.push( { action: ($event) => { - this.moveWidgets($event, layoutCtx.id); + this.moveWidgets($event, layoutCtx.id, layoutCtx.breakpoint); }, enabled: true, value: 'dashboard.move-all-widgets',