Merge pull request #11504 from vvlladd28/bug/dashboard/move-all-widget

Improved move all widget action: fixed overlap widget and add support dashboard layout
This commit is contained in:
Igor Kulikov 2024-09-03 16:05:21 +03:00 committed by GitHub
commit 8410bd6f22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 5 deletions

View File

@ -752,10 +752,25 @@ export class DashboardUtilsService {
public moveWidgets(layout: DashboardLayout, cols: number, rows: number) { public moveWidgets(layout: DashboardLayout, cols: number, rows: number) {
cols = isDefinedAndNotNull(cols) ? Math.round(cols) : 0; cols = isDefinedAndNotNull(cols) ? Math.round(cols) : 0;
rows = isDefinedAndNotNull(rows) ? Math.round(rows) : 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)) { for (const w of Object.keys(layout.widgets)) {
const widget = layout.widgets[w]; const widget = layout.widgets[w];
widget.col = Math.max(0, widget.col + cols); widget.col += cols;
widget.row = Math.max(0, widget.row + rows); widget.row += rows;
} }
} }

View File

@ -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) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
@ -1001,7 +1001,8 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
}).afterClosed().subscribe((result) => { }).afterClosed().subscribe((result) => {
this.layouts[layoutId].layoutCtx.displayGrid = 'onDrag&Resize'; this.layouts[layoutId].layoutCtx.displayGrid = 'onDrag&Resize';
if (result) { 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.dashboardUtils.moveWidgets(targetLayout, result.cols, result.rows);
this.updateLayouts(); this.updateLayouts();
} else { } else {
@ -1582,7 +1583,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
dashboardContextActions.push( dashboardContextActions.push(
{ {
action: ($event) => { action: ($event) => {
this.moveWidgets($event, layoutCtx.id); this.moveWidgets($event, layoutCtx.id, layoutCtx.breakpoint);
}, },
enabled: true, enabled: true,
value: 'dashboard.move-all-widgets', value: 'dashboard.move-all-widgets',