diff --git a/lib/process-services/src/lib/form/start-form.component.mock.ts b/lib/process-services/src/lib/form/start-form.component.mock.ts index d8ae040059..19c49dc645 100644 --- a/lib/process-services/src/lib/form/start-form.component.mock.ts +++ b/lib/process-services/src/lib/form/start-form.component.mock.ts @@ -1011,3 +1011,217 @@ export let startMockFormWithTab = { gridsterForm: false, globalDateFormat: 'D - M - YYYY' }; + +export const taskFormSingleUploadMock = { + id: 4, + name: 'Translation request', + processDefinitionId: 'TranslationProcess:2:8', + processDefinitionName: 'Translation Process', + processDefinitionKey: 'TranslationProcess', + taskId: '91', + taskDefinitionKey: 'sid-DDECD9E4-0299-433F-9193-C3D905C3EEBE', + tabs: [], + fields: [ + { + fieldType: 'ContainerRepresentation', + id: '1582747052793', + name: 'Label', + type: 'container', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + minValue: null, + maxValue: null, + regexPattern: null, + optionType: null, + hasEmptyValue: null, + options: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + tab: null, + className: null, + dateDisplayFormat: null, + layout: null, + sizeX: 2, + sizeY: 1, + row: -1, + col: -1, + visibilityCondition: null, + numberOfColumns: 2, + fields: { + '1': [ + { + fieldType: 'AttachFileFieldRepresentation', + id: 'fake-single-upload', + name: 'Attach file - single type', + type: 'upload', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + params: { + existingColspan: 1, + maxColspan: 2, + fileSource: { + serviceId: 'all-file-sources', + name: 'All file sources' + }, + link: true + }, + visibilityCondition: null + } + ] + } + } + ], + outcomes: [], + javascriptEvents: [], + className: '', + style: '', + customFieldTemplates: {}, + metadata: {}, + variables: [], + customFieldsValueInfo: {}, + gridsterForm: false, + globalDateFormat: 'D-M-YYYY' +}; + +export const taskFormMultipleUploadMock = { + id: 4, + name: 'Translation request', + processDefinitionId: 'TranslationProcess:2:8', + processDefinitionName: 'Translation Process', + processDefinitionKey: 'TranslationProcess', + taskId: '91', + taskDefinitionKey: 'sid-DDECD9E4-0299-433F-9193-C3D905C3EEBE', + tabs: [], + fields: [ + { + fieldType: 'ContainerRepresentation', + id: '1582747052793', + name: 'Label', + type: 'container', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + minValue: null, + maxValue: null, + regexPattern: null, + optionType: null, + hasEmptyValue: null, + options: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + tab: null, + className: null, + dateDisplayFormat: null, + layout: null, + sizeX: 2, + sizeY: 1, + row: -1, + col: -1, + visibilityCondition: null, + numberOfColumns: 2, + fields: { + '1': [ + { + fieldType: 'AttachFileFieldRepresentation', + id: 'fake-multiple-upload', + name: 'Attach file - multiple type', + type: 'upload', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + params: { + existingColspan: 1, + maxColspan: 2, + fileSource: { + serviceId: 'all-file-sources', + name: 'All file sources' + }, + link: true, + multiple: true + }, + visibilityCondition: null + } + ] + } + } + ], + outcomes: [], + javascriptEvents: [], + className: '', + style: '', + customFieldTemplates: {}, + metadata: {}, + variables: [], + customFieldsValueInfo: {}, + gridsterForm: false, + globalDateFormat: 'D-M-YYYY' +}; + +export const preselectedSingleNode = { + 'fake-single-upload': [ + { + id: 1027, + name: 'fake-file.docx', + relatedContent: false, + contentAvailable: true, + link: true, + source: 'alfresco-1-adw-contentAlfresco', + sourceId: '4a440e8f-7fe5-4d83-a042-a19ee10125fb;2.0@', + mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + simpleType: 'word', + previewStatus: 'queued', + thumbnailStatus: 'queued' + } + ] +}; + +export const preselectedMultipleeNode = { + 'fake-multiple-upload': [ + { + id: 1027, + name: 'fake-file.docx', + relatedContent: false, + contentAvailable: true, + link: true, + source: 'alfresco-1-adw-contentAlfresco', + sourceId: '4a440e8f-7fe5-4d83-a042-a19ee10125fb;2.0@', + mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + simpleType: 'word', + previewStatus: 'queued', + thumbnailStatus: 'queued' + }, + { + id: 1028, + name: 'fake-file2.docx', + relatedContent: false, + contentAvailable: true, + link: true, + source: 'alfresco-1-adw-contentAlfresco', + sourceId: '4a440e8f-7fe5-4d83-a042-a19ee10125fb;2.0@', + mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + simpleType: 'word', + previewStatus: 'queued', + thumbnailStatus: 'queued' + } + ] +}; diff --git a/lib/process-services/src/lib/form/start-form.component.spec.ts b/lib/process-services/src/lib/form/start-form.component.spec.ts index 9b0f0edfab..6dc19f69f1 100644 --- a/lib/process-services/src/lib/form/start-form.component.spec.ts +++ b/lib/process-services/src/lib/form/start-form.component.spec.ts @@ -21,7 +21,8 @@ import { of, throwError } from 'rxjs'; import { startFormDateWidgetMock, startFormDropdownDefinitionMock, startFormTextDefinitionMock, startMockForm, startMockFormWithTab, - startFormAmountWidgetMock, startFormNumberWidgetMock, startFormRadioButtonWidgetMock + startFormAmountWidgetMock, startFormNumberWidgetMock, startFormRadioButtonWidgetMock, + taskFormSingleUploadMock, taskFormMultipleUploadMock, preselectedSingleNode, preselectedMultipleeNode } from './start-form.component.mock'; import { StartFormComponent } from './start-form.component'; import { FormService, WidgetVisibilityService, setupTestBed, FormModel, FormOutcomeModel } from '@alfresco/adf-core'; @@ -93,6 +94,26 @@ describe('StartFormComponent', () => { expect(formService.getStartFormDefinition).not.toHaveBeenCalled(); }); + it('should be able to inject sigle file as value into the form with an upload single widget', () => { + getStartFormSpy.and.returnValue(of(taskFormSingleUploadMock)); + component.data = preselectedSingleNode; + component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId1, true) }); + + expect(component.form.getFieldById('fake-single-upload').value).toBeDefined(); + expect(component.form.getFieldById('fake-single-upload').value.length).toBe(1); + expect(component.form.getFieldById('fake-single-upload').value).toBe(preselectedSingleNode['fake-single-upload']); + }); + + it('should be able to inject multiple files as value into the form with an upload multiple widget', () => { + getStartFormSpy.and.returnValue(of(taskFormMultipleUploadMock)); + component.data = preselectedMultipleeNode; + component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId1, true) }); + + expect(component.form.getFieldById('fake-multiple-upload').value).toBeDefined(); + expect(component.form.getFieldById('fake-multiple-upload').value.length).toBe(2); + expect(component.form.getFieldById('fake-multiple-upload').value).toBe(preselectedMultipleeNode['fake-multiple-upload']); + }); + it('should consume errors encountered when loading start form', () => { getStartFormSpy.and.returnValue(throwError({})); component.processDefinitionId = exampleId1; diff --git a/lib/process-services/src/lib/form/start-form.component.ts b/lib/process-services/src/lib/form/start-form.component.ts index d6be1ffa39..bbc29b256c 100644 --- a/lib/process-services/src/lib/form/start-form.component.ts +++ b/lib/process-services/src/lib/form/start-form.component.ts @@ -84,6 +84,12 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn return; } + const data = changes['data']; + if (data && data.currentValue) { + this.parseRefreshVisibilityValidateForm(this.form.json); + return; + } + const processId = changes['processId']; if (processId && processId.currentValue) { this.visibilityService.cleanProcessVariable(); @@ -103,11 +109,7 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn if (instance.variables) { form.processVariables = instance.variables; } - this.form = this.parseForm(form); - this.visibilityService.refreshVisibility(this.form); - this.form.validateForm(); - this.form.readOnly = this.readOnlyForm; - this.onFormLoaded(this.form); + this.parseRefreshVisibilityValidateForm(form); }, (error) => this.handleError(error) ); @@ -120,16 +122,20 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn .subscribe( (form) => { this.formName = form.processDefinitionName; - this.form = this.parseForm(form); - this.visibilityService.refreshVisibility(this.form); - this.form.validateForm(); - this.form.readOnly = this.readOnlyForm; - this.onFormLoaded(this.form); + this.parseRefreshVisibilityValidateForm(form); }, (error) => this.handleError(error) ); } + parseRefreshVisibilityValidateForm(form) { + this.form = this.parseForm(form); + this.visibilityService.refreshVisibility(this.form); + this.form.validateForm(); + this.form.readOnly = this.readOnlyForm; + this.onFormLoaded(this.form); + } + /** @override */ isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean { if (outcome && outcome.isSystem && (outcome.name === FormOutcomeModel.SAVE_ACTION || diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.html b/lib/process-services/src/lib/process-list/components/start-process.component.html index f63fb4f9f8..97a8ebbb03 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.html +++ b/lib/process-services/src/lib/process-list/components/start-process.component.html @@ -81,7 +81,7 @@ { component.moveNodeFromCStoPS(); fixture.whenStable().then(() => { - expect(component.values.file[0].id).toBe(1234); + expect(component.movedNodeToPS.file[0].id).toBe(1234); expect(applyAlfrescoNodeSpy).toHaveBeenCalled(); }); })); @@ -266,9 +266,9 @@ describe('StartFormComponent', () => { component.moveNodeFromCStoPS(); fixture.whenStable().then(() => { - expect(component.values.file.length).toBe(3); - expect(component.values.file[0].id).toBe(1234); - expect(component.values.file[1].id).toBe(1234); + expect(component.movedNodeToPS.file.length).toBe(3); + expect(component.movedNodeToPS.file[0].id).toBe(1234); + expect(component.movedNodeToPS.file[1].id).toBe(1234); expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(3); }); })); diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.ts b/lib/process-services/src/lib/process-list/components/start-process.component.ts index 98ab4429b9..f9e77f8d88 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.ts +++ b/lib/process-services/src/lib/process-list/components/start-process.component.ts @@ -127,6 +127,7 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr isProcessDefinitionsLoading = true; isAppsLoading = true; + movedNodeToPS: FormValues; private onDestroy$ = new Subject(); constructor(private activitiProcess: ProcessService, @@ -364,7 +365,9 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr const currentValue = Array.isArray(this.values[key]) ? this.values[key] : [this.values[key]]; const contents = currentValue.filter((value: any) => value && value.isFile) .map((content: MinimalNode) => this.activitiContentService.applyAlfrescoNode(content, null, accountIdentifier)); - forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => this.values[key] = [...res] ); + forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => { + this.movedNodeToPS = { [key]: [...res]}; + }); } } }