mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4546] Visibility conditions for Form variables don't work on Multiline Widget. (#4786)
* * Finding variable values by id & used date format * * Tests to validate visibility by using id * * [ADF-4529] Refactor conditions * [ADF-4529] Fixed cloud form editor script error
This commit is contained in:
committed by
Eugenio Romano
parent
30c42d17d0
commit
7eb9ffe688
@@ -54,7 +54,8 @@ export class FormCloudDemoComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.formConfig = this.automationService.forms.getFormCloudDefinition();
|
const formDefinitionJSON = this.automationService.forms.getFormCloudDefinition();
|
||||||
|
this.formConfig = JSON.stringify(formDefinitionJSON);
|
||||||
this.parseForm();
|
this.parseForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -898,4 +898,78 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(contModel.isVisible).toBeFalsy();
|
expect(contModel.isVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Visibility based on form variables', () => {
|
||||||
|
|
||||||
|
const fakeFormWithVariables = new FormModel(fakeFormJson);
|
||||||
|
let visibilityObjTest: WidgetVisibilityModel;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set visibility to true when validation for string variables succeeds', () => {
|
||||||
|
visibilityObjTest.leftRestResponseId = 'name';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightValue = 'abc';
|
||||||
|
const isVisible = service.isFieldVisible(fakeFormWithVariables, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(isVisible).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set visibility to false when validation for string variables fails', () => {
|
||||||
|
visibilityObjTest.leftRestResponseId = 'name';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightValue = 'abc1';
|
||||||
|
const isVisible = service.isFieldVisible(fakeFormWithVariables, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(isVisible).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set visibility to true when validation for integer variables succeeds', () => {
|
||||||
|
visibilityObjTest.leftRestResponseId = 'age';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightValue = '11';
|
||||||
|
const isVisible = service.isFieldVisible(fakeFormWithVariables, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(isVisible).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set visibility to false when validation for integer variables fails', () => {
|
||||||
|
visibilityObjTest.leftRestResponseId = 'age';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightValue = '13';
|
||||||
|
const isVisible = service.isFieldVisible(fakeFormWithVariables, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(isVisible).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set visibility to true when validation for date variables succeeds', () => {
|
||||||
|
visibilityObjTest.leftRestResponseId = 'dob';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightValue = '2019-05-13';
|
||||||
|
const isVisible = service.isFieldVisible(fakeFormWithVariables, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(isVisible).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set visibility to false when validation for date variables fails', () => {
|
||||||
|
visibilityObjTest.leftRestResponseId = 'dob';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightValue = '2019-05-15';
|
||||||
|
const isVisible = service.isFieldVisible(fakeFormWithVariables, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(isVisible).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate visiblity for form fields by finding the field with id', () => {
|
||||||
|
visibilityObjTest.leftRestResponseId = '0207b649-ff07-4f3a-a589-d10afa507b9b';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightValue = '2019-05-13';
|
||||||
|
const isVisible = service.isFieldVisible(fakeFormWithVariables, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(isVisible).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -75,7 +75,7 @@ export class WidgetVisibilityService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel): string {
|
||||||
let leftValue = '';
|
let leftValue = '';
|
||||||
if (visibilityObj.leftRestResponseId && visibilityObj.leftRestResponseId !== 'null') {
|
if (visibilityObj.leftRestResponseId && visibilityObj.leftRestResponseId !== 'null') {
|
||||||
leftValue = this.getVariableValue(form, visibilityObj.leftRestResponseId, this.processVarList);
|
leftValue = this.getVariableValue(form, visibilityObj.leftRestResponseId, this.processVarList);
|
||||||
@@ -86,7 +86,7 @@ export class WidgetVisibilityService {
|
|||||||
return leftValue;
|
return leftValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRightValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
getRightValue(form: FormModel, visibilityObj: WidgetVisibilityModel): string {
|
||||||
let valueFound = '';
|
let valueFound = '';
|
||||||
if (visibilityObj.rightRestResponseId) {
|
if (visibilityObj.rightRestResponseId) {
|
||||||
valueFound = this.getVariableValue(form, visibilityObj.rightRestResponseId, this.processVarList);
|
valueFound = this.getVariableValue(form, visibilityObj.rightRestResponseId, this.processVarList);
|
||||||
@@ -102,7 +102,7 @@ export class WidgetVisibilityService {
|
|||||||
return valueFound;
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormValue(form: FormModel, fieldId: string) {
|
getFormValue(form: FormModel, fieldId: string): any {
|
||||||
let value = this.getFieldValue(form.values, fieldId);
|
let value = this.getFieldValue(form.values, fieldId);
|
||||||
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -112,7 +112,7 @@ export class WidgetVisibilityService {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFieldValue(valueList: any, fieldId: string) {
|
getFieldValue(valueList: any, fieldId: string): any {
|
||||||
let dropDownFilterByName, valueFound;
|
let dropDownFilterByName, valueFound;
|
||||||
if (fieldId && fieldId.indexOf('_LABEL') > 0) {
|
if (fieldId && fieldId.indexOf('_LABEL') > 0) {
|
||||||
dropDownFilterByName = fieldId.substring(0, fieldId.length - 6);
|
dropDownFilterByName = fieldId.substring(0, fieldId.length - 6);
|
||||||
@@ -127,7 +127,7 @@ export class WidgetVisibilityService {
|
|||||||
return valueFound;
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchValueInForm(form: FormModel, fieldId: string) {
|
searchValueInForm(form: FormModel, fieldId: string): string {
|
||||||
let fieldValue = '';
|
let fieldValue = '';
|
||||||
form.getFormFields().forEach((formField: FormFieldModel) => {
|
form.getFormFields().forEach((formField: FormFieldModel) => {
|
||||||
if (this.isSearchedField(formField, fieldId)) {
|
if (this.isSearchedField(formField, fieldId)) {
|
||||||
@@ -145,7 +145,7 @@ export class WidgetVisibilityService {
|
|||||||
return fieldValue;
|
return fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getObjectValue(field: FormFieldModel, fieldId: string) {
|
private getObjectValue(field: FormFieldModel, fieldId: string): string {
|
||||||
let value = '';
|
let value = '';
|
||||||
if (field.value && field.value.name) {
|
if (field.value && field.value.name) {
|
||||||
value = field.value.name;
|
value = field.value.name;
|
||||||
@@ -181,22 +181,47 @@ export class WidgetVisibilityService {
|
|||||||
return formattedFieldName;
|
return formattedFieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]) {
|
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]): string {
|
||||||
return this.getFormVariableValue(form, name) ||
|
return this.getFormVariableValue(form, name) ||
|
||||||
this.getProcessVariableValue(name, processVarList);
|
this.getProcessVariableValue(name, processVarList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFormVariableValue(form: FormModel, name: string) {
|
private getFormVariableValue(form: FormModel, identifier: string): string {
|
||||||
if (form.json.variables) {
|
const variables = this.getFormVariables(form);
|
||||||
const formVariable = form.json.variables.find((formVar) => formVar.name === name);
|
if (variables) {
|
||||||
return formVariable ? formVariable.value : formVariable;
|
const formVariable = variables.find((formVar) => {
|
||||||
|
return formVar.name === identifier || formVar.id === identifier;
|
||||||
|
});
|
||||||
|
|
||||||
|
let value;
|
||||||
|
if (formVariable) {
|
||||||
|
value = formVariable.value;
|
||||||
|
if (formVariable.type === 'date') {
|
||||||
|
value += 'T00:00:00.000Z';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getProcessVariableValue(name: string, processVarList: TaskProcessVariableModel[]) {
|
private getFormVariables(form: FormModel): any[] {
|
||||||
if (this.processVarList) {
|
let variables;
|
||||||
const processVariable = this.processVarList.find((variable) => variable.id === name);
|
if (form.json.formRepresentation) {
|
||||||
return processVariable ? processVariable.value : processVariable;
|
variables = form.json.formRepresentation.formDefinition.variables;
|
||||||
|
} else {
|
||||||
|
variables = form.json.variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getProcessVariableValue(name: string, processVarList: TaskProcessVariableModel[]): string {
|
||||||
|
if (processVarList) {
|
||||||
|
const processVariable = processVarList.find((variable) => variable.id === name);
|
||||||
|
if (processVariable) {
|
||||||
|
return processVariable.value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +282,7 @@ export class WidgetVisibilityService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(res: any) {
|
toJson(res: any): any {
|
||||||
return res || {};
|
return res || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,5 +93,25 @@ export let fakeFormJson = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
variables: [
|
||||||
|
{
|
||||||
|
'id': 'e621e8ff-42a6-499c-8121-33c7c35d8641',
|
||||||
|
'name': 'age',
|
||||||
|
'type': 'integer',
|
||||||
|
'value': 11
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '4f8aa99e-8526-429c-9d99-809978489d96',
|
||||||
|
'name': 'name',
|
||||||
|
'type': 'string',
|
||||||
|
'value': 'abc'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '0207b649-ff07-4f3a-a589-d10afa507b9b',
|
||||||
|
'name': 'dob',
|
||||||
|
'type': 'date',
|
||||||
|
'value': '2019-05-13'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user