Browse Source

PR comments fixes

pull/15908/head
Maksym Tsymbarov 1 month ago
parent
commit
89b0b622c0
  1. 32
      ui-ngx/src/app/core/services/dashboard-utils.service.ts
  2. 12
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

32
ui-ngx/src/app/core/services/dashboard-utils.service.ts

@ -696,7 +696,8 @@ export class DashboardUtilsService {
widgetLayout.col = column;
if (this.hasWidgetCollision(widgetLayout.row, widgetLayout.col,
widgetLayout.sizeX, widgetLayout.sizeY, Object.values(layout.widgets))) {
this.widgetPossiblePosition(widgetLayout, layout);
this.widgetPossiblePosition(widgetLayout, Object.values(layout.widgets),
layout.gridSettings.minColumns || layout.gridSettings.columns || 0);
}
} else {
row = 0;
@ -719,15 +720,13 @@ export class DashboardUtilsService {
layout.widgets[widget.id] = widgetLayout;
}
private widgetPossiblePosition(widgetLayout: WidgetLayout, layout: DashboardLayout) {
private widgetPossiblePosition(widgetLayout: WidgetLayout, widgetLayouts: WidgetLayout[], columns: number) {
let bestRow = 0;
let bestCol = 0;
let maxCol = layout.gridSettings.minColumns || layout.gridSettings.columns || 0;
let maxCol = columns;
let maxRow = 0;
const widgetLayouts = Object.values(layout.widgets);
widgetLayouts.forEach(widget => {
maxCol = Math.max(maxCol, widget.col + widget.sizeX);
maxRow = Math.max(maxRow, widget.row + widget.sizeY);
@ -903,33 +902,12 @@ export class DashboardUtilsService {
const placed: WidgetLayout[] = [];
for (const widget of widgets) {
if (this.hasWidgetCollision(widget.row, widget.col, widget.sizeX, widget.sizeY, placed)) {
this.findFreeWidgetPosition(widget, placed, columns);
this.widgetPossiblePosition(widget, placed, columns);
}
placed.push(widget);
}
}
private findFreeWidgetPosition(widgetLayout: WidgetLayout, widgetLayouts: WidgetLayout[], columns: number) {
let maxCol = columns;
let maxRow = 0;
widgetLayouts.forEach(widget => {
maxCol = Math.max(maxCol, widget.col + widget.sizeX);
maxRow = Math.max(maxRow, widget.row + widget.sizeY);
});
for (let row = 0; row <= maxRow; row++) {
for (let col = 0; col + widgetLayout.sizeX <= maxCol; col++) {
if (!this.hasWidgetCollision(row, col, widgetLayout.sizeX, widgetLayout.sizeY, widgetLayouts)) {
widgetLayout.row = row;
widgetLayout.col = col;
return;
}
}
}
// Wider than the grid: park it on a fresh row.
widgetLayout.row = maxRow;
widgetLayout.col = 0;
}
public moveWidgets(layout: DashboardLayout, cols: number, rows: number) {
cols = isDefinedAndNotNull(cols) ? Math.round(cols) : 0;
rows = isDefinedAndNotNull(rows) ? Math.round(rows) : 0;

12
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

@ -1110,9 +1110,15 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
if (layoutsData) {
if (this.isEdit && state !== this.dashboardCtx.state && Object.keys(layoutsData).some(l => {
const layout: DashboardPageLayout = this.layouts[l];
const breakpoint = (layout && layout.layoutCtx.breakpoint) || 'default';
const layoutInfo: BreakpointLayoutInfo = layoutsData[l][breakpoint] || layoutsData[l].default;
return layoutInfo && this.dashboardUtils.hasCollidingWidgets(layoutInfo.widgetLayouts);
let breakpoint = (layout && layout.layoutCtx.breakpoint) || 'default';
if (!layoutsData[l][breakpoint]) {
breakpoint = 'default';
}
const layoutInfo: BreakpointLayoutInfo = layoutsData[l][breakpoint];
if (!layoutInfo || (breakpoint !== 'default' && layoutInfo.gridSettings?.viewFormat === ViewFormatType.list)) {
return false;
}
return this.dashboardUtils.hasCollidingWidgets(layoutInfo.widgetLayouts);
})) {
this.store.dispatch(new ActionNotificationShow({
message: this.translate.instant('dashboard.state-widgets-overlap-warning'),

Loading…
Cancel
Save