From ab844525c3ccd2dc20d99cde068cfe140e98a890 Mon Sep 17 00:00:00 2001 From: Chantsova Ekaterina Date: Tue, 2 May 2023 12:54:45 +0300 Subject: [PATCH] Change approach of adding custom modules to a custom dialog --- .../custom-action-pretty-editor.component.html | 2 +- ...om-action-pretty-resources-tabs.component.html | 2 +- .../widget/dialog/custom-dialog.service.ts | 11 ++++++++--- .../components/widget/widget-components.module.ts | 4 ---- .../home/components/widget/widget.component.ts | 15 ++++++++------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html index 1d72b6c05a..727b5655df 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-editor.component.html @@ -51,7 +51,7 @@ [(ngModel)]="action.customFunction" (ngModelChange)="onActionUpdated()" [fillHeight]="true" - [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel', 'customModules']" + [functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']" [disableUndefinedCheck]="true" [validationArgs]="[]" [editorCompleter]="customPrettyActionEditorCompleter" diff --git a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html index 3e4564f505..7014570235 100644 --- a/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/action/custom-action-pretty-resources-tabs.component.html @@ -94,7 +94,7 @@ > + constructor( private translate: TranslateService, private authService: AuthService, @@ -45,11 +46,15 @@ export class CustomDialogService { ) { } + setAdditionalModules(modules: Array>) { + this.customModules = modules; + } + customDialog(template: string, controller: (instance: CustomDialogComponent) => void, data?: any, config?: MatDialogConfig): Observable { const modules = [this.sharedModule, CommonModule, this.sharedHomeComponentsModule, this.homeComponentsModule]; - if (isObject(data) && data.hasOwnProperty('customModules')) { - modules.push(...data.customModules); + if (Array.isArray(this.customModules)) { + modules.push(...this.customModules); } return this.dynamicComponentFactoryService.createDynamicComponentFactory( class CustomDialogComponentInstance extends CustomDialogComponent {}, template, modules).pipe( diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-components.module.ts b/ui-ngx/src/app/modules/home/components/widget/widget-components.module.ts index 9d3b6a737b..4f0454bb1c 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-components.module.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget-components.module.ts @@ -23,7 +23,6 @@ import { AlarmsTableWidgetComponent } from '@home/components/widget/lib/alarms-t import { SharedHomeComponentsModule } from '@home/components/shared-home-components.module'; import { TimeseriesTableWidgetComponent } from '@home/components/widget/lib/timeseries-table-widget.component'; import { EntitiesHierarchyWidgetComponent } from '@home/components/widget/lib/entities-hierarchy-widget.component'; -import { CustomDialogService } from '@home/components/widget/dialog/custom-dialog.service'; import { RpcWidgetsModule } from '@home/components/widget/lib/rpc/rpc-widgets.module'; import { DateRangeNavigatorPanelComponent, @@ -33,7 +32,6 @@ import { MultipleInputWidgetComponent } from '@home/components/widget/lib/multip import { TripAnimationComponent } from '@home/components/widget/trip-animation/trip-animation.component'; import { PhotoCameraInputWidgetComponent } from '@home/components/widget/lib/photo-camera-input.component'; import { GatewayFormComponent } from '@home/components/widget/lib/gateway/gateway-form.component'; -import { ImportExportService } from '@home/components/import-export/import-export.service'; import { NavigationCardsWidgetComponent } from '@home/components/widget/lib/navigation-cards-widget.component'; import { NavigationCardWidgetComponent } from '@home/components/widget/lib/navigation-card-widget.component'; import { EdgesOverviewWidgetComponent } from '@home/components/widget/lib/edges-overview-widget.component'; @@ -93,8 +91,6 @@ import { WIDGET_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens'; MarkdownWidgetComponent ], providers: [ - CustomDialogService, - ImportExportService, {provide: WIDGET_COMPONENTS_MODULE_TOKEN, useValue: WidgetComponentsModule } ] }) 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 ed301988a0..5a3b55bf2d 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 @@ -92,7 +92,7 @@ import { EntityId } from '@shared/models/id/entity-id'; import { ActivatedRoute, Router } from '@angular/router'; import cssjs from '@core/css/css'; import { ModulesWithFactories, ResourcesService } from '@core/services/resources.service'; -import { catchError, map, mergeMap, switchMap } from 'rxjs/operators'; +import { catchError, map, switchMap } from 'rxjs/operators'; import { ActionNotificationShow } from '@core/notification/notification.actions'; import { TimeService } from '@core/services/time.service'; import { DeviceService } from '@app/core/http/device.service'; @@ -1165,25 +1165,26 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI if (isDefined(customHtml) && customHtml.length > 0) { htmlTemplate = customHtml; } - this.loadCustomActionResources(actionNamespace, customCss, customResources, descriptor).subscribe( - () => { + this.loadCustomActionResources(actionNamespace, customCss, customResources, descriptor).subscribe({ + next: () => { if (isDefined(customPrettyFunction) && customPrettyFunction.length > 0) { try { if (!additionalParams) { additionalParams = {}; } const customActionPrettyFunction = new Function('$event', 'widgetContext', 'entityId', - 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel', 'customModules', customPrettyFunction); - customActionPrettyFunction($event, this.widgetContext, entityId, entityName, htmlTemplate, additionalParams, entityLabel, descriptor.customModules); + 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel', customPrettyFunction); + this.widgetContext.customDialog.setAdditionalModules(descriptor.customModules); + customActionPrettyFunction($event, this.widgetContext, entityId, entityName, htmlTemplate, additionalParams, entityLabel); } catch (e) { console.error(e); } } }, - (errorMessages: string[]) => { + error: (errorMessages: string[]) => { this.processResourcesLoadErrors(errorMessages); } - ); + }); break; case WidgetActionType.mobileAction: const mobileAction = descriptor.mobileAction;