From 2aec503830587684d130e4fbe36f9f4de984beb6 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 28 Dec 2022 14:35:29 +0200 Subject: [PATCH] Revert "Solved issue of a re-init Widget-Component service and widgets-info Cache." This reverts commit 2b0fa4c4 --- .../dashboard-page.component.ts | 6 +--- .../home/components/home-components.module.ts | 2 ++ .../widget/widget-component.service.ts | 31 ++++++++----------- .../components/widget/widget.component.ts | 7 ++--- 4 files changed, 18 insertions(+), 28 deletions(-) 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 fb91752830..b0984a65fb 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 @@ -31,7 +31,6 @@ import { Optional, Renderer2, StaticProvider, - Type, ViewChild, ViewContainerRef, ViewEncapsulation @@ -152,7 +151,6 @@ import { tap } from 'rxjs/operators'; import { LayoutFixedSize, LayoutWidthType } from '@home/components/dashboard-page/layout/layout.models'; import { TbPopoverComponent } from '@shared/components/popover.component'; import { ResizeObserver } from '@juggle/resize-observer'; -import { HOME_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens'; // @dynamic @Component({ @@ -341,7 +339,6 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC constructor(protected store: Store, @Inject(WINDOW) private window: Window, @Inject(DOCUMENT) private document: Document, - @Inject(HOME_COMPONENTS_MODULE_TOKEN) private homeComponentsModule: Type, private breakpointObserver: BreakpointObserver, private route: ActivatedRoute, private router: Router, @@ -1147,8 +1144,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC addWidgetFromType(widget: WidgetInfo) { this.onAddWidgetClosed(); this.searchBundle = ''; - this.widgetComponentService.getWidgetInfo(widget.bundleAlias, widget.typeAlias, widget.isSystemType, - [this.homeComponentsModule]).subscribe( + this.widgetComponentService.getWidgetInfo(widget.bundleAlias, widget.typeAlias, widget.isSystemType).subscribe( (widgetTypeInfo) => { const config: WidgetConfig = JSON.parse(widgetTypeInfo.defaultConfig); config.title = 'New ' + widgetTypeInfo.widgetName; diff --git a/ui-ngx/src/app/modules/home/components/home-components.module.ts b/ui-ngx/src/app/modules/home/components/home-components.module.ts index 669fde14ff..7cfcf269de 100644 --- a/ui-ngx/src/app/modules/home/components/home-components.module.ts +++ b/ui-ngx/src/app/modules/home/components/home-components.module.ts @@ -35,6 +35,7 @@ import { AddAttributeDialogComponent } from '@home/components/attribute/add-attr import { EditAttributeValuePanelComponent } from '@home/components/attribute/edit-attribute-value-panel.component'; import { DashboardComponent } from '@home/components/dashboard/dashboard.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 { AliasesEntitySelectPanelComponent } from '@home/components/alias/aliases-entity-select-panel.component'; import { AliasesEntitySelectComponent } from '@home/components/alias/aliases-entity-select.component'; @@ -455,6 +456,7 @@ import { AssetProfileAutocompleteComponent } from '@home/components/profile/asse RateLimitsDetailsDialogComponent ], providers: [ + WidgetComponentService, CustomDialogService, ImportExportService, {provide: EMBED_DASHBOARD_DIALOG_TOKEN, useValue: EmbedDashboardDialogComponent}, diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts b/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts index 9a4f941211..38b14fe485 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget-component.service.ts @@ -45,13 +45,13 @@ import { MODULES_MAP } from '@shared/public-api'; import * as tinycolor_ from 'tinycolor2'; import moment from 'moment'; 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'; const tinycolor = tinycolor_; -@Injectable({ - providedIn: 'root' -}) +// @dynamic +@Injectable() export class WidgetComponentService { private cssParser = new cssjs(); @@ -68,6 +68,7 @@ export class WidgetComponentService { constructor(@Inject(WINDOW) private window: Window, @Optional() @Inject(MODULES_MAP) private modulesMap: IModulesMap, + @Inject(HOME_COMPONENTS_MODULE_TOKEN) private homeComponentsModule: Type, private dynamicComponentFactoryService: DynamicComponentFactoryService, private widgetService: WidgetService, private utils: UtilsService, @@ -184,9 +185,9 @@ export class WidgetComponentService { () => { const loadDefaultWidgetInfoTasks = [ this.loadWidgetResources(this.missingWidgetType, 'global-widget-missing-type', - [SharedModule, WidgetComponentsModule]), + [SharedModule, WidgetComponentsModule, this.homeComponentsModule]), this.loadWidgetResources(this.errorWidgetType, 'global-widget-error-type', - [SharedModule, WidgetComponentsModule]), + [SharedModule, WidgetComponentsModule, this.homeComponentsModule]), ]; forkJoin(loadDefaultWidgetInfoTasks).subscribe( () => { @@ -230,14 +231,13 @@ export class WidgetComponentService { } } - public getWidgetInfo(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean, modules?: Type[]): Observable { + public getWidgetInfo(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean): Observable { return this.init().pipe( - mergeMap(() => this.getWidgetInfoInternal(bundleAlias, widgetTypeAlias, isSystem, modules)) + mergeMap(() => this.getWidgetInfoInternal(bundleAlias, widgetTypeAlias, isSystem)) ); } - private getWidgetInfoInternal(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean, - modules?: Type[]): Observable { + private getWidgetInfoInternal(bundleAlias: string, widgetTypeAlias: string, isSystem: boolean): Observable { const widgetInfoSubject = new ReplaySubject(); const widgetInfo = this.getWidgetInfoFromCache(bundleAlias, widgetTypeAlias, isSystem); if (widgetInfo) { @@ -245,7 +245,7 @@ export class WidgetComponentService { widgetInfoSubject.complete(); } else { if (this.utils.widgetEditMode) { - this.loadWidget(this.editingWidgetType, bundleAlias, isSystem, widgetInfoSubject, modules); + this.loadWidget(this.editingWidgetType, bundleAlias, isSystem, widgetInfoSubject); } else { const key = this.createWidgetInfoCacheKey(bundleAlias, widgetTypeAlias, isSystem); let fetchQueue = this.widgetsInfoFetchQueue.get(key); @@ -256,7 +256,7 @@ export class WidgetComponentService { this.widgetsInfoFetchQueue.set(key, fetchQueue); this.widgetService.getWidgetType(bundleAlias, widgetTypeAlias, isSystem, {ignoreErrors: true}).subscribe( (widgetType) => { - this.loadWidget(widgetType, bundleAlias, isSystem, widgetInfoSubject, modules); + this.loadWidget(widgetType, bundleAlias, isSystem, widgetInfoSubject); }, () => { widgetInfoSubject.next(this.missingWidgetType); @@ -270,8 +270,7 @@ export class WidgetComponentService { return widgetInfoSubject.asObservable(); } - private loadWidget(widgetType: WidgetType, bundleAlias: string, isSystem: boolean, widgetInfoSubject: Subject, - modules?: Type[]) { + private loadWidget(widgetType: WidgetType, bundleAlias: string, isSystem: boolean, widgetInfoSubject: Subject) { const widgetInfo = toWidgetInfo(widgetType); const key = this.createWidgetInfoCacheKey(bundleAlias, widgetInfo.alias, isSystem); let widgetControllerDescriptor: WidgetControllerDescriptor = null; @@ -284,11 +283,7 @@ export class WidgetComponentService { } if (widgetControllerDescriptor) { const widgetNamespace = `widget-type-${(isSystem ? 'sys-' : '')}${bundleAlias}-${widgetInfo.alias}`; - const widgetModules = [SharedModule, WidgetComponentsModule]; - if (modules) { - widgetModules.push(...modules); - } - this.loadWidgetResources(widgetInfo, widgetNamespace, widgetModules).subscribe( + this.loadWidgetResources(widgetInfo, widgetNamespace, [SharedModule, WidgetComponentsModule, this.homeComponentsModule]).subscribe( () => { if (widgetControllerDescriptor.settingsSchema) { widgetInfo.typeSettingsSchema = widgetControllerDescriptor.settingsSchema; diff --git a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts index cfb95ef97a..baa0664a31 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts @@ -31,7 +31,6 @@ import { OnInit, Renderer2, SimpleChanges, - Type, ViewChild, ViewContainerRef, ViewEncapsulation @@ -115,7 +114,7 @@ import { MobileService } from '@core/services/mobile.service'; import { DialogService } from '@core/services/dialog.service'; import { PopoverPlacement } from '@shared/components/popover.models'; import { TbPopoverService } from '@shared/components/popover.service'; -import { DASHBOARD_PAGE_COMPONENT_TOKEN, HOME_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens'; +import { DASHBOARD_PAGE_COMPONENT_TOKEN } from '@home/components/tokens'; @Component({ selector: 'tb-widget', @@ -191,7 +190,6 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI private popoverService: TbPopoverService, @Inject(EMBED_DASHBOARD_DIALOG_TOKEN) private embedDashboardDialogComponent: ComponentType, @Inject(DASHBOARD_PAGE_COMPONENT_TOKEN) private dashboardPageComponent: ComponentType, - @Inject(HOME_COMPONENTS_MODULE_TOKEN) private homeComponentsModule: Type, private widgetService: WidgetService, private resources: ResourcesService, private timeService: TimeService, @@ -356,8 +354,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI this.subscriptionContext.widgetUtils = this.widgetContext.utils; this.subscriptionContext.getServerTimeDiff = this.dashboardService.getServerTimeDiff.bind(this.dashboardService); - this.widgetComponentService.getWidgetInfo(this.widget.bundleAlias, this.widget.typeAlias, this.widget.isSystemType, - [this.homeComponentsModule]).subscribe( + this.widgetComponentService.getWidgetInfo(this.widget.bundleAlias, this.widget.typeAlias, this.widget.isSystemType).subscribe( (widgetInfo) => { this.widgetInfo = widgetInfo; this.loadFromWidgetInfo();