[ADF-1640] Start form - Get the variables from the process instance API (#2425)

* Get the variables from the process instance API
/api/enterprise/process-instances/XXX
instead of
/api/enterprise/process-instances/382/variables
because the latest api returns 404 if the process is completed

* Fix unit test

* Add field id
This commit is contained in:
Maurizio Vitale 2017-10-05 12:29:09 +01:00 committed by Vito
parent c9c22bc7c1
commit 3f1383e412
4 changed files with 14 additions and 6 deletions

View File

@ -102,14 +102,16 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
} }
loadStartForm(processId: string) { loadStartForm(processId: string) {
this.formService.getProcessVarablesById(processId) this.formService.getProcessIntance(processId)
.subscribe((processVariables: any) => { .subscribe((intance: any) => {
this.formService this.formService
.getStartFormInstance(processId) .getStartFormInstance(processId)
.subscribe( .subscribe(
form => { form => {
this.formName = form.name; this.formName = form.name;
form.processVariables = processVariables; if (intance.variables) {
form.processVariables = intance.variables;
}
this.form = this.parseForm(form); this.form = this.parseForm(form);
this.form.readOnly = this.readOnlyForm; this.form.readOnly = this.readOnlyForm;
this.onFormLoaded(this.form); this.onFormLoaded(this.form);

View File

@ -205,7 +205,7 @@ export class FormFieldModel extends FormWidgetModel {
private getProcessVariableValue(field: any, form: FormModel) { private getProcessVariableValue(field: any, form: FormModel) {
let fieldName = field.name; let fieldName = field.name;
if (this.isTypeaHeadFieldType(field.type)) { if (this.isTypeaHeadFieldType(field.type)) {
fieldName = this.getFieldNameWithLabel(field.name); fieldName = this.getFieldNameWithLabel(field.id);
} }
return this.findProcessVariableValue(fieldName, form); return this.findProcessVariableValue(fieldName, form);
} }

View File

@ -365,12 +365,12 @@ describe('TypeaheadWidgetComponent', () => {
it('should show typeahead value when the type is readonly', async(() => { it('should show typeahead value when the type is readonly', async(() => {
typeaheadWidgetComponent.field = new FormFieldModel( typeaheadWidgetComponent.field = new FormFieldModel(
new FormModel({ taskId: 'fake-task-id', processVariables: [{ name: 'typeahead-name_LABEL', value: 'FakeProcessValue' }] }), { new FormModel({ taskId: 'fake-task-id', processVariables: [{ name: 'typeahead-id_LABEL', value: 'FakeProcessValue' }] }), {
id: 'typeahead-id', id: 'typeahead-id',
name: 'typeahead-name', name: 'typeahead-name',
type: 'readonly', type: 'readonly',
value: '9', value: '9',
params: { field: { name: 'typeahead-name', type: 'typeahead' } } params: { field: { id: 'typeahead-id', name: 'typeahead-name', type: 'typeahead' } }
}); });
fixture.detectChanges(); fixture.detectChanges();
const trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement; const trigger = fixture.debugElement.query(By.css('.mat-select-trigger')).nativeElement;

View File

@ -313,6 +313,12 @@ export class FormService {
.catch(err => this.handleError(err)); .catch(err => this.handleError(err));
} }
getProcessIntance(processId: string): Observable<any> {
return Observable.fromPromise(this.processApi.getProcessInstance(processId))
.map(this.toJson)
.catch(err => this.handleError(err));
}
/** /**
* Get start form definition for a given process * Get start form definition for a given process
* @param processId Process definition ID * @param processId Process definition ID