Merge pull request #7863 from Terny22/improvments/dashboards
Optimizations for dashboard-pages that open in popover or dialog.
This commit is contained in:
commit
aeaa70f96e
@ -869,8 +869,38 @@ export class EntityService {
|
|||||||
};
|
};
|
||||||
aliasInfo.currentEntity = null;
|
aliasInfo.currentEntity = null;
|
||||||
if (!aliasInfo.resolveMultiple && aliasInfo.entityFilter) {
|
if (!aliasInfo.resolveMultiple && aliasInfo.entityFilter) {
|
||||||
return this.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter,
|
let entityInfoObservable: Observable<EntityInfo>;
|
||||||
{ignoreLoading: true, ignoreErrors: true}).pipe(
|
if (result.stateEntity && aliasInfo.entityFilter.type === AliasFilterType.singleEntity) {
|
||||||
|
let currentEntity: EntityInfo = null;
|
||||||
|
if (stateParams) {
|
||||||
|
if (result.entityParamName && result.entityParamName.length) {
|
||||||
|
const stateEntity = stateParams[result.entityParamName];
|
||||||
|
if (stateEntity) {
|
||||||
|
currentEntity = {
|
||||||
|
id: stateEntity.entityId.id,
|
||||||
|
entityType: stateEntity.entityId.entityType,
|
||||||
|
name: stateEntity.entityName,
|
||||||
|
label: stateEntity.entityLabel
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (stateParams.entityId) {
|
||||||
|
currentEntity = {
|
||||||
|
id: stateParams.entityId.id,
|
||||||
|
entityType: stateParams.entityId.entityType as EntityType,
|
||||||
|
name: stateParams.entityName,
|
||||||
|
label: stateParams.entityLabel
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entityInfoObservable = currentEntity ? of(currentEntity) : this.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter,
|
||||||
|
{ignoreLoading: true, ignoreErrors: true});
|
||||||
|
} else {
|
||||||
|
entityInfoObservable = this.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter,
|
||||||
|
{ignoreLoading: true, ignoreErrors: true});
|
||||||
|
}
|
||||||
|
return entityInfoObservable.pipe(
|
||||||
map((entity) => {
|
map((entity) => {
|
||||||
aliasInfo.currentEntity = entity;
|
aliasInfo.currentEntity = entity;
|
||||||
return aliasInfo;
|
return aliasInfo;
|
||||||
|
|||||||
@ -135,7 +135,7 @@
|
|||||||
(click)="openDashboardSettings($event)">
|
(click)="openDashboardSettings($event)">
|
||||||
<mat-icon>settings</mat-icon>
|
<mat-icon>settings</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<tb-dashboard-select [fxShow]="!isEdit && !widgetEditMode && !embedded && displayDashboardsSelect()"
|
<tb-dashboard-select *ngIf="!isEdit && !widgetEditMode && !embedded && displayDashboardsSelect()"
|
||||||
[(ngModel)]="currentDashboardId"
|
[(ngModel)]="currentDashboardId"
|
||||||
(ngModelChange)="currentDashboardIdChanged(currentDashboardId)"
|
(ngModelChange)="currentDashboardIdChanged(currentDashboardId)"
|
||||||
[customerId]="currentCustomerId"
|
[customerId]="currentCustomerId"
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import {
|
|||||||
Optional,
|
Optional,
|
||||||
Renderer2,
|
Renderer2,
|
||||||
StaticProvider,
|
StaticProvider,
|
||||||
|
Type,
|
||||||
ViewChild,
|
ViewChild,
|
||||||
ViewContainerRef,
|
ViewContainerRef,
|
||||||
ViewEncapsulation
|
ViewEncapsulation
|
||||||
@ -148,6 +149,7 @@ import { TbPopoverService } from '@shared/components/popover.service';
|
|||||||
import { tap } from 'rxjs/operators';
|
import { tap } from 'rxjs/operators';
|
||||||
import { LayoutFixedSize, LayoutWidthType } from '@home/components/dashboard-page/layout/layout.models';
|
import { LayoutFixedSize, LayoutWidthType } from '@home/components/dashboard-page/layout/layout.models';
|
||||||
import { TbPopoverComponent } from '@shared/components/popover.component';
|
import { TbPopoverComponent } from '@shared/components/popover.component';
|
||||||
|
import { HOME_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens';
|
||||||
|
|
||||||
// @dynamic
|
// @dynamic
|
||||||
@Component({
|
@Component({
|
||||||
@ -331,6 +333,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
constructor(protected store: Store<AppState>,
|
constructor(protected store: Store<AppState>,
|
||||||
@Inject(WINDOW) private window: Window,
|
@Inject(WINDOW) private window: Window,
|
||||||
@Inject(DOCUMENT) private document: Document,
|
@Inject(DOCUMENT) private document: Document,
|
||||||
|
@Inject(HOME_COMPONENTS_MODULE_TOKEN) private homeComponentsModule: Type<any>,
|
||||||
private breakpointObserver: BreakpointObserver,
|
private breakpointObserver: BreakpointObserver,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@ -1112,7 +1115,8 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
addWidgetFromType(widget: WidgetInfo) {
|
addWidgetFromType(widget: WidgetInfo) {
|
||||||
this.onAddWidgetClosed();
|
this.onAddWidgetClosed();
|
||||||
this.searchBundle = '';
|
this.searchBundle = '';
|
||||||
this.widgetComponentService.getWidgetInfo(widget.bundleAlias, widget.typeAlias, widget.isSystemType).subscribe(
|
this.widgetComponentService.getWidgetInfo(widget.bundleAlias, widget.typeAlias, widget.isSystemType,
|
||||||
|
[this.homeComponentsModule]).subscribe(
|
||||||
(widgetTypeInfo) => {
|
(widgetTypeInfo) => {
|
||||||
const config: WidgetConfig = JSON.parse(widgetTypeInfo.defaultConfig);
|
const config: WidgetConfig = JSON.parse(widgetTypeInfo.defaultConfig);
|
||||||
config.title = 'New ' + widgetTypeInfo.widgetName;
|
config.title = 'New ' + widgetTypeInfo.widgetName;
|
||||||
|
|||||||
@ -35,7 +35,6 @@ import { AddAttributeDialogComponent } from '@home/components/attribute/add-attr
|
|||||||
import { EditAttributeValuePanelComponent } from '@home/components/attribute/edit-attribute-value-panel.component';
|
import { EditAttributeValuePanelComponent } from '@home/components/attribute/edit-attribute-value-panel.component';
|
||||||
import { DashboardComponent } from '@home/components/dashboard/dashboard.component';
|
import { DashboardComponent } from '@home/components/dashboard/dashboard.component';
|
||||||
import { WidgetComponent } from '@home/components/widget/widget.component';
|
import { WidgetComponent } from '@home/components/widget/widget.component';
|
||||||
import { WidgetComponentService } from '@home/components/widget/widget-component.service';
|
|
||||||
import { LegendComponent } from '@home/components/widget/legend.component';
|
import { LegendComponent } from '@home/components/widget/legend.component';
|
||||||
import { AliasesEntitySelectPanelComponent } from '@home/components/alias/aliases-entity-select-panel.component';
|
import { AliasesEntitySelectPanelComponent } from '@home/components/alias/aliases-entity-select-panel.component';
|
||||||
import { AliasesEntitySelectComponent } from '@home/components/alias/aliases-entity-select.component';
|
import { AliasesEntitySelectComponent } from '@home/components/alias/aliases-entity-select.component';
|
||||||
@ -456,7 +455,6 @@ import { AssetProfileAutocompleteComponent } from '@home/components/profile/asse
|
|||||||
RateLimitsDetailsDialogComponent
|
RateLimitsDetailsDialogComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
WidgetComponentService,
|
|
||||||
CustomDialogService,
|
CustomDialogService,
|
||||||
ImportExportService,
|
ImportExportService,
|
||||||
{provide: EMBED_DASHBOARD_DIALOG_TOKEN, useValue: EmbedDashboardDialogComponent},
|
{provide: EMBED_DASHBOARD_DIALOG_TOKEN, useValue: EmbedDashboardDialogComponent},
|
||||||
|
|||||||
@ -45,13 +45,13 @@ import { MODULES_MAP } from '@shared/public-api';
|
|||||||
import * as tinycolor_ from 'tinycolor2';
|
import * as tinycolor_ from 'tinycolor2';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { IModulesMap } from '@modules/common/modules-map.models';
|
import { IModulesMap } from '@modules/common/modules-map.models';
|
||||||
import { HOME_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens';
|
|
||||||
import { widgetSettingsComponentsMap } from '@home/components/widget/lib/settings/widget-settings.module';
|
import { widgetSettingsComponentsMap } from '@home/components/widget/lib/settings/widget-settings.module';
|
||||||
|
|
||||||
const tinycolor = tinycolor_;
|
const tinycolor = tinycolor_;
|
||||||
|
|
||||||
// @dynamic
|
@Injectable({
|
||||||
@Injectable()
|
providedIn: 'root'
|
||||||
|
})
|
||||||
export class WidgetComponentService {
|
export class WidgetComponentService {
|
||||||
|
|
||||||
private cssParser = new cssjs();
|
private cssParser = new cssjs();
|
||||||
@ -68,7 +68,6 @@ export class WidgetComponentService {
|
|||||||
|
|
||||||
constructor(@Inject(WINDOW) private window: Window,
|
constructor(@Inject(WINDOW) private window: Window,
|
||||||
@Optional() @Inject(MODULES_MAP) private modulesMap: IModulesMap,
|
@Optional() @Inject(MODULES_MAP) private modulesMap: IModulesMap,
|
||||||
@Inject(HOME_COMPONENTS_MODULE_TOKEN) private homeComponentsModule: Type<any>,
|
|
||||||
private dynamicComponentFactoryService: DynamicComponentFactoryService,
|
private dynamicComponentFactoryService: DynamicComponentFactoryService,
|
||||||
private widgetService: WidgetService,
|
private widgetService: WidgetService,
|
||||||
private utils: UtilsService,
|
private utils: UtilsService,
|
||||||
@ -185,9 +184,9 @@ export class WidgetComponentService {
|
|||||||
() => {
|
() => {
|
||||||
const loadDefaultWidgetInfoTasks = [
|
const loadDefaultWidgetInfoTasks = [
|
||||||
this.loadWidgetResources(this.missingWidgetType, 'global-widget-missing-type',
|
this.loadWidgetResources(this.missingWidgetType, 'global-widget-missing-type',
|
||||||
[SharedModule, WidgetComponentsModule, this.homeComponentsModule]),
|
[SharedModule, WidgetComponentsModule]),
|
||||||
this.loadWidgetResources(this.errorWidgetType, 'global-widget-error-type',
|
this.loadWidgetResources(this.errorWidgetType, 'global-widget-error-type',
|
||||||
[SharedModule, WidgetComponentsModule, this.homeComponentsModule]),
|
[SharedModule, WidgetComponentsModule]),
|
||||||
];
|
];
|
||||||
forkJoin(loadDefaultWidgetInfoTasks).subscribe(
|
forkJoin(loadDefaultWidgetInfoTasks).subscribe(
|
||||||
() => {
|
() => {
|
||||||
@ -231,13 +230,14 @@ export class WidgetComponentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getWidgetInfo(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean): Observable<WidgetInfo> {
|
public getWidgetInfo(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean, modules?: Type<any>[]): Observable<WidgetInfo> {
|
||||||
return this.init().pipe(
|
return this.init().pipe(
|
||||||
mergeMap(() => this.getWidgetInfoInternal(bundleAlias, widgetTypeAlias, isSystem))
|
mergeMap(() => this.getWidgetInfoInternal(bundleAlias, widgetTypeAlias, isSystem, modules))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getWidgetInfoInternal(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean): Observable<WidgetInfo> {
|
private getWidgetInfoInternal(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean,
|
||||||
|
modules?: Type<any>[]): Observable<WidgetInfo> {
|
||||||
const widgetInfoSubject = new ReplaySubject<WidgetInfo>();
|
const widgetInfoSubject = new ReplaySubject<WidgetInfo>();
|
||||||
const widgetInfo = this.getWidgetInfoFromCache(bundleAlias, widgetTypeAlias, isSystem);
|
const widgetInfo = this.getWidgetInfoFromCache(bundleAlias, widgetTypeAlias, isSystem);
|
||||||
if (widgetInfo) {
|
if (widgetInfo) {
|
||||||
@ -245,7 +245,7 @@ export class WidgetComponentService {
|
|||||||
widgetInfoSubject.complete();
|
widgetInfoSubject.complete();
|
||||||
} else {
|
} else {
|
||||||
if (this.utils.widgetEditMode) {
|
if (this.utils.widgetEditMode) {
|
||||||
this.loadWidget(this.editingWidgetType, bundleAlias, isSystem, widgetInfoSubject);
|
this.loadWidget(this.editingWidgetType, bundleAlias, isSystem, widgetInfoSubject, modules);
|
||||||
} else {
|
} else {
|
||||||
const key = this.createWidgetInfoCacheKey(bundleAlias, widgetTypeAlias, isSystem);
|
const key = this.createWidgetInfoCacheKey(bundleAlias, widgetTypeAlias, isSystem);
|
||||||
let fetchQueue = this.widgetsInfoFetchQueue.get(key);
|
let fetchQueue = this.widgetsInfoFetchQueue.get(key);
|
||||||
@ -256,7 +256,7 @@ export class WidgetComponentService {
|
|||||||
this.widgetsInfoFetchQueue.set(key, fetchQueue);
|
this.widgetsInfoFetchQueue.set(key, fetchQueue);
|
||||||
this.widgetService.getWidgetType(bundleAlias, widgetTypeAlias, isSystem, {ignoreErrors: true}).subscribe(
|
this.widgetService.getWidgetType(bundleAlias, widgetTypeAlias, isSystem, {ignoreErrors: true}).subscribe(
|
||||||
(widgetType) => {
|
(widgetType) => {
|
||||||
this.loadWidget(widgetType, bundleAlias, isSystem, widgetInfoSubject);
|
this.loadWidget(widgetType, bundleAlias, isSystem, widgetInfoSubject, modules);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
widgetInfoSubject.next(this.missingWidgetType);
|
widgetInfoSubject.next(this.missingWidgetType);
|
||||||
@ -270,7 +270,8 @@ export class WidgetComponentService {
|
|||||||
return widgetInfoSubject.asObservable();
|
return widgetInfoSubject.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadWidget(widgetType: WidgetType, bundleAlias: string, isSystem: boolean, widgetInfoSubject: Subject<WidgetInfo>) {
|
private loadWidget(widgetType: WidgetType, bundleAlias: string, isSystem: boolean, widgetInfoSubject: Subject<WidgetInfo>,
|
||||||
|
modules?: Type<any>[]) {
|
||||||
const widgetInfo = toWidgetInfo(widgetType);
|
const widgetInfo = toWidgetInfo(widgetType);
|
||||||
const key = this.createWidgetInfoCacheKey(bundleAlias, widgetInfo.alias, isSystem);
|
const key = this.createWidgetInfoCacheKey(bundleAlias, widgetInfo.alias, isSystem);
|
||||||
let widgetControllerDescriptor: WidgetControllerDescriptor = null;
|
let widgetControllerDescriptor: WidgetControllerDescriptor = null;
|
||||||
@ -283,7 +284,11 @@ export class WidgetComponentService {
|
|||||||
}
|
}
|
||||||
if (widgetControllerDescriptor) {
|
if (widgetControllerDescriptor) {
|
||||||
const widgetNamespace = `widget-type-${(isSystem ? 'sys-' : '')}${bundleAlias}-${widgetInfo.alias}`;
|
const widgetNamespace = `widget-type-${(isSystem ? 'sys-' : '')}${bundleAlias}-${widgetInfo.alias}`;
|
||||||
this.loadWidgetResources(widgetInfo, widgetNamespace, [SharedModule, WidgetComponentsModule, this.homeComponentsModule]).subscribe(
|
const widgetModules = [SharedModule, WidgetComponentsModule];
|
||||||
|
if (modules) {
|
||||||
|
widgetModules.push(...modules);
|
||||||
|
}
|
||||||
|
this.loadWidgetResources(widgetInfo, widgetNamespace, widgetModules).subscribe(
|
||||||
() => {
|
() => {
|
||||||
if (widgetControllerDescriptor.settingsSchema) {
|
if (widgetControllerDescriptor.settingsSchema) {
|
||||||
widgetInfo.typeSettingsSchema = widgetControllerDescriptor.settingsSchema;
|
widgetInfo.typeSettingsSchema = widgetControllerDescriptor.settingsSchema;
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import {
|
|||||||
OnInit,
|
OnInit,
|
||||||
Renderer2,
|
Renderer2,
|
||||||
SimpleChanges,
|
SimpleChanges,
|
||||||
|
Type,
|
||||||
ViewChild,
|
ViewChild,
|
||||||
ViewContainerRef,
|
ViewContainerRef,
|
||||||
ViewEncapsulation
|
ViewEncapsulation
|
||||||
@ -114,7 +115,7 @@ import { MobileService } from '@core/services/mobile.service';
|
|||||||
import { DialogService } from '@core/services/dialog.service';
|
import { DialogService } from '@core/services/dialog.service';
|
||||||
import { PopoverPlacement } from '@shared/components/popover.models';
|
import { PopoverPlacement } from '@shared/components/popover.models';
|
||||||
import { TbPopoverService } from '@shared/components/popover.service';
|
import { TbPopoverService } from '@shared/components/popover.service';
|
||||||
import { DASHBOARD_PAGE_COMPONENT_TOKEN } from '@home/components/tokens';
|
import { DASHBOARD_PAGE_COMPONENT_TOKEN, HOME_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-widget',
|
selector: 'tb-widget',
|
||||||
@ -190,6 +191,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
private popoverService: TbPopoverService,
|
private popoverService: TbPopoverService,
|
||||||
@Inject(EMBED_DASHBOARD_DIALOG_TOKEN) private embedDashboardDialogComponent: ComponentType<any>,
|
@Inject(EMBED_DASHBOARD_DIALOG_TOKEN) private embedDashboardDialogComponent: ComponentType<any>,
|
||||||
@Inject(DASHBOARD_PAGE_COMPONENT_TOKEN) private dashboardPageComponent: ComponentType<any>,
|
@Inject(DASHBOARD_PAGE_COMPONENT_TOKEN) private dashboardPageComponent: ComponentType<any>,
|
||||||
|
@Inject(HOME_COMPONENTS_MODULE_TOKEN) private homeComponentsModule: Type<any>,
|
||||||
private widgetService: WidgetService,
|
private widgetService: WidgetService,
|
||||||
private resources: ResourcesService,
|
private resources: ResourcesService,
|
||||||
private timeService: TimeService,
|
private timeService: TimeService,
|
||||||
@ -354,7 +356,8 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
this.subscriptionContext.widgetUtils = this.widgetContext.utils;
|
this.subscriptionContext.widgetUtils = this.widgetContext.utils;
|
||||||
this.subscriptionContext.getServerTimeDiff = this.dashboardService.getServerTimeDiff.bind(this.dashboardService);
|
this.subscriptionContext.getServerTimeDiff = this.dashboardService.getServerTimeDiff.bind(this.dashboardService);
|
||||||
|
|
||||||
this.widgetComponentService.getWidgetInfo(this.widget.bundleAlias, this.widget.typeAlias, this.widget.isSystemType).subscribe(
|
this.widgetComponentService.getWidgetInfo(this.widget.bundleAlias, this.widget.typeAlias, this.widget.isSystemType,
|
||||||
|
[this.homeComponentsModule]).subscribe(
|
||||||
(widgetInfo) => {
|
(widgetInfo) => {
|
||||||
this.widgetInfo = widgetInfo;
|
this.widgetInfo = widgetInfo;
|
||||||
this.loadFromWidgetInfo();
|
this.loadFromWidgetInfo();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user