Fix start process form (#4847)

This commit is contained in:
Maurizio Vitale
2019-06-13 18:21:33 +01:00
committed by GitHub
parent c44c2eae77
commit 819ed9ae6a
7 changed files with 206 additions and 129 deletions

View File

@@ -27,7 +27,7 @@ import { ProcessServiceCloudTestingModule } from '../../testing/process-service-
import { FormCloudService } from '../services/form-cloud.service';
import { FormCloudComponent } from './form-cloud.component';
import { FormCloud } from '../models/form-cloud.model';
import { cloudFormMock } from '../mocks/cloud-form.mock';
import { cloudFormMock, fakeCloudForm } from '../mocks/cloud-form.mock';
import { FormCloudRepresentation } from '../models/form-cloud-representation.model';
describe('FormCloudComponent', () => {
@@ -422,15 +422,10 @@ describe('FormCloudComponent', () => {
});
it('should fetch and parse form definition by id', (done) => {
spyOn(formCloudService, 'getForm').and.callFake((currentAppName, currentFormId) => {
return new Observable((observer) => {
observer.next({ id: currentFormId });
observer.complete();
});
});
spyOn(formCloudService, 'getForm').and.returnValue(of(fakeCloudForm));
const appName = 'test-app';
const formId = '456';
const formId = 'form-de8895be-d0d7-4434-beef-559b15305d72';
formComponent.formLoaded.subscribe(() => {
expect(formComponent.form).toBeDefined();
expect(formComponent.form.id).toBe(formId);

View File

@@ -20,7 +20,7 @@ import {
Output, SimpleChanges, OnDestroy
} from '@angular/core';
import { Observable, of, forkJoin, Subject } from 'rxjs';
import { switchMap, takeUntil } from 'rxjs/operators';
import { switchMap, takeUntil, map } from 'rxjs/operators';
import { Subscription } from 'rxjs';
import {
FormBaseComponent,
@@ -206,7 +206,13 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
getFormById(appName: string, formId: string) {
this.formCloudService
.getForm(appName, formId)
.pipe(takeUntil(this.onDestroy$))
.pipe(
map((form: any) => {
const flattenForm = {...form.formRepresentation, ...form.formRepresentation.formDefinition};
delete flattenForm.formDefinition;
return flattenForm;
}),
takeUntil(this.onDestroy$))
.subscribe(
(form) => {
const parsedForm = this.parseForm(form);

View File

@@ -675,3 +675,67 @@ export const cloudFormMock = {
}
]
};
export let fakeCloudForm = {
'formRepresentation': {
'id': 'form-de8895be-d0d7-4434-beef-559b15305d72',
'name': 'StartEventForm',
'description': '',
'version': 0,
'formDefinition': {
'tabs': [],
'fields': [
{
'type': 'container',
'id': '5a6b24c1-db2b-45e9-9aff-142395433d23',
'name': 'Label',
'tab': null,
'fields': {
'1': [
{
'type': 'text',
'id': 'firstName',
'name': 'firstName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
],
'2': [
{
'type': 'text',
'id': 'lastName',
'name': 'lastName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
]
},
'numberOfColumns': 2
}
],
'outcomes': [],
'metadata': {},
'variables': []
}
}
};

View File

@@ -211,11 +211,11 @@ export class FormCloudService extends BaseCloudService {
/**
* Gets a form definition.
* @param appName Name of the app
* @param taskId ID of the target task
* @param formKey key of the target task
* @returns Form definition
*/
getForm(appName: string, taskId: string): Observable<any> {
const apiUrl = this.buildGetFormUrl(appName, taskId);
getForm(appName: string, formKey: string): Observable<any> {
const apiUrl = this.buildGetFormUrl(appName, formKey);
const bodyParam = {}, pathParams = {}, queryParams = {}, headerParams = {},
formParams = {};
@@ -282,8 +282,8 @@ export class FormCloudService extends BaseCloudService {
return `${this.getBasePath(appName)}/query/v1/tasks/${taskId}`;
}
private buildGetFormUrl(appName: string, formId: string): string {
return `${this.getBasePath(appName)}/form/v1/forms/${formId}`;
private buildGetFormUrl(appName: string, formKey: string): string {
return `${this.getBasePath(appName)}/form/v1/forms/${formKey}`;
}
private buildSaveFormUrl(appName: string, formId: string): string {

View File

@@ -91,6 +91,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
processPayloadCloud = new ProcessPayloadCloud();
filteredProcesses: ProcessDefinitionCloud[] = [];
isLoading = false;
isFormCloudLoaded = false;
formCloud: FormCloud;
protected onDestroy$ = new Subject<boolean>();
constructor(private startProcessCloudService: StartProcessCloudService,
@@ -128,6 +129,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
}
onFormLoaded(form: FormCloud) {
this.isFormCloudLoaded = true;
this.formCloud = form;
}
@@ -140,6 +142,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
this.filteredProcesses = this.getProcessDefinitionList(processDefinition);
const selectedProcess = this.getProcessIfExists(processDefinition);
this.processDefinitionCurrent = selectedProcess;
this.isFormCloudLoaded = false;
this.processPayloadCloud.processDefinitionKey = selectedProcess.key;
}
@@ -167,6 +170,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
const selectedProcess = this.getProcessDefinitionByName(this.processDefinitionName);
if (selectedProcess) {
this.processDefinitionCurrent = selectedProcess;
this.isFormCloudLoaded = false;
this.processDefinition.setValue(selectedProcess.name);
this.processPayloadCloud.processDefinitionKey = selectedProcess.key;
}
@@ -193,7 +197,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
}
isProcessFormValid(): boolean {
if (this.hasForm()) {
if (this.hasForm() && this.isFormCloudLoaded) {
return this.formCloud.isValid || this.isLoading;
} else {
return this.processForm.valid || this.isLoading;

View File

@@ -81,121 +81,129 @@ export let fakeProcessPayload = new ProcessPayloadCloud({
});
export let fakeStartForm = {
'id': 'form-a5d50817-5183-4850-802d-17af54b2632f',
'name': 'simpleform',
'description': '',
'version': 0,
'tabs': [],
'fields': [
{
'type': 'container',
'id': '5a6b24c1-db2b-45e9-9aff-142395433d23',
'name': 'Label',
'tab': null,
'fields': {
'1': [
{
'type': 'text',
'id': 'firstName',
'name': 'firstName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
],
'2': [
{
'type': 'text',
'id': 'lastName',
'name': 'lastName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
]
},
'numberOfColumns': 2
'formRepresentation': {
'id': 'form-de8895be-d0d7-4434-beef-559b15305d72',
'name': 'StartEventForm',
'description': '',
'version': 0,
'formDefinition': {
'tabs': [],
'fields': [
{
'type': 'container',
'id': '5a6b24c1-db2b-45e9-9aff-142395433d23',
'name': 'Label',
'tab': null,
'fields': {
'1': [
{
'type': 'text',
'id': 'firstName',
'name': 'firstName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
],
'2': [
{
'type': 'text',
'id': 'lastName',
'name': 'lastName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
]
},
'numberOfColumns': 2
}
],
'outcomes': [],
'metadata': {},
'variables': []
}
],
'outcomes': [],
'metadata': {},
'variables': []
}
};
export let fakeStartFormNotValid = {
'id': 'form-a5d50817-5183-4850-802d-17af54b2632f',
'name': 'simpleform',
'description': '',
'version': 0,
'tabs': [],
'fields': [
{
'type': 'container',
'id': '5a6b24c1-db2b-45e9-9aff-142395433d23',
'name': 'Label',
'tab': null,
'fields': {
'1': [
{
'type': 'text',
'id': 'firstName',
'name': 'firstName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': true,
'minLength': 15,
'maxLength': 0,
'regexPattern': null
}
],
'2': [
{
'type': 'text',
'id': 'lastName',
'name': 'lastName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
]
},
'numberOfColumns': 2
'formRepresentation': {
'id': 'form-a5d50817-5183-4850-802d-17af54b2632f',
'name': 'simpleform',
'description': '',
'version': 0,
'formDefinition': {
'tabs': [],
'fields': [
{
'type': 'container',
'id': '5a6b24c1-db2b-45e9-9aff-142395433d23',
'name': 'Label',
'tab': null,
'fields': {
'1': [
{
'type': 'text',
'id': 'firstName',
'name': 'firstName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': true,
'minLength': 15,
'maxLength': 0,
'regexPattern': null
}
],
'2': [
{
'type': 'text',
'id': 'lastName',
'name': 'lastName',
'colspan': 1,
'params': {
'existingColspan': 1,
'maxColspan': 2
},
'visibilityCondition': null,
'placeholder': null,
'value': null,
'required': false,
'minLength': 0,
'maxLength': 0,
'regexPattern': null
}
]
},
'numberOfColumns': 2
}
],
'outcomes': [],
'metadata': {},
'variables': []
}
],
'outcomes': [],
'metadata': {},
'variables': []
}
};

View File

@@ -26,6 +26,6 @@ export class ProcessPayloadCloud {
this.processDefinitionKey = obj && obj.processDefinitionKey ? obj.processDefinitionKey : null;
this.name = obj && obj.name ? obj.name : null;
this.businessKey = obj && obj.businessKey ? obj.businessKey : null;
this.variables = obj && obj.variables ? obj.variables : null;
this.variables = obj && obj.variables ? obj.variables : {};
}
}