[ADF-2055] Ability to pre-populate form with a file and values (#2834)

* fix translations form

* fix style webpack script

* fix tslint error problem in viewer

* fix naming problems in attach file widget

* add start process form values data initialization option

* fix translation problems

* missing return type

* start process name configuration

* add CS cross PS configuration

* start process from file example

* fix minor issues

* add documentation and move the dialog in a separate component

* easy test select app

* alfrescoRepositoryName right property

* file conversion test

* fix issue after CR

* Remove forgotten semicolon.
This commit is contained in:
Eugenio Romano
2018-01-17 17:06:00 +00:00
committed by GitHub
parent 244234db4f
commit b1fd6cb60c
48 changed files with 789 additions and 344 deletions

View File

@@ -17,6 +17,7 @@
</mat-select>
</mat-form-field>
<adf-start-form *ngIf="hasStartForm()"
[data]="values"
[disableStartProcessButton]="!hasProcessName()"
[processDefinitionId]="currentProcessDef.id"
(outcomeClick)="onOutcomeClick($event)"

View File

@@ -23,7 +23,7 @@ import {
MatInputModule,
MatSelectModule
} from '@angular/material';
import { FormModule, FormService } from '@alfresco/adf-core';
import { ActivitiContentService, AppConfigService, FormModule, FormService } from '@alfresco/adf-core';
import { Observable } from 'rxjs/Observable';
import { ProcessInstanceVariable } from '../models/process-instance-variable.model';
@@ -33,6 +33,8 @@ import { StartProcessInstanceComponent } from './start-process.component';
describe('StartProcessInstanceComponent', () => {
let appConfig: AppConfigService;
let activitiContentService: ActivitiContentService;
let component: StartProcessInstanceComponent;
let fixture: ComponentFixture<StartProcessInstanceComponent>;
let processService: ProcessService;
@@ -54,6 +56,7 @@ describe('StartProcessInstanceComponent', () => {
StartProcessInstanceComponent
],
providers: [
ActivitiContentService,
ProcessService,
FormService
]
@@ -61,7 +64,8 @@ describe('StartProcessInstanceComponent', () => {
}));
beforeEach(() => {
appConfig = TestBed.get(AppConfigService);
activitiContentService = TestBed.get(ActivitiContentService);
fixture = TestBed.createComponent(StartProcessInstanceComponent);
component = fixture.componentInstance;
processService = fixture.debugElement.injector.get(ProcessService);
@@ -70,7 +74,7 @@ describe('StartProcessInstanceComponent', () => {
getDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(Observable.of(testProcessDefs));
startProcessSpy = spyOn(processService, 'startProcess').and.returnValue(Observable.of(newProcess));
getStartFormDefinitionSpy = spyOn(formService, 'getStartFormDefinition').and.returnValue(Observable.of(taskFormMock));
spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(Observable.of({ id: 1234 }));
});
it('should create instance of StartProcessInstanceComponent', () => {
@@ -81,7 +85,7 @@ describe('StartProcessInstanceComponent', () => {
it('should call service to fetch process definitions with appId', () => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
expect(getDefinitionsSpy).toHaveBeenCalledWith('123');
@@ -89,7 +93,7 @@ describe('StartProcessInstanceComponent', () => {
it('should call service to fetch process definitions without appId', () => {
let change = new SimpleChange(null, null, true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
expect(getDefinitionsSpy).toHaveBeenCalledWith(null);
@@ -97,7 +101,7 @@ describe('StartProcessInstanceComponent', () => {
it('should call service to fetch process definitions with appId when provided', () => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
expect(getDefinitionsSpy).toHaveBeenCalledWith('123');
@@ -105,7 +109,7 @@ describe('StartProcessInstanceComponent', () => {
it('should display the correct number of processes in the select list', () => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
let selectElement = fixture.nativeElement.querySelector('mat-select');
@@ -114,7 +118,7 @@ describe('StartProcessInstanceComponent', () => {
it('should display the option def details', () => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
component.processDefinitions = testProcessDefs;
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -131,7 +135,7 @@ describe('StartProcessInstanceComponent', () => {
it('should indicate an error to the user if process defs cannot be loaded', async(() => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.throw({}));
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -144,7 +148,7 @@ describe('StartProcessInstanceComponent', () => {
it('should show no process available message when no process definition is loaded', async(() => {
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of([]));
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -156,7 +160,7 @@ describe('StartProcessInstanceComponent', () => {
it('should auto-select process def from dropdown if there is just one process def', () => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
component.processDefinitions[0] = testProcessDefRepr;
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -183,17 +187,17 @@ describe('StartProcessInstanceComponent', () => {
}));
it('should reload processes when appId input changed', () => {
component.ngOnChanges({appId: change});
component.ngOnChanges({ appId: change });
expect(getDefinitionsSpy).toHaveBeenCalledWith(456);
});
it('should reload processes when appId input changed to null', () => {
component.ngOnChanges({appId: nullChange});
component.ngOnChanges({ appId: nullChange });
expect(getDefinitionsSpy).toHaveBeenCalledWith(null);
});
it('should get current processDeff', () => {
component.ngOnChanges({appId: change});
component.ngOnChanges({ appId: change });
component.onProcessDefChange('my:Process');
fixture.detectChanges();
expect(getDefinitionsSpy).toHaveBeenCalled();
@@ -206,7 +210,7 @@ describe('StartProcessInstanceComponent', () => {
beforeEach(() => {
component.name = 'My new process';
let change = new SimpleChange(null, 123, true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
});
it('should call service to start process if required fields provided', async(() => {
@@ -261,7 +265,7 @@ describe('StartProcessInstanceComponent', () => {
it('should throw error event when process cannot be started', async(() => {
let errorSpy = spyOn(component.error, 'error');
let error = {message: 'My error'};
let error = { message: 'My error' };
startProcessSpy = startProcessSpy.and.returnValue(Observable.throw(error));
component.onProcessDefChange('my:process1');
component.startProcess();
@@ -331,7 +335,7 @@ describe('StartProcessInstanceComponent', () => {
beforeEach(async(() => {
component.name = 'My new process';
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
fixture.detectChanges();
}));
@@ -374,7 +378,7 @@ describe('StartProcessInstanceComponent', () => {
beforeEach(() => {
getDefinitionsSpy.and.returnValue(Observable.of(testProcessDefWithForm));
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({'appId': change});
component.ngOnChanges({ 'appId': change });
component.onProcessDefChange('my:process1');
fixture.detectChanges();
fixture.whenStable();
@@ -397,7 +401,7 @@ describe('StartProcessInstanceComponent', () => {
}));
it('should emit cancel event on cancel Button', () => {
let cancelButton = fixture.nativeElement.querySelector('#cancle_process');
let cancelButton = fixture.nativeElement.querySelector('#cancle_process');
let cancelSpy: jasmine.Spy = spyOn(component.cancel, 'emit');
cancelButton.click();
fixture.detectChanges();
@@ -405,6 +409,35 @@ describe('StartProcessInstanceComponent', () => {
});
});
describe('CS content connection', () => {
fit('alfrescoRepositoryName default configuration property', () => {
expect(component.getAlfrescoRepositoryName()).toBe('alfresco-1Alfresco');
});
fit('alfrescoRepositoryName configuration property should be fetched', () => {
appConfig.config = Object.assign(appConfig.config, {
'alfrescoRepositoryName': 'alfresco-123'
};
expect(component.getAlfrescoRepositoryName()).toBe('alfresco-123Alfresco');
});
fit('if values in input is a node should be linked in the process service', () => {
component.values = {};
component.values['file'] = {
isFile: true,
name= 'example-file'
};
component.moveNodeFromCStoPS();
fixture.whenStable().then(() => {
expect(component.values.file[0].id).toBe(1234);
});
});
});
});
});

View File

@@ -15,8 +15,23 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core';
import { StartFormComponent, FormRenderingService } from '@alfresco/adf-core';
import {
Component,
EventEmitter,
Input,
OnChanges,
Output,
SimpleChanges,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import {
ActivitiContentService,
AppConfigService,
StartFormComponent,
FormRenderingService,
FormValues
} from '@alfresco/adf-core';
import { ProcessInstanceVariable } from '../models/process-instance-variable.model';
import { ProcessDefinitionRepresentation } from './../models/process-definition.model';
import { ProcessInstance } from './../models/process-instance.model';
@@ -37,6 +52,12 @@ export class StartProcessInstanceComponent implements OnChanges {
@Input()
variables: ProcessInstanceVariable[];
@Input()
values: FormValues;
@Input()
name: string;
@Output()
start: EventEmitter<ProcessInstance> = new EventEmitter<ProcessInstance>();
@@ -51,19 +72,23 @@ export class StartProcessInstanceComponent implements OnChanges {
processDefinitions: ProcessDefinitionRepresentation[] = [];
name: string;
currentProcessDef: ProcessDefinitionRepresentation = new ProcessDefinitionRepresentation();
errorMessageId: string = '';
constructor(private activitiProcess: ProcessService,
private formRenderingService: FormRenderingService) {
private formRenderingService: FormRenderingService,
private activitiContentService: ActivitiContentService,
private appConfig: AppConfigService) {
this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileWidgetComponent, true);
this.formRenderingService.setComponentTypeResolver('select-folder', () => AttachFolderWidgetComponent, true);
}
ngOnChanges(changes: SimpleChanges) {
if (changes['values'] && changes['values'].currentValue) {
this.moveNodeFromCStoPS();
}
let appIdChange = changes['appId'];
let appId = appIdChange ? appIdChange.currentValue : null;
this.load(appId);
@@ -82,6 +107,30 @@ export class StartProcessInstanceComponent implements OnChanges {
);
}
getAlfrescoRepositoryName(): string {
let alfrescoRepositoryName = this.appConfig.get<string>('alfrescoRepositoryName');
if (!alfrescoRepositoryName) {
alfrescoRepositoryName = 'alfresco-1';
}
return alfrescoRepositoryName + 'Alfresco';
}
moveNodeFromCStoPS() {
let accountIdentifier = this.getAlfrescoRepositoryName();
for (let key in this.values) {
if (this.values.hasOwnProperty(key)) {
let currentValue = this.values[key];
if (currentValue.isFile) {
this.activitiContentService.applyAlfrescoNode(currentValue, null, accountIdentifier).subscribe((res) => {
this.values[key] = [res];
});
}
}
}
}
public startProcess(outcome?: string) {
if (this.currentProcessDef.id && this.name) {
this.resetErrorMessage();
@@ -121,7 +170,7 @@ export class StartProcessInstanceComponent implements OnChanges {
this.cancel.emit();
}
hasStartForm() {
hasStartForm(): boolean {
return this.currentProcessDef && this.currentProcessDef.hasStartForm;
}
@@ -129,7 +178,7 @@ export class StartProcessInstanceComponent implements OnChanges {
return this.processDefinitions ? (this.processDefinitions.length > 0 || this.errorMessageId) : this.errorMessageId;
}
isStartFormMissingOrValid() {
isStartFormMissingOrValid(): boolean {
if (this.startForm) {
return this.startForm.form && this.startForm.form.isValid;
} else {
@@ -137,7 +186,7 @@ export class StartProcessInstanceComponent implements OnChanges {
}
}
validateForm() {
validateForm(): boolean {
return this.currentProcessDef.id && this.name && this.isStartFormMissingOrValid();
}
@@ -149,7 +198,7 @@ export class StartProcessInstanceComponent implements OnChanges {
this.errorMessageId = '';
}
hasErrorMessage() {
hasErrorMessage(): boolean {
return this.processDefinitions.length === 0 && !this.errorMessageId;
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AlfrescoApiService, FormValues } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { TaskDetailsModel } from '../../task-list';
@@ -98,7 +98,7 @@ export class ProcessService {
.catch(err => this.handleProcessError(err));
}
startProcess(processDefinitionId: string, name: string, outcome?: string, startFormValues?: any, variables?: ProcessInstanceVariable[]): Observable<ProcessInstance> {
startProcess(processDefinitionId: string, name: string, outcome?: string, startFormValues?: FormValues, variables?: ProcessInstanceVariable[]): Observable<ProcessInstance> {
let startRequest: any = {
name: name,
processDefinitionId: processDefinitionId