|
|
|
@ -204,8 +204,7 @@ export class DashboardWidgets implements Iterable<DashboardWidget> { |
|
|
|
index = this.dashboardWidgets.findIndex((dashboardWidget) => dashboardWidget.widgetId === record.widgetId); |
|
|
|
if (index > -1) { |
|
|
|
const prevDashboardWidget = this.dashboardWidgets[index]; |
|
|
|
if (!isEqual(prevDashboardWidget.widget, record.widget) || |
|
|
|
!isEqual(prevDashboardWidget.widgetLayout, record.widgetLayout)) { |
|
|
|
if (!isEqual(prevDashboardWidget.widget, record.widget)) { |
|
|
|
this.dashboardWidgets[index] = new DashboardWidget(this.dashboard, record.widget, record.widgetLayout, |
|
|
|
this.parentDashboard, this.popoverComponent); |
|
|
|
this.dashboardWidgets[index].highlighted = prevDashboardWidget.highlighted; |
|
|
|
@ -391,7 +390,7 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget { |
|
|
|
private gridsterItemComponentSubject = new Subject<GridsterItemComponentInterface>(); |
|
|
|
private gridsterItemComponentValue: GridsterItemComponentInterface; |
|
|
|
|
|
|
|
private readonly aspectRatio: number; |
|
|
|
private aspectRatio: number; |
|
|
|
|
|
|
|
private heightValue: number; |
|
|
|
private widthValue: number; |
|
|
|
@ -419,85 +418,97 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget { |
|
|
|
this.gridsterItemComponentSubject.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
private preserveAspectRatioApplied = false; |
|
|
|
|
|
|
|
private applyPreserveAspectRatio(item: GridsterItemComponentInterface) { |
|
|
|
this.resizableHandles.ne = false; |
|
|
|
this.resizableHandles.sw = false; |
|
|
|
this.resizableHandles.nw = false; |
|
|
|
|
|
|
|
const $item = item.$item; |
|
|
|
if (this.widgetLayout?.preserveAspectRatio) { |
|
|
|
this.resizableHandles.ne = false; |
|
|
|
this.resizableHandles.sw = false; |
|
|
|
this.resizableHandles.nw = false; |
|
|
|
} else { |
|
|
|
this.resizableHandles.ne = true; |
|
|
|
this.resizableHandles.sw = true; |
|
|
|
this.resizableHandles.nw = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (!this.preserveAspectRatioApplied) { |
|
|
|
const $item = item.$item; |
|
|
|
|
|
|
|
this.rowsValue = $item.rows; |
|
|
|
this.colsValue = $item.cols; |
|
|
|
this.rowsValue = $item.rows; |
|
|
|
this.colsValue = $item.cols; |
|
|
|
|
|
|
|
Object.defineProperty($item, 'rows', { |
|
|
|
get: () => this.rowsValue, |
|
|
|
set: v => { |
|
|
|
if (this.rowsValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.colsValue = v * this.aspectRatio; |
|
|
|
Object.defineProperty($item, 'rows', { |
|
|
|
get: () => this.rowsValue, |
|
|
|
set: v => { |
|
|
|
if (this.rowsValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.colsValue = v * this.aspectRatio; |
|
|
|
} |
|
|
|
this.rowsValue = v; |
|
|
|
} |
|
|
|
this.rowsValue = v; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Object.defineProperty($item, 'cols', { |
|
|
|
get: () => this.colsValue, |
|
|
|
set: v => { |
|
|
|
if (this.colsValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.rowsValue = v / this.aspectRatio; |
|
|
|
Object.defineProperty($item, 'cols', { |
|
|
|
get: () => this.colsValue, |
|
|
|
set: v => { |
|
|
|
if (this.colsValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.rowsValue = v / this.aspectRatio; |
|
|
|
} |
|
|
|
this.colsValue = v; |
|
|
|
} |
|
|
|
this.colsValue = v; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
const resizable = item.resize; |
|
|
|
const resizable = item.resize; |
|
|
|
|
|
|
|
this.heightValue = resizable.height; |
|
|
|
this.widthValue = resizable.width; |
|
|
|
this.heightValue = resizable.height; |
|
|
|
this.widthValue = resizable.width; |
|
|
|
|
|
|
|
const setItemHeight = resizable.setItemHeight.bind(resizable); |
|
|
|
const setItemWidth = resizable.setItemWidth.bind(resizable); |
|
|
|
resizable.setItemHeight = (height) => { |
|
|
|
setItemHeight(height); |
|
|
|
this.heightValue = height; |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
setItemWidth(height * this.aspectRatio); |
|
|
|
} |
|
|
|
}; |
|
|
|
resizable.setItemWidth = (width) => { |
|
|
|
setItemWidth(width); |
|
|
|
this.widthValue = width; |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
setItemHeight(width / this.aspectRatio); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
Object.defineProperty(resizable, 'height', { |
|
|
|
get: () => this.heightValue, |
|
|
|
set: v => { |
|
|
|
if (this.heightValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.widthValue = v * this.aspectRatio; |
|
|
|
const setItemHeight = resizable.setItemHeight.bind(resizable); |
|
|
|
const setItemWidth = resizable.setItemWidth.bind(resizable); |
|
|
|
resizable.setItemHeight = (height) => { |
|
|
|
setItemHeight(height); |
|
|
|
this.heightValue = height; |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
setItemWidth(height * this.aspectRatio); |
|
|
|
} |
|
|
|
}; |
|
|
|
resizable.setItemWidth = (width) => { |
|
|
|
setItemWidth(width); |
|
|
|
this.widthValue = width; |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
setItemHeight(width / this.aspectRatio); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
Object.defineProperty(resizable, 'height', { |
|
|
|
get: () => this.heightValue, |
|
|
|
set: v => { |
|
|
|
if (this.heightValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.widthValue = v * this.aspectRatio; |
|
|
|
} |
|
|
|
this.heightValue = v; |
|
|
|
} |
|
|
|
this.heightValue = v; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
Object.defineProperty(resizable, 'width', { |
|
|
|
get: () => this.widthValue, |
|
|
|
set: v => { |
|
|
|
if (this.widthValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.heightValue = v / this.aspectRatio; |
|
|
|
Object.defineProperty(resizable, 'width', { |
|
|
|
get: () => this.widthValue, |
|
|
|
set: v => { |
|
|
|
if (this.widthValue !== v) { |
|
|
|
if (this.preserveAspectRatio) { |
|
|
|
this.heightValue = v / this.aspectRatio; |
|
|
|
} |
|
|
|
this.widthValue = v; |
|
|
|
} |
|
|
|
this.widthValue = v; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.preserveAspectRatioApplied = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
get highlighted() { |
|
|
|
@ -527,19 +538,36 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
get widgetLayout(): WidgetLayout { |
|
|
|
return this.widgetLayoutValue; |
|
|
|
} |
|
|
|
|
|
|
|
set widgetLayout(value: WidgetLayout) { |
|
|
|
this.widgetLayoutValue = value; |
|
|
|
this._widgetLayoutUpdated(); |
|
|
|
} |
|
|
|
|
|
|
|
private _widgetLayoutUpdated() { |
|
|
|
if (isDefined(this.widgetLayout?.resizable)) { |
|
|
|
this.resizeEnabled = this.widgetLayout.resizable; |
|
|
|
} |
|
|
|
if (this.widgetLayout?.preserveAspectRatio) { |
|
|
|
this.aspectRatio = this.widgetLayout.sizeX / this.widgetLayout.sizeY; |
|
|
|
} |
|
|
|
if (this.gridsterItemComponentValue) { |
|
|
|
this.applyPreserveAspectRatio(this.gridsterItemComponentValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
constructor( |
|
|
|
private dashboard: IDashboardComponent, |
|
|
|
public widget: Widget, |
|
|
|
public widgetLayout?: WidgetLayout, |
|
|
|
private widgetLayoutValue?: WidgetLayout, |
|
|
|
private parentDashboard?: IDashboardComponent, |
|
|
|
private popoverComponent?: TbPopoverComponent) { |
|
|
|
|
|
|
|
if (isDefined(widgetLayout?.resizable)) { |
|
|
|
this.resizeEnabled = widgetLayout.resizable; |
|
|
|
} |
|
|
|
if (widgetLayout?.preserveAspectRatio) { |
|
|
|
this.aspectRatio = this.widgetLayout.sizeX / this.widgetLayout.sizeY; |
|
|
|
} |
|
|
|
this.widgetLayout = widgetLayoutValue; |
|
|
|
|
|
|
|
if (!widget.id) { |
|
|
|
widget.id = guid(); |
|
|
|
} |
|
|
|
|