Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions packages/core/modules/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ const conjunctions = {

//---------------------------- operators



const operators = {
equal: {
label: "==",
Expand All @@ -98,7 +96,7 @@ const operators = {
return `${field} ${opStr} ${value}`;
},
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$eq", v => v, false, ...args); },
jsonLogic: "==",
jsonLogic: ({field, val}) => ({ "==": [field, val] }),
elasticSearchQueryType: "term",
},
not_equal: {
Expand All @@ -117,7 +115,7 @@ const operators = {
return `${field} ${opDef.label} ${value}`;
},
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$ne", v => v, false, ...args); },
jsonLogic: "!=",
jsonLogic: ({field, val}) => ({ "!=": [field, val] }),
},
less: {
label: "<",
Expand All @@ -127,7 +125,7 @@ const operators = {
spelOps: ["<", "lt"],
reversedOp: "greater_or_equal",
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$lt", v => v, false, ...args); },
jsonLogic: "<",
jsonLogic: ({field, val}) => ({ "<": [field, val] }),
elasticSearchQueryType: "range",
},
less_or_equal: {
Expand All @@ -138,7 +136,7 @@ const operators = {
spelOps: ["<=", "le"],
reversedOp: "greater",
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$lte", v => v, false, ...args); },
jsonLogic: "<=",
jsonLogic: ({field, val}) => ({ "<=": [field, val] }),
elasticSearchQueryType: "range",
},
greater: {
Expand All @@ -149,7 +147,7 @@ const operators = {
spelOps: [">", "gt"],
reversedOp: "less_or_equal",
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$gt", v => v, false, ...args); },
jsonLogic: ">",
jsonLogic: ({field, val}) => ({ ">": [field, val] }),
elasticSearchQueryType: "range",
},
greater_or_equal: {
Expand All @@ -160,7 +158,7 @@ const operators = {
spelOps: [">=", "ge"],
reversedOp: "less",
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$gte", v => v, false, ...args); },
jsonLogic: ">=",
jsonLogic: ({field, val}) => ({ ">=": [field, val] }),
elasticSearchQueryType: "range",
},
like: {
Expand Down Expand Up @@ -193,7 +191,7 @@ const operators = {
spelOp: "${0}.contains(${1})",
valueTypes: ["text"],
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$regex", v => (typeof v == "string" ? this.utils.escapeRegExp(v) : undefined), false, ...args); },
jsonLogic: (field, op, val) => ({ "in": [val, field] }),
jsonLogic: ({field, val}) => ({ "in": [val, field] }),
jsonLogic2: "#in",
valueSources: ["value"],
elasticSearchQueryType: "regexp",
Expand All @@ -205,7 +203,7 @@ const operators = {
labelForFormat: "Not Contains",
sqlOp: "NOT LIKE",
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$regex", v => (typeof v == "string" ? this.utils.escapeRegExp(v) : undefined), true, ...args); },
jsonLogic: (field, op, val) => ({"!": { "in": [val, field] }}),
jsonLogic: ({field, val}) => ({"!": { "in": [val, field] }}),
jsonLogic2: "#!in",
_jsonLogicIsExclamationOp: true,
valueSources: ["value"],
Expand Down Expand Up @@ -257,7 +255,7 @@ const operators = {
"and"
],
reversedOp: "not_between",
jsonLogic: "<=",
jsonLogic: ({field, twoVals}) => ({ "<=": [twoVals[0], field, twoVals[1]] }),
validateValues: (values) => {
if (values[0] != undefined && values[1] != undefined) {
return values[0] <= values[1];
Expand Down Expand Up @@ -297,7 +295,7 @@ const operators = {
"and"
],
reversedOp: "between",
jsonLogic: (field, op, val) => ({"!": { "<=": [Array.isArray(val) ? val[0] : val, field, Array.isArray(val) ? val[1] : val] }}),
jsonLogic: ({field, twoVals}) => ({"!": { "<=": [twoVals[0], field, twoVals[1]] }}),
jsonLogic2: "!<=",
_jsonLogicIsExclamationOp: true,
validateValues: (values) => {
Expand Down Expand Up @@ -336,7 +334,7 @@ const operators = {
return `${field} <= ''`;
},
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$in", (v, fieldDef) => [this.utils.mongoEmptyValue(fieldDef), null], false, ...args); },
jsonLogic: "!",
jsonLogic: ({field}) => ({"!": field}),
},
is_not_empty: {
isNotOp: true,
Expand All @@ -356,7 +354,7 @@ const operators = {
return `${field} > ''`;
},
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$nin", (v, fieldDef) => [this.utils.mongoEmptyValue(fieldDef), null], false, ...args); },
jsonLogic: "!!",
jsonLogic: ({field}) => ({"!!": field}),
elasticSearchQueryType: "exists",
},
is_null: {
Expand Down Expand Up @@ -385,7 +383,7 @@ const operators = {
},
// check if value is null OR not exists
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$eq", v => null, false, ...args); },
jsonLogic: "==",
jsonLogic: ({field}) => ({"==": [field, null]}),
},
is_not_null: {
label: "Is not null",
Expand All @@ -401,7 +399,7 @@ const operators = {
},
// check if value exists and is not null
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$ne", v => null, false, ...args); },
jsonLogic: "!=",
jsonLogic: ({field}) => ({"!=": [field, null]}),
elasticSearchQueryType: "exists",
},
select_equals: {
Expand All @@ -416,7 +414,7 @@ const operators = {
spelOps: ["==", "eq"],
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$eq", v => v, false, ...args); },
reversedOp: "select_not_equals",
jsonLogic: "==",
jsonLogic: ({field, val}) => ({"==": [field, val]}),
elasticSearchQueryType: "term",
},
select_not_equals: {
Expand All @@ -432,7 +430,7 @@ const operators = {
spelOps: ["!=", "ne"],
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$ne", v => v, false, ...args); },
reversedOp: "select_equals",
jsonLogic: "!=",
jsonLogic: ({field, val}) => ({"!=": [field, val]}),
},
select_any_in: {
label: "Any in",
Expand All @@ -453,7 +451,7 @@ const operators = {
spelOp: "${1}.contains(${0})",
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$in", v => v, false, ...args); },
reversedOp: "select_not_any_in",
jsonLogic: "in",
jsonLogic: ({field, vals}) => ({"in": [field, vals]}),
elasticSearchQueryType: "term",
},
select_not_any_in: {
Expand All @@ -474,7 +472,7 @@ const operators = {
},
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$nin", v => v, false, ...args); },
reversedOp: "select_any_in",
jsonLogic: (field, op, val) => ({"!": { "in": [field, val] }}),
jsonLogic: ({field, vals}) => ({"!": {"in": [field, vals]}}),
jsonLogic2: "!in",
_jsonLogicIsExclamationOp: true,
},
Expand All @@ -491,7 +489,7 @@ const operators = {
},
reversedOp: "multiselect_not_contains",
jsonLogic2: "some-in",
jsonLogic: (field, op, vals) => ({
jsonLogic: ({field, vals}) => ({
"some": [ field, {"in": [{"var": ""}, vals]} ]
}),
//spelOp: "${0}.containsAll(${1})",
Expand Down Expand Up @@ -526,7 +524,7 @@ const operators = {
},
reversedOp: "multiselect_contains",
jsonLogic2: "!some-in",
jsonLogic: (field, op, vals) => ({
jsonLogic: ({field, vals}) => ({
"!": { "some": [ field, {"in": [{"var": ""}, vals]} ]}
}),
_jsonLogicIsExclamationOp: true,
Expand Down Expand Up @@ -554,7 +552,7 @@ const operators = {
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$eq", v => v, false, ...args); },
reversedOp: "multiselect_not_equals",
jsonLogic2: "all-in",
jsonLogic: (field, op, vals) => ({
jsonLogic: ({field, vals}) => ({
// it's not "equals", but "includes" operator - just for example
"all": [ field, {"in": [{"var": ""}, vals]} ]
}),
Expand Down Expand Up @@ -583,7 +581,7 @@ const operators = {
mongoFormatOp: function(...args) { return this.utils.mongoFormatOp1("$ne", v => v, false, ...args); },
reversedOp: "multiselect_equals",
jsonLogic2: "!all-in",
jsonLogic: (field, op, vals) => ({
jsonLogic: ({field, vals}) => ({
// it's not "equals", but "includes" operator - just for example
"!": { "all": [ field, {"in": [{"var": ""}, vals]} ]}
}),
Expand Down
11 changes: 6 additions & 5 deletions packages/core/modules/export/jsonLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const jsonLogicFormat = (item, config) => {

const extendedConfig = extendConfig(config, undefined, false);
const logic = formatItem(item, extendedConfig, meta, false, true);

// build empty data
const {errors, usedFields} = meta;
const {fieldSeparator} = extendedConfig.settings;
Expand Down Expand Up @@ -568,16 +568,17 @@ const formatLogic = (config, properties, formattedField, formattedValue, operato
let fn = typeof operatorDefinition.jsonLogic == "function"
? operatorDefinition.jsonLogic
: buildFnToFormatOp(operator, operatorDefinition, formattedField, formattedValue);
const args = [
/* const args = [
formattedField,
operator,
formattedValue,
omit(operatorDefinition, opDefKeysToOmit),
operatorOptions,
fieldDefinition,
];
let ruleQuery = fn.call(config.ctx, ...args);

];*/
const functionInput = {field: formattedField, val: formattedValue, vals: formattedValue, twoVals: formattedValue};
//let ruleQuery = fn.call(functionInput);
let ruleQuery = fn(functionInput);
if (isRev) {
ruleQuery = { "!": ruleQuery };
}
Expand Down
Loading
Loading