|
@@ -15,7 +15,70 @@
|
|
|
dataMap: current
|
|
|
};
|
|
|
$(this).closest('form').find('input[name="data"]').val(JSON.stringify(fullData));
|
|
|
+
|
|
|
+ runDQConditions($(this).closest('.dq-edit-container'));
|
|
|
});
|
|
|
};
|
|
|
+
|
|
|
+ function resolveAtomicCondition(_condition, _dataMap) {
|
|
|
+ if(!_condition.hasOwnProperty('key') || !_condition.hasOwnProperty('value')) {
|
|
|
+ _condition.resolution = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let key = _condition.key, op = _condition.hasOwnProperty('op') ? _condition.op : 'eq';
|
|
|
+ let lhs = _dataMap[key], rhs = _condition.value;
|
|
|
+ switch(op) {
|
|
|
+ case 'eq':
|
|
|
+ _condition.resolution = (lhs == rhs); // NOTE: using == instead of === on purpose
|
|
|
+ break;
|
|
|
+ case 'lt':
|
|
|
+ _condition.resolution = (+lhs < +rhs);
|
|
|
+ break;
|
|
|
+ case 'lte':
|
|
|
+ _condition.resolution = (+lhs <= +rhs);
|
|
|
+ break;
|
|
|
+ case 'gt':
|
|
|
+ _condition.resolution = (+lhs > +rhs);
|
|
|
+ break;
|
|
|
+ case 'gte':
|
|
|
+ _condition.resolution = (+lhs >= +rhs);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ _condition.resolution = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function resolveAllAtomicConditions(_conditions, _dataMap) {
|
|
|
+ if(Array.isArray(_conditions)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ resolveAtomicCondition(_conditions, _dataMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ window.runDQConditions = function(_parent) {
|
|
|
+
|
|
|
+ _parent.find('.dq-line.has-pre-condition').each(function() {
|
|
|
+ let conditions = JSON.parse($(this).find('>.dq-pre-condition').first().text()),
|
|
|
+ dataMap = JSON.parse($(this).closest('.dq-edit-container').find('>.dq-data-map').first().text());
|
|
|
+
|
|
|
+ resolveAllAtomicConditions(conditions, dataMap);
|
|
|
+
|
|
|
+ // if object, single condition with key, op and value
|
|
|
+ if(!Array.isArray(conditions)) {
|
|
|
+ if(conditions.resolution) {
|
|
|
+ $(this).removeClass('d-none');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $(this).addClass('d-none');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // else if array - means list of conditions with 'and' or 'or' separators - array size MUST be an odd number
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
addMCInitializer('dq-edit', initDQ, '.dq-edit-container');
|
|
|
}).call(window);
|