|
|
@ -23,6 +23,8 @@ import { Widget } from '@shared/models/widget.models'; |
|
|
import { toWidgetInfo } from '@home/models/widget-component.models'; |
|
|
import { toWidgetInfo } from '@home/models/widget-component.models'; |
|
|
import { share } from 'rxjs/operators'; |
|
|
import { share } from 'rxjs/operators'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Observable } from 'rxjs'; |
|
|
|
|
|
import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; |
|
|
|
|
|
import { isDefinedAndNotNull } from '@core/utils'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'tb-dashboard-widget-select', |
|
|
selector: 'tb-dashboard-widget-select', |
|
|
@ -47,7 +49,8 @@ export class DashboardWidgetSelectComponent implements OnInit, OnChanges { |
|
|
|
|
|
|
|
|
widgetsBundles$: Observable<Array<WidgetsBundle>>; |
|
|
widgetsBundles$: Observable<Array<WidgetsBundle>>; |
|
|
|
|
|
|
|
|
constructor(private widgetsService: WidgetService) { |
|
|
constructor(private widgetsService: WidgetService, |
|
|
|
|
|
private sanitizer: DomSanitizer) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
ngOnInit(): void { |
|
|
@ -59,7 +62,7 @@ export class DashboardWidgetSelectComponent implements OnInit, OnChanges { |
|
|
ngOnChanges(changes: SimpleChanges): void { |
|
|
ngOnChanges(changes: SimpleChanges): void { |
|
|
for (const propName of Object.keys(changes)) { |
|
|
for (const propName of Object.keys(changes)) { |
|
|
const change = changes[propName]; |
|
|
const change = changes[propName]; |
|
|
if (change.currentValue !== change.previousValue && change.currentValue) { |
|
|
if (change.currentValue !== change.previousValue && (change.currentValue || change.currentValue === null)) { |
|
|
if (propName === 'widgetsBundle') { |
|
|
if (propName === 'widgetsBundle') { |
|
|
this.loadLibrary(); |
|
|
this.loadLibrary(); |
|
|
} |
|
|
} |
|
|
@ -69,36 +72,38 @@ export class DashboardWidgetSelectComponent implements OnInit, OnChanges { |
|
|
|
|
|
|
|
|
private loadLibrary() { |
|
|
private loadLibrary() { |
|
|
this.widgets.length = 0; |
|
|
this.widgets.length = 0; |
|
|
const bundleAlias = this.widgetsBundle.alias; |
|
|
if (this.widgetsBundle !== null) { |
|
|
const isSystem = this.widgetsBundle.tenantId.id === NULL_UUID; |
|
|
const bundleAlias = this.widgetsBundle.alias; |
|
|
this.widgetsService.getBundleWidgetTypes(bundleAlias, |
|
|
const isSystem = this.widgetsBundle.tenantId.id === NULL_UUID; |
|
|
isSystem).subscribe( |
|
|
this.widgetsService.getBundleWidgetTypes(bundleAlias, |
|
|
(types) => { |
|
|
isSystem).subscribe( |
|
|
types = types.sort((a, b) => b.createdTime - a.createdTime); |
|
|
(types) => { |
|
|
let top = 0; |
|
|
types = types.sort((a, b) => b.createdTime - a.createdTime); |
|
|
types.forEach((type) => { |
|
|
let top = 0; |
|
|
const widgetTypeInfo = toWidgetInfo(type); |
|
|
types.forEach((type) => { |
|
|
const widget: Widget = { |
|
|
const widgetTypeInfo = toWidgetInfo(type); |
|
|
typeId: type.id, |
|
|
const widget: Widget = { |
|
|
isSystemType: isSystem, |
|
|
typeId: type.id, |
|
|
bundleAlias, |
|
|
isSystemType: isSystem, |
|
|
typeAlias: widgetTypeInfo.alias, |
|
|
bundleAlias, |
|
|
type: widgetTypeInfo.type, |
|
|
typeAlias: widgetTypeInfo.alias, |
|
|
title: widgetTypeInfo.widgetName, |
|
|
type: widgetTypeInfo.type, |
|
|
image: widgetTypeInfo.image, |
|
|
title: widgetTypeInfo.widgetName, |
|
|
description: widgetTypeInfo.description, |
|
|
image: widgetTypeInfo.image, |
|
|
sizeX: widgetTypeInfo.sizeX, |
|
|
description: widgetTypeInfo.description, |
|
|
sizeY: widgetTypeInfo.sizeY, |
|
|
sizeX: widgetTypeInfo.sizeX, |
|
|
row: top, |
|
|
sizeY: widgetTypeInfo.sizeY, |
|
|
col: 0, |
|
|
row: top, |
|
|
config: JSON.parse(widgetTypeInfo.defaultConfig) |
|
|
col: 0, |
|
|
}; |
|
|
config: JSON.parse(widgetTypeInfo.defaultConfig) |
|
|
widget.config.title = widgetTypeInfo.widgetName; |
|
|
}; |
|
|
this.widgets.push(widget); |
|
|
widget.config.title = widgetTypeInfo.widgetName; |
|
|
top += widget.sizeY; |
|
|
this.widgets.push(widget); |
|
|
}); |
|
|
top += widget.sizeY; |
|
|
} |
|
|
}); |
|
|
); |
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
hasWidgetTypes(): boolean { |
|
|
hasWidgetTypes(): boolean { |
|
|
@ -119,10 +124,11 @@ export class DashboardWidgetSelectComponent implements OnInit, OnChanges { |
|
|
this.widgetsBundleSelected.emit(bundle); |
|
|
this.widgetsBundleSelected.emit(bundle); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
backToSelectWidgetsBundle() { |
|
|
getPreviewImage(imageUrl: string | null): SafeUrl | string { |
|
|
this.widgetsBundle = null; |
|
|
if (isDefinedAndNotNull(imageUrl)) { |
|
|
this.widgets.length = 0; |
|
|
return this.sanitizer.bypassSecurityTrustUrl(imageUrl); |
|
|
this.widgetsBundleSelected.emit(null); |
|
|
} |
|
|
|
|
|
return '/assets/widget-preview-empty.svg'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|