Browse Source

UI: Improve widget models

pull/9193/head
Igor Kulikov 3 years ago
parent
commit
3d1158d3bd
  1. 20
      ui-ngx/src/app/core/services/dashboard-utils.service.ts
  2. 3
      ui-ngx/src/app/modules/dashboard/dashboard-pages.routing.module.ts
  3. 1
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts
  4. 3
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts
  5. 13
      ui-ngx/src/app/shared/models/widget.models.ts

20
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';

3
ui-ngx/src/app/modules/dashboard/dashboard-pages.routing.module.ts

@ -40,9 +40,6 @@ export class WidgetEditorDashboardResolver implements Resolve<Dashboard> {
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,

1
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,

3
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,

13
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;

Loading…
Cancel
Save