Change approach of adding custom modules to a custom dialog
This commit is contained in:
parent
bc93e16ced
commit
ab844525c3
@ -51,7 +51,7 @@
|
|||||||
[(ngModel)]="action.customFunction"
|
[(ngModel)]="action.customFunction"
|
||||||
(ngModelChange)="onActionUpdated()"
|
(ngModelChange)="onActionUpdated()"
|
||||||
[fillHeight]="true"
|
[fillHeight]="true"
|
||||||
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel', 'customModules']"
|
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']"
|
||||||
[disableUndefinedCheck]="true"
|
[disableUndefinedCheck]="true"
|
||||||
[validationArgs]="[]"
|
[validationArgs]="[]"
|
||||||
[editorCompleter]="customPrettyActionEditorCompleter"
|
[editorCompleter]="customPrettyActionEditorCompleter"
|
||||||
|
|||||||
@ -94,7 +94,7 @@
|
|||||||
<tb-js-func
|
<tb-js-func
|
||||||
[(ngModel)]="action.customFunction"
|
[(ngModel)]="action.customFunction"
|
||||||
(ngModelChange)="notifyActionUpdated()"
|
(ngModelChange)="notifyActionUpdated()"
|
||||||
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel', 'customModules']"
|
[functionArgs]="['$event', 'widgetContext', 'entityId', 'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel']"
|
||||||
[disableUndefinedCheck]="true"
|
[disableUndefinedCheck]="true"
|
||||||
[validationArgs]="[]"
|
[validationArgs]="[]"
|
||||||
[editorCompleter]="customPrettyActionEditorCompleter"
|
[editorCompleter]="customPrettyActionEditorCompleter"
|
||||||
|
|||||||
@ -29,11 +29,12 @@ import {
|
|||||||
} from '@home/components/widget/dialog/custom-dialog-container.component';
|
} from '@home/components/widget/dialog/custom-dialog-container.component';
|
||||||
import { SHARED_MODULE_TOKEN } from '@shared/components/tokens';
|
import { SHARED_MODULE_TOKEN } from '@shared/components/tokens';
|
||||||
import { HOME_COMPONENTS_MODULE_TOKEN, SHARED_HOME_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens';
|
import { HOME_COMPONENTS_MODULE_TOKEN, SHARED_HOME_COMPONENTS_MODULE_TOKEN } from '@home/components/tokens';
|
||||||
import { isObject } from '@core/utils';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CustomDialogService {
|
export class CustomDialogService {
|
||||||
|
|
||||||
|
private customModules: Array<Type<any>>
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private translate: TranslateService,
|
private translate: TranslateService,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
@ -45,11 +46,15 @@ export class CustomDialogService {
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setAdditionalModules(modules: Array<Type<any>>) {
|
||||||
|
this.customModules = modules;
|
||||||
|
}
|
||||||
|
|
||||||
customDialog(template: string, controller: (instance: CustomDialogComponent) => void, data?: any,
|
customDialog(template: string, controller: (instance: CustomDialogComponent) => void, data?: any,
|
||||||
config?: MatDialogConfig): Observable<any> {
|
config?: MatDialogConfig): Observable<any> {
|
||||||
const modules = [this.sharedModule, CommonModule, this.sharedHomeComponentsModule, this.homeComponentsModule];
|
const modules = [this.sharedModule, CommonModule, this.sharedHomeComponentsModule, this.homeComponentsModule];
|
||||||
if (isObject(data) && data.hasOwnProperty('customModules')) {
|
if (Array.isArray(this.customModules)) {
|
||||||
modules.push(...data.customModules);
|
modules.push(...this.customModules);
|
||||||
}
|
}
|
||||||
return this.dynamicComponentFactoryService.createDynamicComponentFactory(
|
return this.dynamicComponentFactoryService.createDynamicComponentFactory(
|
||||||
class CustomDialogComponentInstance extends CustomDialogComponent {}, template, modules).pipe(
|
class CustomDialogComponentInstance extends CustomDialogComponent {}, template, modules).pipe(
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import { AlarmsTableWidgetComponent } from '@home/components/widget/lib/alarms-t
|
|||||||
import { SharedHomeComponentsModule } from '@home/components/shared-home-components.module';
|
import { SharedHomeComponentsModule } from '@home/components/shared-home-components.module';
|
||||||
import { TimeseriesTableWidgetComponent } from '@home/components/widget/lib/timeseries-table-widget.component';
|
import { TimeseriesTableWidgetComponent } from '@home/components/widget/lib/timeseries-table-widget.component';
|
||||||
import { EntitiesHierarchyWidgetComponent } from '@home/components/widget/lib/entities-hierarchy-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 { RpcWidgetsModule } from '@home/components/widget/lib/rpc/rpc-widgets.module';
|
||||||
import {
|
import {
|
||||||
DateRangeNavigatorPanelComponent,
|
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 { TripAnimationComponent } from '@home/components/widget/trip-animation/trip-animation.component';
|
||||||
import { PhotoCameraInputWidgetComponent } from '@home/components/widget/lib/photo-camera-input.component';
|
import { PhotoCameraInputWidgetComponent } from '@home/components/widget/lib/photo-camera-input.component';
|
||||||
import { GatewayFormComponent } from '@home/components/widget/lib/gateway/gateway-form.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 { NavigationCardsWidgetComponent } from '@home/components/widget/lib/navigation-cards-widget.component';
|
||||||
import { NavigationCardWidgetComponent } from '@home/components/widget/lib/navigation-card-widget.component';
|
import { NavigationCardWidgetComponent } from '@home/components/widget/lib/navigation-card-widget.component';
|
||||||
import { EdgesOverviewWidgetComponent } from '@home/components/widget/lib/edges-overview-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
|
MarkdownWidgetComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
CustomDialogService,
|
|
||||||
ImportExportService,
|
|
||||||
{provide: WIDGET_COMPONENTS_MODULE_TOKEN, useValue: WidgetComponentsModule }
|
{provide: WIDGET_COMPONENTS_MODULE_TOKEN, useValue: WidgetComponentsModule }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@ -92,7 +92,7 @@ import { EntityId } from '@shared/models/id/entity-id';
|
|||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import cssjs from '@core/css/css';
|
import cssjs from '@core/css/css';
|
||||||
import { ModulesWithFactories, ResourcesService } from '@core/services/resources.service';
|
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 { ActionNotificationShow } from '@core/notification/notification.actions';
|
||||||
import { TimeService } from '@core/services/time.service';
|
import { TimeService } from '@core/services/time.service';
|
||||||
import { DeviceService } from '@app/core/http/device.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) {
|
if (isDefined(customHtml) && customHtml.length > 0) {
|
||||||
htmlTemplate = customHtml;
|
htmlTemplate = customHtml;
|
||||||
}
|
}
|
||||||
this.loadCustomActionResources(actionNamespace, customCss, customResources, descriptor).subscribe(
|
this.loadCustomActionResources(actionNamespace, customCss, customResources, descriptor).subscribe({
|
||||||
() => {
|
next: () => {
|
||||||
if (isDefined(customPrettyFunction) && customPrettyFunction.length > 0) {
|
if (isDefined(customPrettyFunction) && customPrettyFunction.length > 0) {
|
||||||
try {
|
try {
|
||||||
if (!additionalParams) {
|
if (!additionalParams) {
|
||||||
additionalParams = {};
|
additionalParams = {};
|
||||||
}
|
}
|
||||||
const customActionPrettyFunction = new Function('$event', 'widgetContext', 'entityId',
|
const customActionPrettyFunction = new Function('$event', 'widgetContext', 'entityId',
|
||||||
'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel', 'customModules', customPrettyFunction);
|
'entityName', 'htmlTemplate', 'additionalParams', 'entityLabel', customPrettyFunction);
|
||||||
customActionPrettyFunction($event, this.widgetContext, entityId, entityName, htmlTemplate, additionalParams, entityLabel, descriptor.customModules);
|
this.widgetContext.customDialog.setAdditionalModules(descriptor.customModules);
|
||||||
|
customActionPrettyFunction($event, this.widgetContext, entityId, entityName, htmlTemplate, additionalParams, entityLabel);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(errorMessages: string[]) => {
|
error: (errorMessages: string[]) => {
|
||||||
this.processResourcesLoadErrors(errorMessages);
|
this.processResourcesLoadErrors(errorMessages);
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
break;
|
break;
|
||||||
case WidgetActionType.mobileAction:
|
case WidgetActionType.mobileAction:
|
||||||
const mobileAction = descriptor.mobileAction;
|
const mobileAction = descriptor.mobileAction;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user