Browse Source

UI: Improved move all widget action - fixed overlap and add support dashboard layout

pull/11504/head
Vladyslav_Prykhodko 2 years ago
parent
commit
4753455941
  1. 19
      ui-ngx/src/app/core/services/dashboard-utils.service.ts
  2. 7
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

19
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) { 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;
} }
} }

7
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) { 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',

Loading…
Cancel
Save