[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 { 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 {

View File

@ -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
})

View File

@ -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

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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,

View File

@ -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,

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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 }
]
};
}

View File

@ -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() {