mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-10896] - Fix attach file widget destinationFolderPath is broken … (#7888)
* [AAE-10896] - Fix attach file widget destinationFolderPath is broken when using string variables * Fix unit tests * Add unit test * Fix linting problems
This commit is contained in:
@@ -201,25 +201,7 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
|
|
||||||
if (FormFieldTypes.isReadOnlyType(this.type)) {
|
if (FormFieldTypes.isReadOnlyType(this.type)) {
|
||||||
if (this.params && this.params.field) {
|
if (this.params && this.params.field) {
|
||||||
let valueFound = false;
|
this.setValueForReadonlyType(form);
|
||||||
|
|
||||||
if (form.processVariables) {
|
|
||||||
const processVariable = this.getProcessVariableValue(this.params.field, form);
|
|
||||||
|
|
||||||
if (processVariable) {
|
|
||||||
valueFound = true;
|
|
||||||
this.value = processVariable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!valueFound && this.params.responseVariable) {
|
|
||||||
const defaultValue = form.getFormVariableValue(this.params.field.name);
|
|
||||||
|
|
||||||
if (defaultValue) {
|
|
||||||
valueFound = true;
|
|
||||||
this.value = defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +226,13 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
this.updateForm();
|
this.updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setValueForReadonlyType(form: any) {
|
||||||
|
const value = this.getProcessVariableValue(this.params.field, form);
|
||||||
|
if (value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private getDefaultDateFormat(jsonField: any): string {
|
private getDefaultDateFormat(jsonField: any): string {
|
||||||
let originalType = jsonField.type;
|
let originalType = jsonField.type;
|
||||||
if (FormFieldTypes.isReadOnlyType(jsonField.type) &&
|
if (FormFieldTypes.isReadOnlyType(jsonField.type) &&
|
||||||
|
@@ -540,25 +540,25 @@ describe('FormModel', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should find a form variable value', () => {
|
it('should find a form variable value', () => {
|
||||||
const result1 = form.getFormVariableValue('name1');
|
const result1 = form.getDefaultFormVariableValue('name1');
|
||||||
const result2 = form.getFormVariableValue('bfca9766-7bc1-45cc-8ecf-cdad551e36e2');
|
const result2 = form.getDefaultFormVariableValue('bfca9766-7bc1-45cc-8ecf-cdad551e36e2');
|
||||||
|
|
||||||
expect(result1).toEqual(result2);
|
expect(result1).toEqual(result2);
|
||||||
expect(result1).toEqual('hello');
|
expect(result1).toEqual('hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert the date variable value', () => {
|
it('should convert the date variable value', () => {
|
||||||
const value = form.getFormVariableValue('name2');
|
const value = form.getDefaultFormVariableValue('name2');
|
||||||
expect(value).toBe('29.09.2019T00:00:00.000Z');
|
expect(value).toBe('29.09.2019T00:00:00.000Z');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert the boolean variable value', () => {
|
it('should convert the boolean variable value', () => {
|
||||||
const value = form.getFormVariableValue('bool');
|
const value = form.getDefaultFormVariableValue('bool');
|
||||||
expect(value).toEqual(true);
|
expect(value).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not find variable value', () => {
|
it('should not find variable value', () => {
|
||||||
const value = form.getFormVariableValue('missing');
|
const value = form.getDefaultFormVariableValue('missing');
|
||||||
expect(value).toBeUndefined();
|
expect(value).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -264,7 +264,7 @@ export class FormModel implements ProcessFormModel {
|
|||||||
*
|
*
|
||||||
* @param identifier The `name` or `id` value
|
* @param identifier The `name` or `id` value
|
||||||
*/
|
*/
|
||||||
getFormVariableValue(identifier: string): any {
|
getDefaultFormVariableValue(identifier: string): any {
|
||||||
const variable = this.getFormVariable(identifier);
|
const variable = this.getFormVariable(identifier);
|
||||||
|
|
||||||
if (variable && variable.hasOwnProperty('value')) {
|
if (variable && variable.hasOwnProperty('value')) {
|
||||||
@@ -276,23 +276,30 @@ export class FormModel implements ProcessFormModel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a process variable value.
|
* Returns a process variable value.
|
||||||
|
* When mapping a process variable with a form variable the mapping
|
||||||
|
* is already resolved by the rest API with the name of variables.formVariableName
|
||||||
*
|
*
|
||||||
* @param name Variable name
|
* @param name Variable name
|
||||||
*/
|
*/
|
||||||
getProcessVariableValue(name: string): any {
|
getProcessVariableValue(name: string): any {
|
||||||
if (this.processVariables) {
|
let value;
|
||||||
|
if (this.processVariables?.length) {
|
||||||
const names = [`variables.${ name }`, name];
|
const names = [`variables.${ name }`, name];
|
||||||
|
|
||||||
const variable = this.processVariables.find(
|
const processVariable = this.processVariables.find(
|
||||||
entry => names.includes(entry.name)
|
entry => names.includes(entry.name)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (variable) {
|
if (processVariable) {
|
||||||
return this.parseValue(variable.type, variable.value);
|
value = this.parseValue(processVariable.type, processVariable.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
if (!value) {
|
||||||
|
value = this.getDefaultFormVariableValue(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected parseValue(type: string, value: any): any {
|
protected parseValue(type: string, value: any): any {
|
||||||
|
@@ -283,7 +283,7 @@ export class WidgetVisibilityService {
|
|||||||
|
|
||||||
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]): string {
|
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]): string {
|
||||||
const processVariableValue = this.getProcessVariableValue(name, processVarList);
|
const processVariableValue = this.getProcessVariableValue(name, processVarList);
|
||||||
const variableDefaultValue = form.getFormVariableValue(name);
|
const variableDefaultValue = form.getDefaultFormVariableValue(name);
|
||||||
|
|
||||||
return (processVariableValue === undefined) ? variableDefaultValue : processVariableValue;
|
return (processVariableValue === undefined) ? variableDefaultValue : processVariableValue;
|
||||||
}
|
}
|
||||||
|
@@ -330,8 +330,7 @@ describe('AttachFileCloudWidgetComponent', () => {
|
|||||||
it('should be able to use mapped string variable value if the destinationFolderPath set to string type variable', async () => {
|
it('should be able to use mapped string variable value if the destinationFolderPath set to string type variable', async () => {
|
||||||
const getNodeIdFromPathSpy = spyOn(contentCloudNodeSelectorService, 'getNodeIdFromPath').and.returnValue(mockNodeIdBasedOnStringVariableValue);
|
const getNodeIdFromPathSpy = spyOn(contentCloudNodeSelectorService, 'getNodeIdFromPath').and.returnValue(mockNodeIdBasedOnStringVariableValue);
|
||||||
|
|
||||||
const variables = formVariables;
|
const form = new FormModel({ formVariables, processVariables });
|
||||||
const form = new FormModel({ variables, formVariables, processVariables });
|
|
||||||
createUploadWidgetField(form, 'attach-file-alfresco', [], mockAllFileSourceWithStringVariablePathType);
|
createUploadWidgetField(form, 'attach-file-alfresco', [], mockAllFileSourceWithStringVariablePathType);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
@@ -791,10 +790,9 @@ describe('AttachFileCloudWidgetComponent', () => {
|
|||||||
|
|
||||||
describe('Upload widget with destination folder path params', () => {
|
describe('Upload widget with destination folder path params', () => {
|
||||||
let form: FormModel;
|
let form: FormModel;
|
||||||
const variables = formVariables;
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
form = new FormModel({
|
form = new FormModel({
|
||||||
variables,
|
|
||||||
formVariables,
|
formVariables,
|
||||||
processVariables
|
processVariables
|
||||||
});
|
});
|
||||||
@@ -808,6 +806,24 @@ describe('AttachFileCloudWidgetComponent', () => {
|
|||||||
expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('-root-/pathBasedOnStringvariablevalue');
|
expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('-root-/pathBasedOnStringvariablevalue');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to fetch the destinationFolderPath from the default value of a form variable', () => {
|
||||||
|
form.processVariables = [];
|
||||||
|
form.variables = formVariables;
|
||||||
|
|
||||||
|
createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithStringVariablePathType);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('mock destination folder path');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it should get a destination folder path value from a folder variable', () => {
|
||||||
|
createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithFolderVariablePathType);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(widget.field.params.fileSource.destinationFolderPath.type).toBe('folder');
|
||||||
|
expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('mock-folder-id');
|
||||||
|
});
|
||||||
|
|
||||||
it('it should get a destination folder path value from a folder variable', () => {
|
it('it should get a destination folder path value from a folder variable', () => {
|
||||||
createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithFolderVariablePathType);
|
createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithFolderVariablePathType);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@@ -204,6 +204,6 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getDestinationFolderPathValue(): any {
|
private getDestinationFolderPathValue(): any {
|
||||||
return this.field.form.getFormVariableValue(this.field.params.fileSource?.destinationFolderPath?.name);
|
return this.field.form.getProcessVariableValue(this.field.params.fileSource?.destinationFolderPath?.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -397,13 +397,12 @@ export const formVariables = [
|
|||||||
id: 'bfca9766-7bc1-45cc-8ecf-cdad551e36e2',
|
id: 'bfca9766-7bc1-45cc-8ecf-cdad551e36e2',
|
||||||
name: 'name1',
|
name: 'name1',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
value: '-root-/pathBasedOnStringvariablevalue'
|
value: 'mock destination folder path'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '3ed9f28a-dbae-463f-b991-47ef06658bb6',
|
id: '3ed9f28a-dbae-463f-b991-47ef06658bb6',
|
||||||
name: 'name2',
|
name: 'name2',
|
||||||
type: 'folder',
|
type: 'folder'
|
||||||
value: [{ id: 'mock-folder-id'}]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'booleanVar',
|
id: 'booleanVar',
|
||||||
|
Reference in New Issue
Block a user