Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACA-3881] Able to start form with preselected ACS nodes #6700

Merged
merged 5 commits into from Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
214 changes: 214 additions & 0 deletions lib/process-services/src/lib/form/start-form.component.mock.ts
Expand Up @@ -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'
}
]
};
23 changes: 22 additions & 1 deletion lib/process-services/src/lib/form/start-form.component.spec.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 16 additions & 10 deletions lib/process-services/src/lib/form/start-form.component.ts
Expand Up @@ -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();
Expand All @@ -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)
);
Expand All @@ -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 ||
Expand Down
Expand Up @@ -81,7 +81,7 @@
<ng-container *ngIf="hasStartForm(); else noStartFormTemplate">
<adf-start-form
#startForm
[data]="values"
[data]="movedNodeToPS"
[disableStartProcessButton]="processNameInput.invalid"
[processDefinitionId]="selectedProcessDef.id"
(outcomeClick)="onOutcomeClick($event)"
Expand Down
Expand Up @@ -241,7 +241,7 @@ describe('StartFormComponent', () => {
component.moveNodeFromCStoPS();

fixture.whenStable().then(() => {
expect(component.values.file[0].id).toBe(1234);
expect(component.movedNodeToPS.file[0].id).toBe(1234);
expect(applyAlfrescoNodeSpy).toHaveBeenCalled();
});
}));
Expand All @@ -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);
});
}));
Expand Down
Expand Up @@ -127,6 +127,7 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr

isProcessDefinitionsLoading = true;
isAppsLoading = true;
movedNodeToPS;
eromano marked this conversation as resolved.
Show resolved Hide resolved

private onDestroy$ = new Subject<boolean>();
constructor(private activitiProcess: ProcessService,
Expand Down Expand Up @@ -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]};
});
}
}
}
Expand Down