diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts index 7143d41a35..c455cdcfd6 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts @@ -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); diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts index c6c0c73bc3..8f137341a7 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.ts @@ -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); diff --git a/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts b/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts index ca50cf819b..4de430f69b 100644 --- a/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts +++ b/lib/process-services-cloud/src/lib/form/mocks/cloud-form.mock.ts @@ -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': [] + } + } +}; diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts index 5f8d457800..db153cc893 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts @@ -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 { - const apiUrl = this.buildGetFormUrl(appName, taskId); + getForm(appName: string, formKey: string): Observable { + 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 { diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts index 618c729387..b2f687c9cb 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts @@ -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(); 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; diff --git a/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts b/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts index 5783ccc910..97cd674705 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts @@ -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': [] + } }; diff --git a/lib/process-services-cloud/src/lib/process/start-process/models/process-payload-cloud.model.ts b/lib/process-services-cloud/src/lib/process/start-process/models/process-payload-cloud.model.ts index 44f481f1b5..828c696b6a 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/models/process-payload-cloud.model.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/models/process-payload-cloud.model.ts @@ -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 : {}; } }