diff --git a/docs/process-services-cloud/components/form-cloud.component.md b/docs/process-services-cloud/components/form-cloud.component.md index 4167d2b05f..baa50c30f0 100644 --- a/docs/process-services-cloud/components/form-cloud.component.md +++ b/docs/process-services-cloud/components/form-cloud.component.md @@ -29,7 +29,8 @@ Shows a [`form`](../../../lib/process-services-cloud/src/lib/form/models/form-cl ```html + [taskId]="taskId" + [processInstanceId]="processInstanceId"> ``` @@ -92,6 +93,7 @@ The template defined inside `empty-form` will be shown when no form definition i | showTitle | `boolean` | true | Toggle rendering of the form title. | | showValidationIcon | `boolean` | true | Toggle rendering of the validation icon next to the form title. | | taskId | `string` | | Task id to fetch corresponding form and values. | +| processInstanceId | `string `| | Process instance id to fetch corresponding form and values.| ### Events @@ -116,6 +118,7 @@ All `formXXX` events receive a [`FormCloudModel`](../../../lib/process-services- ``` @@ -132,12 +135,13 @@ onFormSaved(form: FormCloudModel) { There are various ways to display a form. The common scenarios are detailed below. -#### Displaying a form instance by task id +#### Displaying a form instance by task id and processInstanceId ```html + [taskId]="selectedTask?.id" + [processInstanceId]="selectedTask?.processInstanceId"> ``` @@ -172,6 +176,7 @@ of the form validation before it is submitted. ``` 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 cf4b36a26b..34b7437c27 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 @@ -466,6 +466,7 @@ describe('FormCloudComponent', () => { const taskId = '123-223'; const appName = 'test-app'; + const processInstanceId = '333-444'; const formModel = new FormCloud({ formRepresentation: { @@ -482,10 +483,11 @@ describe('FormCloudComponent', () => { formComponent.form = formModel; formComponent.taskId = taskId; formComponent.appName = appName; + formComponent.processInstanceId = processInstanceId; formComponent.saveTaskForm(); - expect(formCloudService.saveTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, formModel.id, formModel.values); + expect(formCloudService.saveTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values); expect(saved).toBeTruthy(); expect(savedForm).toEqual(formModel); }); @@ -567,6 +569,8 @@ describe('FormCloudComponent', () => { const taskId = '123-223'; const appName = 'test-app'; + const processInstanceId = '333-444'; + const formModel = new FormCloud({ formRepresentation: { id: '23', @@ -583,9 +587,10 @@ describe('FormCloudComponent', () => { formComponent.form = formModel; formComponent.taskId = taskId; formComponent.appName = appName; + formComponent.processInstanceId = processInstanceId; formComponent.completeTaskForm(outcome); - expect(formCloudService.completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, formModel.id, formModel.values, outcome); + expect(formCloudService.completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values, outcome); expect(completed).toBeTruthy(); }); 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 7ff00949e9..4a164cddeb 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 @@ -52,6 +52,10 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, @Input() formId: string; + /** ProcessInstanceId id to fetch corresponding form and values. */ + @Input() + processInstanceId: string; + /** Underlying form model instance. */ @Input() form: FormCloud; @@ -110,8 +114,8 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, ngOnChanges(changes: SimpleChanges) { const appName = changes['appName']; if (appName && appName.currentValue) { - if (this.taskId) { - this.getFormDefinitionWithFolderTask(this.appName, this.taskId); + if (this.taskId && this.processInstanceId) { + this.getFormDefinitionWithFolderTask(this.appName, this.taskId, this.processInstanceId); } else if (this.formId) { this.getFormById(appName.currentValue, this.formId); } @@ -211,22 +215,22 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, ); } - getFormDefinitionWithFolderTask(appName: string, taskId: string) { - this.getFormDefinitionWithFolderByTaskId(appName, taskId); + getFormDefinitionWithFolderTask(appName: string, taskId: string, processInstanceId: string) { + this.getFormDefinitionWithFolder(appName, taskId, processInstanceId); } - async getFormDefinitionWithFolderByTaskId(appName: string, taskId: string) { + async getFormDefinitionWithFolder(appName: string, taskId: string, processInstanceId: string) { try { await this.getFormByTaskId(appName, taskId); const hasUploadWidget = ( this.form).hasUpload; if (hasUploadWidget) { try { - const processStorageCloudModel = await this.formCloudService.getProcessStorageFolderTask(appName, taskId).toPromise(); + const processStorageCloudModel = await this.formCloudService.getProcessStorageFolderTask(appName, taskId, processInstanceId).toPromise(); this.form.nodeId = processStorageCloudModel.nodeId; this.form.contentHost = processStorageCloudModel.path; } catch (error) { - this.notificationService.openSnackMessage('The content repo is not configured'); + this.notificationService.openSnackMessage('The content repo is not configured'); } } @@ -239,7 +243,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, saveTaskForm() { if (this.form && this.appName && this.taskId) { this.formCloudService - .saveTaskForm(this.appName, this.taskId, this.form.id, this.form.values) + .saveTaskForm(this.appName, this.taskId, this.processInstanceId, this.form.id, this.form.values) .pipe(takeUntil(this.onDestroy$)) .subscribe( () => { @@ -253,7 +257,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges, completeTaskForm(outcome?: string) { if (this.form && this.appName && this.taskId) { this.formCloudService - .completeTaskForm(this.appName, this.taskId, this.form.id, this.form.values, outcome) + .completeTaskForm(this.appName, this.taskId, this.processInstanceId, this.form.id, this.form.values, outcome) .pipe(takeUntil(this.onDestroy$)) .subscribe( () => { diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts index 6cc3123c18..494d7375a8 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts @@ -41,6 +41,7 @@ describe('Form Cloud service', () => { let apiService: AlfrescoApiService; const appName = 'app-name'; const taskId = 'task-id'; + const processInstanceId = 'process-instance-id'; setupTestBed({ imports: [ @@ -167,7 +168,7 @@ describe('Form Cloud service', () => { oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody)); const formId = 'form-id'; - service.saveTaskForm(appName, taskId, formId, {}).subscribe((result: any) => { + service.saveTaskForm(appName, taskId, processInstanceId, formId, {}).subscribe((result: any) => { expect(result).toBeDefined(); expect(result.id).toBe('id'); expect(result.name).toBe('name'); @@ -182,7 +183,7 @@ describe('Form Cloud service', () => { oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody)); const formId = 'form-id'; - service.completeTaskForm(appName, taskId, formId, {}, '').subscribe((result: any) => { + service.completeTaskForm(appName, taskId, processInstanceId, formId, {}, '').subscribe((result: any) => { expect(result).toBeDefined(); expect(result.id).toBe('id'); expect(result.name).toBe('name'); 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 8c73f0dd0e..6150a114a3 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 @@ -30,7 +30,10 @@ import { BaseCloudService } from '../../services/base-cloud.service'; }) export class FormCloudService extends BaseCloudService { - contentTypes = ['application/json']; accepts = ['application/json']; returnType = Object; + contentTypes = ['application/json']; + accepts = ['application/json']; + returnType = Object; + constructor( private apiService: AlfrescoApiService, private appConfigService: AppConfigService, @@ -71,9 +74,9 @@ export class FormCloudService extends BaseCloudService { * @param formValues Form values object * @returns Updated task details */ - saveTaskForm(appName: string, taskId: string, formId: string, formValues: FormValues): Observable { + saveTaskForm(appName: string, taskId: string, processInstanceId: string, formId: string, formValues: FormValues): Observable { const apiUrl = this.buildSaveFormUrl(appName, formId); - const saveFormRepresentation = { values: formValues, taskId: taskId }; + const saveFormRepresentation = {values: formValues, taskId: taskId, processInstanceId: processInstanceId}; return from(this.apiService .getInstance() .oauth2Auth.callCustomApi(apiUrl, 'POST', @@ -100,7 +103,7 @@ export class FormCloudService extends BaseCloudService { '', nodeId, '', - { overwrite: true } + {overwrite: true} )).pipe( map((res: any) => { return (res.entry); @@ -118,9 +121,9 @@ export class FormCloudService extends BaseCloudService { * @param outcome (Optional) Form outcome * @returns Updated task details */ - completeTaskForm(appName: string, taskId: string, formId: string, formValues: FormValues, outcome: string): Observable { + completeTaskForm(appName: string, taskId: string, processInstanceId: string, formId: string, formValues: FormValues, outcome: string): Observable { const apiUrl = this.buildSubmitFormUrl(appName, formId); - const completeFormRepresentation: any = { values: formValues, taskId: taskId }; + const completeFormRepresentation: any = {values: formValues, taskId: taskId, processInstanceId: processInstanceId}; if (outcome) { completeFormRepresentation.outcome = outcome; } @@ -163,8 +166,8 @@ export class FormCloudService extends BaseCloudService { ); } - getProcessStorageFolderTask(appName: string, taskId: string): Observable { - const apiUrl = this.buildFolderTask(appName, taskId); + getProcessStorageFolderTask(appName: string, taskId: string, processInstanceId: string): Observable { + const apiUrl = this.buildFolderTask(appName, taskId, processInstanceId); return from(this.apiService .getInstance() .oauth2Auth.callCustomApi(apiUrl, 'GET', @@ -218,9 +221,9 @@ export class FormCloudService extends BaseCloudService { this.apiService .getInstance() .oauth2Auth.callCustomApi( - apiUrl, 'GET', pathParams, queryParams, - headerParams, formParams, bodyParam, - this.contentTypes, this.accepts, this.returnType, null, null) + apiUrl, 'GET', pathParams, queryParams, + headerParams, formParams, bodyParam, + this.contentTypes, this.accepts, this.returnType, null, null) ).pipe( catchError((err) => this.handleError(err)) ); @@ -290,8 +293,8 @@ export class FormCloudService extends BaseCloudService { return `${this.getBasePath(appName)}/query/v1/tasks/${taskId}/variables`; } - private buildFolderTask(appName: string, taskId: string): string { - return `${this.getBasePath(appName)}/process-storage/v1/folders/tasks/${taskId}`; + private buildFolderTask(appName: string, taskId: string, processInstanceId: string): string { + return `${this.getBasePath(appName)}/process-storage/v1/folders/${processInstanceId}/${taskId}`; } private handleError(error: any) { diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html index 9a1085fe28..86908275bd 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html @@ -1,15 +1,16 @@
+ [appName]="appName" + [taskId]="taskId" + [processInstanceId]="taskDetails.processInstanceId" + [readOnly]="isReadOnly()" + [showRefreshButton]="showRefreshButton" + [showValidationIcon]="showValidationIcon" + [showCompleteButton]="canCompleteTask()" + [showSaveButton]="canCompleteTask()" + (formSaved)="onFormSaved($event)" + (formCompleted)="onFormCompleted($event)" + (formError)="onError($event)"> @@ -40,7 +41,8 @@ - @@ -50,10 +52,12 @@ - - diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts index 405c7f98ec..f9ad3a8914 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts @@ -96,13 +96,13 @@ export class TaskFormCloudComponent implements OnChanges { constructor( private taskCloudService: TaskCloudService, private formRenderingService: FormRenderingService) { - this.formRenderingService.setComponentTypeResolver('upload', () => UploadCloudWidgetComponent, true); - this.formRenderingService.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true); + this.formRenderingService.setComponentTypeResolver('upload', () => UploadCloudWidgetComponent, true); + this.formRenderingService.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true); } ngOnChanges(changes: SimpleChanges) { const appName = changes['appName']; - if (appName && (appName.currentValue || appName.currentValue === '' ) && this.taskId) { + if (appName && (appName.currentValue || appName.currentValue === '') && this.taskId) { this.loadTask(); return; }