mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-22348] - Fixed visibility when complex cases are appling (#7176)
* [MNT-22348] - Fixed visibility when complex cases are appling * [MNT-22348] - Fixed lint errrors * [MNT-22461] Unit test for visibility condition behaviour for checkxox expression is added * fixed unit test for visibility condition * [MNT-22348] - Fixed wrong form definition * [MNT-22348] - Fixed wrong quote * [MNT-22348] - Fixed wrong form definition * [MNT-22348] - fixed form definition Co-authored-by: Ketevani Kvirikashvili <qqetikv@gmail.com>
This commit is contained in:
@@ -84,28 +84,38 @@ export class WidgetVisibilityService {
|
||||
const rightValue = this.getRightValue(form, visibilityObj);
|
||||
const actualResult = this.evaluateCondition(leftValue, rightValue, visibilityObj.operator);
|
||||
|
||||
if (this.isValidOperator(visibilityObj.nextConditionOperator)) {
|
||||
accumulator.push({ value: actualResult, operator: visibilityObj.nextConditionOperator });
|
||||
}
|
||||
accumulator.push({ value: actualResult, operator: visibilityObj.nextConditionOperator });
|
||||
|
||||
if (this.isValidCondition(visibilityObj.nextCondition)) {
|
||||
result = this.isFieldVisible(form, visibilityObj.nextCondition, accumulator);
|
||||
} else if (accumulator[0] !== undefined) {
|
||||
result = accumulator[0].value;
|
||||
for (let i = 1; i < accumulator.length; i++) {
|
||||
if (accumulator[i] !== undefined) {
|
||||
result = this.evaluateLogicalOperation(
|
||||
accumulator[i - 1].operator,
|
||||
result,
|
||||
accumulator[i].value
|
||||
);
|
||||
}
|
||||
}
|
||||
result = Function('"use strict";return (' +
|
||||
accumulator.map((expression) => this.transformToLiteralExpression(expression)).join('') +
|
||||
')')();
|
||||
} else {
|
||||
result = actualResult;
|
||||
}
|
||||
return !!result;
|
||||
}
|
||||
|
||||
private transformToLiteralExpression(currentExpression: any): string {
|
||||
const currentTransformedValue = !!currentExpression.value ? 'true' : 'false';
|
||||
return currentTransformedValue.concat(this.transformToLiteralOperator(currentExpression.operator));
|
||||
}
|
||||
|
||||
private transformToLiteralOperator(currentOperator): string {
|
||||
switch (currentOperator) {
|
||||
case 'and':
|
||||
return '&&';
|
||||
case 'or' :
|
||||
return '||';
|
||||
case 'and-not':
|
||||
return '&& !';
|
||||
case 'or-not':
|
||||
return '|| !';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel): string {
|
||||
@@ -280,22 +290,6 @@ export class WidgetVisibilityService {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
evaluateLogicalOperation(logicOp: string, previousValue: any, newValue: any): boolean | undefined {
|
||||
switch (logicOp) {
|
||||
case 'and':
|
||||
return previousValue && newValue;
|
||||
case 'or' :
|
||||
return previousValue || newValue;
|
||||
case 'and-not':
|
||||
return previousValue && !newValue;
|
||||
case 'or-not':
|
||||
return previousValue || !newValue;
|
||||
default:
|
||||
this.logService.error(`Invalid operator: ${logicOp}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
evaluateCondition(leftValue: any, rightValue: any, operator: string): boolean | undefined {
|
||||
switch (operator) {
|
||||
case '==':
|
||||
@@ -340,10 +334,6 @@ export class WidgetVisibilityService {
|
||||
return res || {};
|
||||
}
|
||||
|
||||
private isValidOperator(operator: string): boolean {
|
||||
return operator !== undefined;
|
||||
}
|
||||
|
||||
private isValidCondition(condition: WidgetVisibilityModel): boolean {
|
||||
return !!(condition && condition.operator);
|
||||
}
|
||||
|
Reference in New Issue
Block a user