|
@@ -50,13 +50,50 @@
|
|
|
|
|
|
function resolveAllAtomicConditions(_conditions, _dataMap) {
|
|
function resolveAllAtomicConditions(_conditions, _dataMap) {
|
|
if(Array.isArray(_conditions)) {
|
|
if(Array.isArray(_conditions)) {
|
|
-
|
|
|
|
|
|
+ for (let i = 0; i < _conditions.length; i++) {
|
|
|
|
+ resolveAllAtomicConditions(_conditions[i], _dataMap);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else if(typeof _conditions === 'object') {
|
|
resolveAtomicCondition(_conditions, _dataMap);
|
|
resolveAtomicCondition(_conditions, _dataMap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function reduceConditionsIntoResolutions(_conditions) {
|
|
|
|
+ for (let i = 0; i < _conditions.length; i++) {
|
|
|
|
+ // if simple object, resolve
|
|
|
|
+ if(!Array.isArray(_conditions[i]) && typeof _conditions[i] === 'object') {
|
|
|
|
+ _conditions.splice(i, 1, _conditions[i].resolution);
|
|
|
|
+ }
|
|
|
|
+ else if(Array.isArray(_conditions[i])) {
|
|
|
|
+ reduceConditionsIntoResolutions(_conditions[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function combineResolutionListsIntoSingleResolutions(_conditions) {
|
|
|
|
+ console.log('ALIX 1', _conditions);
|
|
|
|
+ for (let i = 0; i < _conditions.length; i++) {
|
|
|
|
+ if(Array.isArray(_conditions[i])) {
|
|
|
|
+ _conditions[i] = combineResolutionListsIntoSingleResolutions(_conditions[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ console.log('ALIX 2', _conditions);
|
|
|
|
+
|
|
|
|
+ // at this point, the array will have only booleans and "AND", "OR" combinators
|
|
|
|
+ let resolution = _conditions[0];
|
|
|
|
+ for (let i = 1; i < _conditions.length; i+=2) {
|
|
|
|
+ if(_conditions[i] === 'AND') {
|
|
|
|
+ resolution = resolution && _conditions[i + 1];
|
|
|
|
+ }
|
|
|
|
+ else if(_conditions[i] === 'OR') {
|
|
|
|
+ resolution = resolution || _conditions[i + 1];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resolution;
|
|
|
|
+ }
|
|
|
|
+
|
|
window.runDQConditions = function(_parent) {
|
|
window.runDQConditions = function(_parent) {
|
|
|
|
|
|
_parent.find('.dq-line.has-pre-condition').each(function() {
|
|
_parent.find('.dq-line.has-pre-condition').each(function() {
|
|
@@ -66,7 +103,7 @@
|
|
resolveAllAtomicConditions(conditions, dataMap);
|
|
resolveAllAtomicConditions(conditions, dataMap);
|
|
|
|
|
|
// if object, single condition with key, op and value
|
|
// if object, single condition with key, op and value
|
|
- if(!Array.isArray(conditions)) {
|
|
|
|
|
|
+ if(!Array.isArray(conditions) && typeof conditions === 'object') {
|
|
if(conditions.resolution) {
|
|
if(conditions.resolution) {
|
|
$(this).removeClass('d-none');
|
|
$(this).removeClass('d-none');
|
|
}
|
|
}
|
|
@@ -74,8 +111,22 @@
|
|
$(this).addClass('d-none');
|
|
$(this).addClass('d-none');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
// else if array - means list of conditions with 'and' or 'or' separators - array size MUST be an odd number
|
|
// else if array - means list of conditions with 'and' or 'or' separators - array size MUST be an odd number
|
|
|
|
+ else if(Array.isArray(conditions)) {
|
|
|
|
+
|
|
|
|
+ // goal is to reduce each item in the array into a single boolean - recursively
|
|
|
|
+ reduceConditionsIntoResolutions(conditions);
|
|
|
|
+
|
|
|
|
+ conditions = combineResolutionListsIntoSingleResolutions(conditions);
|
|
|
|
+
|
|
|
|
+ if(conditions) {
|
|
|
|
+ $(this).removeClass('d-none');
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $(this).addClass('d-none');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|