From f6801b19974329edfde79e25e4e6ee4d7c1b59a0 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 13 May 2020 19:31:49 +0100 Subject: [PATCH] [ADF-5106] fix stencil registration (#5694) * customize services on the module level * improved service registration --- .../cloud/form-demo/cloud-form-demo.component.ts | 9 ++++++--- .../src/app/components/form/form.component.ts | 6 ++++-- .../services/dynamic-component-mapper.service.ts | 11 +++++++++++ .../form/components/cloud-form-rendering.service.ts | 13 ++++++++----- .../src/lib/form/components/form-cloud.component.ts | 7 +------ .../src/lib/form/form-cloud.module.ts | 5 ++--- .../src/lib/process-services-cloud.module.ts | 7 +++++-- lib/process-services/src/lib/form/form.component.ts | 8 ++------ .../src/lib/form/process-form-rendering.service.ts | 7 +++++-- lib/process-services/src/lib/process.module.ts | 7 +++++-- .../components/task-form/task-form.component.ts | 6 ------ 11 files changed, 49 insertions(+), 37 deletions(-) diff --git a/demo-shell/src/app/components/app-layout/cloud/form-demo/cloud-form-demo.component.ts b/demo-shell/src/app/components/app-layout/cloud/form-demo/cloud-form-demo.component.ts index 9148af01bd..481e1aa42c 100644 --- a/demo-shell/src/app/components/app-layout/cloud/form-demo/cloud-form-demo.component.ts +++ b/demo-shell/src/app/components/app-layout/cloud/form-demo/cloud-form-demo.component.ts @@ -16,13 +16,16 @@ */ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { FormFieldModel, NotificationService, CoreAutomationService, FormModel } from '@alfresco/adf-core'; -import { FormCloudService } from '@alfresco/adf-process-services-cloud'; +import { FormFieldModel, NotificationService, CoreAutomationService, FormModel, FormRenderingService } from '@alfresco/adf-core'; +import { FormCloudService, CloudFormRenderingService } from '@alfresco/adf-process-services-cloud'; import { Subscription } from 'rxjs'; @Component({ templateUrl: 'cloud-form-demo.component.html', - styleUrls: ['cloud-form-demo.component.scss'] + styleUrls: ['cloud-form-demo.component.scss'], + providers: [ + { provide: FormRenderingService, useClass: CloudFormRenderingService } + ] }) export class FormCloudDemoComponent implements OnInit, OnDestroy { diff --git a/demo-shell/src/app/components/form/form.component.ts b/demo-shell/src/app/components/form/form.component.ts index 8559e4d031..7a4843c055 100644 --- a/demo-shell/src/app/components/form/form.component.ts +++ b/demo-shell/src/app/components/form/form.component.ts @@ -16,7 +16,8 @@ */ import { Component, Inject, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; -import { FormModel, FormFieldModel, FormService, FormOutcomeEvent, NotificationService, CoreAutomationService } from '@alfresco/adf-core'; +import { FormModel, FormFieldModel, FormService, FormOutcomeEvent, NotificationService, CoreAutomationService, FormRenderingService } from '@alfresco/adf-core'; +import { ProcessFormRenderingService } from '@alfresco/adf-process-services'; import { InMemoryFormService } from '../../services/in-memory-form.service'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -26,7 +27,8 @@ import { takeUntil } from 'rxjs/operators'; templateUrl: 'form.component.html', styleUrls: ['form.component.scss'], providers: [ - { provide: FormService, useClass: InMemoryFormService } + { provide: FormService, useClass: InMemoryFormService }, + { provide: FormRenderingService, useClass: ProcessFormRenderingService } ], encapsulation: ViewEncapsulation.None }) diff --git a/lib/core/services/dynamic-component-mapper.service.ts b/lib/core/services/dynamic-component-mapper.service.ts index 27914ddc2d..4f7d1836c0 100644 --- a/lib/core/services/dynamic-component-mapper.service.ts +++ b/lib/core/services/dynamic-component-mapper.service.ts @@ -67,6 +67,17 @@ export abstract class DynamicComponentMapper { this.types[type] = resolver; } + /** + * Register multiple components + */ + register(components: { [key: string]: DynamicComponentResolveFunction }, override: boolean = false) { + if (components) { + for (const type of Object.keys(components)) { + this.setComponentTypeResolver(type, components[type], override); + } + } + } + /** * Finds the component type that is needed to render a form field. * @param model Form field model for the field to render diff --git a/lib/process-services-cloud/src/lib/form/components/cloud-form-rendering.service.ts b/lib/process-services-cloud/src/lib/form/components/cloud-form-rendering.service.ts index ceb26f72e4..7fa023a70f 100644 --- a/lib/process-services-cloud/src/lib/form/components/cloud-form-rendering.service.ts +++ b/lib/process-services-cloud/src/lib/form/components/cloud-form-rendering.service.ts @@ -29,10 +29,13 @@ import { GroupCloudWidgetComponent } from './widgets/group/group-cloud.widget'; export class CloudFormRenderingService extends FormRenderingService { constructor() { super(); - this.setComponentTypeResolver('upload', () => AttachFileCloudWidgetComponent, true); - this.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true); - this.setComponentTypeResolver('date', () => DateCloudWidgetComponent, true); - this.setComponentTypeResolver('people', () => PeopleCloudWidgetComponent, true); - this.setComponentTypeResolver('functional-group', () => GroupCloudWidgetComponent, true); + + this.register({ + 'upload': () => AttachFileCloudWidgetComponent, + 'dropdown': () => DropdownCloudWidgetComponent, + 'date': () => DateCloudWidgetComponent, + 'people': () => PeopleCloudWidgetComponent, + 'functional-group': () => GroupCloudWidgetComponent + }, true); } } diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts index 9deb10fedf..d439f790ce 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts @@ -29,7 +29,6 @@ import { WidgetVisibilityService, FormService, NotificationService, - FormRenderingService, FORM_FIELD_VALIDATORS, FormFieldValidator, FormValues, @@ -40,14 +39,10 @@ import { import { FormCloudService } from '../services/form-cloud.service'; import { TaskVariableCloud } from '../models/task-variable-cloud.model'; import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model'; -import { CloudFormRenderingService } from './cloud-form-rendering.service'; @Component({ selector: 'adf-cloud-form', - templateUrl: './form-cloud.component.html', - providers: [ - { provide: FormRenderingService, useClass: CloudFormRenderingService } - ] + templateUrl: './form-cloud.component.html' }) export class FormCloudComponent extends FormBaseComponent implements OnChanges, OnDestroy { diff --git a/lib/process-services-cloud/src/lib/form/form-cloud.module.ts b/lib/process-services-cloud/src/lib/form/form-cloud.module.ts index e950bf7b60..806be708a2 100644 --- a/lib/process-services-cloud/src/lib/form/form-cloud.module.ts +++ b/lib/process-services-cloud/src/lib/form/form-cloud.module.ts @@ -18,7 +18,7 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FlexLayoutModule } from '@angular/flex-layout'; -import { TemplateModule, FormBaseModule, PipeModule, CoreModule, FormRenderingService } from '@alfresco/adf-core'; +import { TemplateModule, FormBaseModule, PipeModule, CoreModule } from '@alfresco/adf-core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MaterialModule } from '../material.module'; import { FormCloudComponent } from './components/form-cloud.component'; @@ -64,8 +64,7 @@ import { GroupCloudModule } from '../group/group-cloud.module'; GroupCloudWidgetComponent ], providers: [ - FormDefinitionSelectorCloudService, - FormRenderingService + FormDefinitionSelectorCloudService ], entryComponents: [ UploadCloudWidgetComponent, diff --git a/lib/process-services-cloud/src/lib/process-services-cloud.module.ts b/lib/process-services-cloud/src/lib/process-services-cloud.module.ts index 0412f68c38..572cee6444 100644 --- a/lib/process-services-cloud/src/lib/process-services-cloud.module.ts +++ b/lib/process-services-cloud/src/lib/process-services-cloud.module.ts @@ -16,7 +16,7 @@ */ import { NgModule } from '@angular/core'; -import { TRANSLATION_PROVIDER, CoreModule } from '@alfresco/adf-core'; +import { TRANSLATION_PROVIDER, CoreModule, FormRenderingService } from '@alfresco/adf-core'; import { AppListCloudModule } from './app/app-list-cloud.module'; import { TaskCloudModule } from './task/task-cloud.module'; import { ProcessCloudModule } from './process/process-cloud.module'; @@ -30,6 +30,7 @@ import { TASK_FILTERS_SERVICE_TOKEN } from './services/public-api'; import { PeopleCloudModule } from './people/people-cloud.module'; +import { CloudFormRenderingService } from './form/components/cloud-form-rendering.service'; @NgModule({ imports: [ @@ -54,7 +55,9 @@ import { PeopleCloudModule } from './people/people-cloud.module'; UserPreferenceCloudService, LocalPreferenceCloudService, { provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }, - { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService } + { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }, + FormRenderingService, + { provide: FormRenderingService, useClass: CloudFormRenderingService } ], exports: [ AppListCloudModule, diff --git a/lib/process-services/src/lib/form/form.component.ts b/lib/process-services/src/lib/form/form.component.ts index f6efcee659..16c3b85317 100644 --- a/lib/process-services/src/lib/form/form.component.ts +++ b/lib/process-services/src/lib/form/form.component.ts @@ -17,20 +17,16 @@ import { Component, EventEmitter, Input, Output, ViewEncapsulation, SimpleChanges, OnInit, OnDestroy, OnChanges } from '@angular/core'; import { EcmModelService, NodeService, WidgetVisibilityService, - FormService, FormRenderingService, FormBaseComponent, FormOutcomeModel, + FormService, FormBaseComponent, FormOutcomeModel, FormEvent, FormErrorEvent, FormFieldModel, FormModel, FormOutcomeEvent, FormValues, ContentLinkModel } from '@alfresco/adf-core'; import { Observable, of, Subject } from 'rxjs'; import { switchMap, takeUntil } from 'rxjs/operators'; -import { ProcessFormRenderingService } from './process-form-rendering.service'; @Component({ selector: 'adf-form', templateUrl: './form.component.html', - encapsulation: ViewEncapsulation.None, - providers: [ - { provide: FormRenderingService, useClass: ProcessFormRenderingService } - ] + encapsulation: ViewEncapsulation.None }) export class FormComponent extends FormBaseComponent implements OnInit, OnDestroy, OnChanges { diff --git a/lib/process-services/src/lib/form/process-form-rendering.service.ts b/lib/process-services/src/lib/form/process-form-rendering.service.ts index dfaa2b993e..ff39a9bfe7 100644 --- a/lib/process-services/src/lib/form/process-form-rendering.service.ts +++ b/lib/process-services/src/lib/form/process-form-rendering.service.ts @@ -26,7 +26,10 @@ import { AttachFolderWidgetComponent } from '../content-widget/attach-folder-wid export class ProcessFormRenderingService extends FormRenderingService { constructor() { super(); - this.setComponentTypeResolver('upload', () => AttachFileWidgetComponent, true); - this.setComponentTypeResolver('select-folder', () => AttachFolderWidgetComponent, true); + + this.register({ + 'upload': () => AttachFileWidgetComponent, + 'select-folder': () => AttachFolderWidgetComponent + }, true); } } diff --git a/lib/process-services/src/lib/process.module.ts b/lib/process-services/src/lib/process.module.ts index da1639502b..264b697556 100644 --- a/lib/process-services/src/lib/process.module.ts +++ b/lib/process-services/src/lib/process.module.ts @@ -18,7 +18,7 @@ import { CommonModule } from '@angular/common'; import { NgModule, ModuleWithProviders } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { CoreModule, TRANSLATION_PROVIDER } from '@alfresco/adf-core'; +import { CoreModule, TRANSLATION_PROVIDER, FormRenderingService } from '@alfresco/adf-core'; import { MaterialModule } from './material.module'; @@ -29,6 +29,7 @@ import { ProcessCommentsModule } from './process-comments/process-comments.modul import { AttachmentModule } from './attachment/attachment.module'; import { PeopleModule } from './people/people.module'; import { FormModule } from './form/form.module'; +import { ProcessFormRenderingService } from './form/process-form-rendering.service'; @NgModule({ imports: [ @@ -80,7 +81,9 @@ export class ProcessModule { name: 'adf-process-services', source: 'assets/adf-process-services' } - } + }, + FormRenderingService, + { provide: FormRenderingService, useClass: ProcessFormRenderingService } ] }; } diff --git a/lib/process-services/src/lib/task-list/components/task-form/task-form.component.ts b/lib/process-services/src/lib/task-list/components/task-form/task-form.component.ts index 0cd3b8188a..b53caf4ee3 100644 --- a/lib/process-services/src/lib/task-list/components/task-form/task-form.component.ts +++ b/lib/process-services/src/lib/task-list/components/task-form/task-form.component.ts @@ -19,7 +19,6 @@ import { Component, OnInit, Input, Output, EventEmitter, SimpleChanges } from '@ import { FormModel, ContentLinkModel, - FormRenderingService, FormFieldValidator, FormOutcomeEvent, AuthenticationService, @@ -29,8 +28,6 @@ import { import { TaskDetailsModel } from '../../models/task-details.model'; import { TaskListService } from '../../services/tasklist.service'; import { UserRepresentation } from '@alfresco/js-api'; -import { AttachFileWidgetComponent } from '../../../content-widget/attach-file-widget.component'; -import { AttachFolderWidgetComponent } from '../../../content-widget/attach-folder-widget.component'; import { Observable } from 'rxjs'; @Component({ @@ -129,11 +126,8 @@ export class TaskFormComponent implements OnInit { constructor( private taskListService: TaskListService, private authService: AuthenticationService, - private formRenderingService: FormRenderingService, private translationService: TranslationService ) { - this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileWidgetComponent, true); - this.formRenderingService.setComponentTypeResolver('select-folder', () => AttachFolderWidgetComponent, true); } ngOnInit() {