mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Fix start process form (#4847)
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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': []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
@@ -81,10 +81,12 @@ export let fakeProcessPayload = new ProcessPayloadCloud({
|
||||
});
|
||||
|
||||
export let fakeStartForm = {
|
||||
'id': 'form-a5d50817-5183-4850-802d-17af54b2632f',
|
||||
'name': 'simpleform',
|
||||
'formRepresentation': {
|
||||
'id': 'form-de8895be-d0d7-4434-beef-559b15305d72',
|
||||
'name': 'StartEventForm',
|
||||
'description': '',
|
||||
'version': 0,
|
||||
'formDefinition': {
|
||||
'tabs': [],
|
||||
'fields': [
|
||||
{
|
||||
@@ -138,13 +140,17 @@ export let fakeStartForm = {
|
||||
'outcomes': [],
|
||||
'metadata': {},
|
||||
'variables': []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export let fakeStartFormNotValid = {
|
||||
'formRepresentation': {
|
||||
'id': 'form-a5d50817-5183-4850-802d-17af54b2632f',
|
||||
'name': 'simpleform',
|
||||
'description': '',
|
||||
'version': 0,
|
||||
'formDefinition': {
|
||||
'tabs': [],
|
||||
'fields': [
|
||||
{
|
||||
@@ -198,4 +204,6 @@ export let fakeStartFormNotValid = {
|
||||
'outcomes': [],
|
||||
'metadata': {},
|
||||
'variables': []
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -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 : {};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user