Skip to content

Commit

Permalink
[ADF-5106] fix stencil registration (#5694)
Browse files Browse the repository at this point in the history
* customize services on the module level

* improved service registration
  • Loading branch information
DenysVuika committed May 13, 2020
1 parent 2b79439 commit f6801b1
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 37 deletions.
Expand Up @@ -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 {

Expand Down
6 changes: 4 additions & 2 deletions demo-shell/src/app/components/form/form.component.ts
Expand Up @@ -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';
Expand All @@ -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
})
Expand Down
11 changes: 11 additions & 0 deletions lib/core/services/dynamic-component-mapper.service.ts
Expand Up @@ -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
Expand Down
Expand Up @@ -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);
}
}
Expand Up @@ -29,7 +29,6 @@ import {
WidgetVisibilityService,
FormService,
NotificationService,
FormRenderingService,
FORM_FIELD_VALIDATORS,
FormFieldValidator,
FormValues,
Expand All @@ -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 {

Expand Down
5 changes: 2 additions & 3 deletions lib/process-services-cloud/src/lib/form/form-cloud.module.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -64,8 +64,7 @@ import { GroupCloudModule } from '../group/group-cloud.module';
GroupCloudWidgetComponent
],
providers: [
FormDefinitionSelectorCloudService,
FormRenderingService
FormDefinitionSelectorCloudService
],
entryComponents: [
UploadCloudWidgetComponent,
Expand Down
Expand Up @@ -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';
Expand All @@ -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: [
Expand All @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions lib/process-services/src/lib/form/form.component.ts
Expand Up @@ -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 {

Expand Down
Expand Up @@ -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);
}
}
7 changes: 5 additions & 2 deletions lib/process-services/src/lib/process.module.ts
Expand Up @@ -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';

Expand All @@ -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: [
Expand Down Expand Up @@ -80,7 +81,9 @@ export class ProcessModule {
name: 'adf-process-services',
source: 'assets/adf-process-services'
}
}
},
FormRenderingService,
{ provide: FormRenderingService, useClass: ProcessFormRenderingService }
]
};
}
Expand Down
Expand Up @@ -19,7 +19,6 @@ import { Component, OnInit, Input, Output, EventEmitter, SimpleChanges } from '@
import {
FormModel,
ContentLinkModel,
FormRenderingService,
FormFieldValidator,
FormOutcomeEvent,
AuthenticationService,
Expand All @@ -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({
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f6801b1

Please sign in to comment.