From 3d1158d3bdfab59ffc3051a2feec7ae5d38696ce Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Tue, 5 Sep 2023 12:18:59 +0300 Subject: [PATCH] UI: Improve widget models --- .../core/services/dashboard-utils.service.ts | 20 ++++++++++++++++++- .../dashboard-pages.routing.module.ts | 3 --- .../attribute/attribute-table.component.ts | 1 - .../dashboard-page.component.ts | 3 --- ui-ngx/src/app/shared/models/widget.models.ts | 13 +++++++----- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ui-ngx/src/app/core/services/dashboard-utils.service.ts b/ui-ngx/src/app/core/services/dashboard-utils.service.ts index 3bca1bc96a..bb4c738516 100644 --- a/ui-ngx/src/app/core/services/dashboard-utils.service.ts +++ b/ui-ngx/src/app/core/services/dashboard-utils.service.ts @@ -223,6 +223,15 @@ export class DashboardUtilsService { public validateAndUpdateWidget(widget: Widget): Widget { widget.config = this.validateAndUpdateWidgetConfig(widget.config, widget.type); 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 if (['system.charts.state_chart', 'system.charts.basic_timeseries', @@ -246,12 +255,21 @@ export class DashboardUtilsService { } private validateAndUpdateWidgetTypeFqn(widget: Widget): Widget { + const w = widget as any; if (!isValidWidgetFullFqn(widget.typeFullFqn)) { - const w = widget as any; if (isDefinedAndNotNull(w.isSystemType) && isNotEmptyStr(w.bundleAlias) && isNotEmptyStr(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 if (widget.typeFullFqn === 'system.charts.timeseries') { widget.typeFullFqn = 'system.charts.basic_timeseries'; diff --git a/ui-ngx/src/app/modules/dashboard/dashboard-pages.routing.module.ts b/ui-ngx/src/app/modules/dashboard/dashboard-pages.routing.module.ts index 4963818aa0..a89f467e1e 100644 --- a/ui-ngx/src/app/modules/dashboard/dashboard-pages.routing.module.ts +++ b/ui-ngx/src/app/modules/dashboard/dashboard-pages.routing.module.ts @@ -40,9 +40,6 @@ export class WidgetEditorDashboardResolver implements Resolve { const widget: Widget = { typeFullFqn: 'system.customWidget', type: editWidgetInfo.type, - title: 'My widget', - image: null, - description: null, sizeX: editWidgetInfo.sizeX * 2, sizeY: editWidgetInfo.sizeY * 2, row: 2, diff --git a/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts b/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts index 0837474a87..872e124f3a 100644 --- a/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts +++ b/ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts @@ -585,7 +585,6 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI const widget: Widget = { typeFullFqn: widgetInfo.fullFqn, type: widgetInfo.type, - title: widgetInfo.widgetName, sizeX, sizeY, row: 0, diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts index e24f1cad07..7b84dbd6d0 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts @@ -1162,9 +1162,6 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC let newWidget: Widget = { typeFullFqn: widgetTypeInfo.fullFqn, type: widgetTypeInfo.type, - title: 'New widget', - image: null, - description: null, sizeX: widgetTypeInfo.sizeX, sizeY: widgetTypeInfo.sizeY, config, diff --git a/ui-ngx/src/app/shared/models/widget.models.ts b/ui-ngx/src/app/shared/models/widget.models.ts index 21de5376ab..c04eb6f7ec 100644 --- a/ui-ngx/src/app/shared/models/widget.models.ts +++ b/ui-ngx/src/app/shared/models/widget.models.ts @@ -681,7 +681,13 @@ export interface WidgetConfig { [key: string]: any; } -export interface Widget extends WidgetInfo{ +export interface BaseWidgetInfo { + id?: string; + typeFullFqn: string; + type: widgetType; +} + +export interface Widget extends BaseWidgetInfo { typeId?: WidgetTypeId; sizeX: number; sizeY: number; @@ -690,10 +696,7 @@ export interface Widget extends WidgetInfo{ config: WidgetConfig; } -export interface WidgetInfo { - id?: string; - typeFullFqn: string; - type: widgetType; +export interface WidgetInfo extends BaseWidgetInfo { title: string; image?: string; description?: string;