[ADF-5106] fix stencil registration (#5694)

* customize services on the module level

* improved service registration
This commit is contained in:
Denys Vuika 2020-05-13 19:31:49 +01:00 committed by GitHub
parent 2b7943919d
commit f6801b1997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 49 additions and 37 deletions

View File

@ -16,13 +16,16 @@
*/ */
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormFieldModel, NotificationService, CoreAutomationService, FormModel } from '@alfresco/adf-core'; import { FormFieldModel, NotificationService, CoreAutomationService, FormModel, FormRenderingService } from '@alfresco/adf-core';
import { FormCloudService } from '@alfresco/adf-process-services-cloud'; import { FormCloudService, CloudFormRenderingService } from '@alfresco/adf-process-services-cloud';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
@Component({ @Component({
templateUrl: 'cloud-form-demo.component.html', 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 { export class FormCloudDemoComponent implements OnInit, OnDestroy {

View File

@ -16,7 +16,8 @@
*/ */
import { Component, Inject, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; 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 { InMemoryFormService } from '../../services/in-memory-form.service';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
@ -26,7 +27,8 @@ import { takeUntil } from 'rxjs/operators';
templateUrl: 'form.component.html', templateUrl: 'form.component.html',
styleUrls: ['form.component.scss'], styleUrls: ['form.component.scss'],
providers: [ providers: [
{ provide: FormService, useClass: InMemoryFormService } { provide: FormService, useClass: InMemoryFormService },
{ provide: FormRenderingService, useClass: ProcessFormRenderingService }
], ],
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })

View File

@ -67,6 +67,17 @@ export abstract class DynamicComponentMapper {
this.types[type] = resolver; 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. * Finds the component type that is needed to render a form field.
* @param model Form field model for the field to render * @param model Form field model for the field to render

View File

@ -29,10 +29,13 @@ import { GroupCloudWidgetComponent } from './widgets/group/group-cloud.widget';
export class CloudFormRenderingService extends FormRenderingService { export class CloudFormRenderingService extends FormRenderingService {
constructor() { constructor() {
super(); super();
this.setComponentTypeResolver('upload', () => AttachFileCloudWidgetComponent, true);
this.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true); this.register({
this.setComponentTypeResolver('date', () => DateCloudWidgetComponent, true); 'upload': () => AttachFileCloudWidgetComponent,
this.setComponentTypeResolver('people', () => PeopleCloudWidgetComponent, true); 'dropdown': () => DropdownCloudWidgetComponent,
this.setComponentTypeResolver('functional-group', () => GroupCloudWidgetComponent, true); 'date': () => DateCloudWidgetComponent,
'people': () => PeopleCloudWidgetComponent,
'functional-group': () => GroupCloudWidgetComponent
}, true);
} }
} }

View File

@ -29,7 +29,6 @@ import {
WidgetVisibilityService, WidgetVisibilityService,
FormService, FormService,
NotificationService, NotificationService,
FormRenderingService,
FORM_FIELD_VALIDATORS, FORM_FIELD_VALIDATORS,
FormFieldValidator, FormFieldValidator,
FormValues, FormValues,
@ -40,14 +39,10 @@ import {
import { FormCloudService } from '../services/form-cloud.service'; import { FormCloudService } from '../services/form-cloud.service';
import { TaskVariableCloud } from '../models/task-variable-cloud.model'; import { TaskVariableCloud } from '../models/task-variable-cloud.model';
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model'; import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
import { CloudFormRenderingService } from './cloud-form-rendering.service';
@Component({ @Component({
selector: 'adf-cloud-form', selector: 'adf-cloud-form',
templateUrl: './form-cloud.component.html', templateUrl: './form-cloud.component.html'
providers: [
{ provide: FormRenderingService, useClass: CloudFormRenderingService }
]
}) })
export class FormCloudComponent extends FormBaseComponent implements OnChanges, OnDestroy { export class FormCloudComponent extends FormBaseComponent implements OnChanges, OnDestroy {

View File

@ -18,7 +18,7 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { FlexLayoutModule } from '@angular/flex-layout'; 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 { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MaterialModule } from '../material.module'; import { MaterialModule } from '../material.module';
import { FormCloudComponent } from './components/form-cloud.component'; import { FormCloudComponent } from './components/form-cloud.component';
@ -64,8 +64,7 @@ import { GroupCloudModule } from '../group/group-cloud.module';
GroupCloudWidgetComponent GroupCloudWidgetComponent
], ],
providers: [ providers: [
FormDefinitionSelectorCloudService, FormDefinitionSelectorCloudService
FormRenderingService
], ],
entryComponents: [ entryComponents: [
UploadCloudWidgetComponent, UploadCloudWidgetComponent,

View File

@ -16,7 +16,7 @@
*/ */
import { NgModule } from '@angular/core'; 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 { AppListCloudModule } from './app/app-list-cloud.module';
import { TaskCloudModule } from './task/task-cloud.module'; import { TaskCloudModule } from './task/task-cloud.module';
import { ProcessCloudModule } from './process/process-cloud.module'; import { ProcessCloudModule } from './process/process-cloud.module';
@ -30,6 +30,7 @@ import {
TASK_FILTERS_SERVICE_TOKEN TASK_FILTERS_SERVICE_TOKEN
} from './services/public-api'; } from './services/public-api';
import { PeopleCloudModule } from './people/people-cloud.module'; import { PeopleCloudModule } from './people/people-cloud.module';
import { CloudFormRenderingService } from './form/components/cloud-form-rendering.service';
@NgModule({ @NgModule({
imports: [ imports: [
@ -54,7 +55,9 @@ import { PeopleCloudModule } from './people/people-cloud.module';
UserPreferenceCloudService, UserPreferenceCloudService,
LocalPreferenceCloudService, LocalPreferenceCloudService,
{ provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: 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: [ exports: [
AppListCloudModule, AppListCloudModule,

View File

@ -17,20 +17,16 @@
import { Component, EventEmitter, Input, Output, ViewEncapsulation, SimpleChanges, OnInit, OnDestroy, OnChanges } from '@angular/core'; import { Component, EventEmitter, Input, Output, ViewEncapsulation, SimpleChanges, OnInit, OnDestroy, OnChanges } from '@angular/core';
import { EcmModelService, NodeService, WidgetVisibilityService, import { EcmModelService, NodeService, WidgetVisibilityService,
FormService, FormRenderingService, FormBaseComponent, FormOutcomeModel, FormService, FormBaseComponent, FormOutcomeModel,
FormEvent, FormErrorEvent, FormFieldModel, FormEvent, FormErrorEvent, FormFieldModel,
FormModel, FormOutcomeEvent, FormValues, ContentLinkModel } from '@alfresco/adf-core'; FormModel, FormOutcomeEvent, FormValues, ContentLinkModel } from '@alfresco/adf-core';
import { Observable, of, Subject } from 'rxjs'; import { Observable, of, Subject } from 'rxjs';
import { switchMap, takeUntil } from 'rxjs/operators'; import { switchMap, takeUntil } from 'rxjs/operators';
import { ProcessFormRenderingService } from './process-form-rendering.service';
@Component({ @Component({
selector: 'adf-form', selector: 'adf-form',
templateUrl: './form.component.html', templateUrl: './form.component.html',
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None
providers: [
{ provide: FormRenderingService, useClass: ProcessFormRenderingService }
]
}) })
export class FormComponent extends FormBaseComponent implements OnInit, OnDestroy, OnChanges { export class FormComponent extends FormBaseComponent implements OnInit, OnDestroy, OnChanges {

View File

@ -26,7 +26,10 @@ import { AttachFolderWidgetComponent } from '../content-widget/attach-folder-wid
export class ProcessFormRenderingService extends FormRenderingService { export class ProcessFormRenderingService extends FormRenderingService {
constructor() { constructor() {
super(); super();
this.setComponentTypeResolver('upload', () => AttachFileWidgetComponent, true);
this.setComponentTypeResolver('select-folder', () => AttachFolderWidgetComponent, true); this.register({
'upload': () => AttachFileWidgetComponent,
'select-folder': () => AttachFolderWidgetComponent
}, true);
} }
} }

View File

@ -18,7 +18,7 @@
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { NgModule, ModuleWithProviders } from '@angular/core'; import { NgModule, ModuleWithProviders } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 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'; import { MaterialModule } from './material.module';
@ -29,6 +29,7 @@ import { ProcessCommentsModule } from './process-comments/process-comments.modul
import { AttachmentModule } from './attachment/attachment.module'; import { AttachmentModule } from './attachment/attachment.module';
import { PeopleModule } from './people/people.module'; import { PeopleModule } from './people/people.module';
import { FormModule } from './form/form.module'; import { FormModule } from './form/form.module';
import { ProcessFormRenderingService } from './form/process-form-rendering.service';
@NgModule({ @NgModule({
imports: [ imports: [
@ -80,7 +81,9 @@ export class ProcessModule {
name: 'adf-process-services', name: 'adf-process-services',
source: 'assets/adf-process-services' source: 'assets/adf-process-services'
} }
} },
FormRenderingService,
{ provide: FormRenderingService, useClass: ProcessFormRenderingService }
] ]
}; };
} }

View File

@ -19,7 +19,6 @@ import { Component, OnInit, Input, Output, EventEmitter, SimpleChanges } from '@
import { import {
FormModel, FormModel,
ContentLinkModel, ContentLinkModel,
FormRenderingService,
FormFieldValidator, FormFieldValidator,
FormOutcomeEvent, FormOutcomeEvent,
AuthenticationService, AuthenticationService,
@ -29,8 +28,6 @@ import {
import { TaskDetailsModel } from '../../models/task-details.model'; import { TaskDetailsModel } from '../../models/task-details.model';
import { TaskListService } from '../../services/tasklist.service'; import { TaskListService } from '../../services/tasklist.service';
import { UserRepresentation } from '@alfresco/js-api'; 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'; import { Observable } from 'rxjs';
@Component({ @Component({
@ -129,11 +126,8 @@ export class TaskFormComponent implements OnInit {
constructor( constructor(
private taskListService: TaskListService, private taskListService: TaskListService,
private authService: AuthenticationService, private authService: AuthenticationService,
private formRenderingService: FormRenderingService,
private translationService: TranslationService private translationService: TranslationService
) { ) {
this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileWidgetComponent, true);
this.formRenderingService.setComponentTypeResolver('select-folder', () => AttachFolderWidgetComponent, true);
} }
ngOnInit() { ngOnInit() {