UI: Improve widget models
This commit is contained in:
parent
3c51a25eac
commit
3d1158d3bd
@ -223,6 +223,15 @@ export class DashboardUtilsService {
|
|||||||
public validateAndUpdateWidget(widget: Widget): Widget {
|
public validateAndUpdateWidget(widget: Widget): Widget {
|
||||||
widget.config = this.validateAndUpdateWidgetConfig(widget.config, widget.type);
|
widget.config = this.validateAndUpdateWidgetConfig(widget.config, widget.type);
|
||||||
widget = this.validateAndUpdateWidgetTypeFqn(widget);
|
widget = this.validateAndUpdateWidgetTypeFqn(widget);
|
||||||
|
if (isDefined((widget as any).title)) {
|
||||||
|
delete (widget as any).title;
|
||||||
|
}
|
||||||
|
if (isDefined((widget as any).image)) {
|
||||||
|
delete (widget as any).image;
|
||||||
|
}
|
||||||
|
if (isDefined((widget as any).description)) {
|
||||||
|
delete (widget as any).description;
|
||||||
|
}
|
||||||
// Temp workaround
|
// Temp workaround
|
||||||
if (['system.charts.state_chart',
|
if (['system.charts.state_chart',
|
||||||
'system.charts.basic_timeseries',
|
'system.charts.basic_timeseries',
|
||||||
@ -246,12 +255,21 @@ export class DashboardUtilsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private validateAndUpdateWidgetTypeFqn(widget: Widget): Widget {
|
private validateAndUpdateWidgetTypeFqn(widget: Widget): Widget {
|
||||||
|
const w = widget as any;
|
||||||
if (!isValidWidgetFullFqn(widget.typeFullFqn)) {
|
if (!isValidWidgetFullFqn(widget.typeFullFqn)) {
|
||||||
const w = widget as any;
|
|
||||||
if (isDefinedAndNotNull(w.isSystemType) && isNotEmptyStr(w.bundleAlias) && isNotEmptyStr(w.typeAlias)) {
|
if (isDefinedAndNotNull(w.isSystemType) && isNotEmptyStr(w.bundleAlias) && isNotEmptyStr(w.typeAlias)) {
|
||||||
widget.typeFullFqn = (w.isSystemType ? 'system' : 'tenant') + '.' + w.bundleAlias + '.' + w.typeAlias;
|
widget.typeFullFqn = (w.isSystemType ? 'system' : 'tenant') + '.' + w.bundleAlias + '.' + w.typeAlias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isDefined(w.isSystemType)) {
|
||||||
|
delete w.isSystemType;
|
||||||
|
}
|
||||||
|
if (isDefined(w.bundleAlias)) {
|
||||||
|
delete w.bundleAlias;
|
||||||
|
}
|
||||||
|
if (isDefined(w.typeAlias)) {
|
||||||
|
delete w.typeAlias;
|
||||||
|
}
|
||||||
// Temp workaround
|
// Temp workaround
|
||||||
if (widget.typeFullFqn === 'system.charts.timeseries') {
|
if (widget.typeFullFqn === 'system.charts.timeseries') {
|
||||||
widget.typeFullFqn = 'system.charts.basic_timeseries';
|
widget.typeFullFqn = 'system.charts.basic_timeseries';
|
||||||
|
|||||||
@ -40,9 +40,6 @@ export class WidgetEditorDashboardResolver implements Resolve<Dashboard> {
|
|||||||
const widget: Widget = {
|
const widget: Widget = {
|
||||||
typeFullFqn: 'system.customWidget',
|
typeFullFqn: 'system.customWidget',
|
||||||
type: editWidgetInfo.type,
|
type: editWidgetInfo.type,
|
||||||
title: 'My widget',
|
|
||||||
image: null,
|
|
||||||
description: null,
|
|
||||||
sizeX: editWidgetInfo.sizeX * 2,
|
sizeX: editWidgetInfo.sizeX * 2,
|
||||||
sizeY: editWidgetInfo.sizeY * 2,
|
sizeY: editWidgetInfo.sizeY * 2,
|
||||||
row: 2,
|
row: 2,
|
||||||
|
|||||||
@ -585,7 +585,6 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
|
|||||||
const widget: Widget = {
|
const widget: Widget = {
|
||||||
typeFullFqn: widgetInfo.fullFqn,
|
typeFullFqn: widgetInfo.fullFqn,
|
||||||
type: widgetInfo.type,
|
type: widgetInfo.type,
|
||||||
title: widgetInfo.widgetName,
|
|
||||||
sizeX,
|
sizeX,
|
||||||
sizeY,
|
sizeY,
|
||||||
row: 0,
|
row: 0,
|
||||||
|
|||||||
@ -1162,9 +1162,6 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
let newWidget: Widget = {
|
let newWidget: Widget = {
|
||||||
typeFullFqn: widgetTypeInfo.fullFqn,
|
typeFullFqn: widgetTypeInfo.fullFqn,
|
||||||
type: widgetTypeInfo.type,
|
type: widgetTypeInfo.type,
|
||||||
title: 'New widget',
|
|
||||||
image: null,
|
|
||||||
description: null,
|
|
||||||
sizeX: widgetTypeInfo.sizeX,
|
sizeX: widgetTypeInfo.sizeX,
|
||||||
sizeY: widgetTypeInfo.sizeY,
|
sizeY: widgetTypeInfo.sizeY,
|
||||||
config,
|
config,
|
||||||
|
|||||||
@ -681,7 +681,13 @@ export interface WidgetConfig {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Widget extends WidgetInfo{
|
export interface BaseWidgetInfo {
|
||||||
|
id?: string;
|
||||||
|
typeFullFqn: string;
|
||||||
|
type: widgetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Widget extends BaseWidgetInfo {
|
||||||
typeId?: WidgetTypeId;
|
typeId?: WidgetTypeId;
|
||||||
sizeX: number;
|
sizeX: number;
|
||||||
sizeY: number;
|
sizeY: number;
|
||||||
@ -690,10 +696,7 @@ export interface Widget extends WidgetInfo{
|
|||||||
config: WidgetConfig;
|
config: WidgetConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WidgetInfo {
|
export interface WidgetInfo extends BaseWidgetInfo {
|
||||||
id?: string;
|
|
||||||
typeFullFqn: string;
|
|
||||||
type: widgetType;
|
|
||||||
title: string;
|
title: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user