mirror of
https://github.com/wekan/wekan.git
synced 2025-12-23 19:00:12 +01:00
More conditions and logic Operators, Also Brackets.
This commit is contained in:
parent
c3044a6b8b
commit
1c0c5bde0f
1 changed files with 148 additions and 4 deletions
|
|
@ -158,14 +158,60 @@ class AdvancedFilter {
|
||||||
console.log('Parts: ', JSON.stringify(commands));
|
console.log('Parts: ', JSON.stringify(commands));
|
||||||
try {
|
try {
|
||||||
//let changed = false;
|
//let changed = false;
|
||||||
|
this._processSubCommands(commands);
|
||||||
|
}
|
||||||
|
catch (e){return { $in: [] };}
|
||||||
|
return {$or: commands};
|
||||||
|
}
|
||||||
|
|
||||||
|
_processSubCommands(commands)
|
||||||
|
{
|
||||||
|
console.log('SubCommands: ', JSON.stringify(commands));
|
||||||
|
const subcommands = [];
|
||||||
|
let level = 0;
|
||||||
|
let start = -1;
|
||||||
|
for (let i = 0; i < commands.length; i++)
|
||||||
|
{
|
||||||
|
if (!commands[i].string && commands[i].cmd)
|
||||||
|
{
|
||||||
|
switch (commands[i].cmd)
|
||||||
|
{
|
||||||
|
case '(':
|
||||||
|
{
|
||||||
|
level++;
|
||||||
|
if (start === -1) start = i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
case ')':
|
||||||
|
{
|
||||||
|
level--;
|
||||||
|
commands.splice(i, 1);
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (level > 0)
|
||||||
|
{
|
||||||
|
subcommands.push(commands[i]);
|
||||||
|
commands.splice(i, 1);
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start !== -1)
|
||||||
|
{
|
||||||
|
this._processSubCommands(subcommands);
|
||||||
|
commands.splice(start, 0, subcommands);
|
||||||
|
}
|
||||||
this._processConditions(commands);
|
this._processConditions(commands);
|
||||||
console.log('Conditions: ', JSON.stringify(commands));
|
console.log('Conditions: ', JSON.stringify(commands));
|
||||||
this._processLogicalOperators(commands);
|
this._processLogicalOperators(commands);
|
||||||
console.log('Operator: ', JSON.stringify(commands));
|
console.log('Operator: ', JSON.stringify(commands));
|
||||||
}
|
}
|
||||||
catch (e){return { $in: [] };}
|
|
||||||
return {$or: commands};
|
|
||||||
}
|
|
||||||
|
|
||||||
_processConditions(commands)
|
_processConditions(commands)
|
||||||
{
|
{
|
||||||
|
|
@ -188,6 +234,76 @@ class AdvancedFilter {
|
||||||
i--;
|
i--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case '!=':
|
||||||
|
case '!==':
|
||||||
|
{
|
||||||
|
const field = commands[i-1].cmd;
|
||||||
|
const str = commands[i+1].cmd;
|
||||||
|
commands[i] = {$not: {'customFields._id':this._fieldNameToId(field), 'customFields.value':str}};
|
||||||
|
commands.splice(i-1, 1);
|
||||||
|
commands.splice(i, 1);
|
||||||
|
//changed = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '>':
|
||||||
|
case 'gt':
|
||||||
|
case 'Gt':
|
||||||
|
case 'GT':
|
||||||
|
{
|
||||||
|
const field = commands[i-1].cmd;
|
||||||
|
const str = commands[i+1].cmd;
|
||||||
|
commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value': { $gt: str } };
|
||||||
|
commands.splice(i-1, 1);
|
||||||
|
commands.splice(i, 1);
|
||||||
|
//changed = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '>=':
|
||||||
|
case '>==':
|
||||||
|
case 'gte':
|
||||||
|
case 'Gte':
|
||||||
|
case 'GTE':
|
||||||
|
{
|
||||||
|
const field = commands[i-1].cmd;
|
||||||
|
const str = commands[i+1].cmd;
|
||||||
|
commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value': { $gte: str } };
|
||||||
|
commands.splice(i-1, 1);
|
||||||
|
commands.splice(i, 1);
|
||||||
|
//changed = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '<':
|
||||||
|
case 'lt':
|
||||||
|
case 'Lt':
|
||||||
|
case 'LT':
|
||||||
|
{
|
||||||
|
const field = commands[i-1].cmd;
|
||||||
|
const str = commands[i+1].cmd;
|
||||||
|
commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value': { $lt: str } };
|
||||||
|
commands.splice(i-1, 1);
|
||||||
|
commands.splice(i, 1);
|
||||||
|
//changed = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '<=':
|
||||||
|
case '<==':
|
||||||
|
case 'lte':
|
||||||
|
case 'Lte':
|
||||||
|
case 'LTE':
|
||||||
|
{
|
||||||
|
const field = commands[i-1].cmd;
|
||||||
|
const str = commands[i+1].cmd;
|
||||||
|
commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value': { $lte: str } };
|
||||||
|
commands.splice(i-1, 1);
|
||||||
|
commands.splice(i, 1);
|
||||||
|
//changed = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -217,6 +333,34 @@ class AdvancedFilter {
|
||||||
i--;
|
i--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'and':
|
||||||
|
case 'And':
|
||||||
|
case 'AND':
|
||||||
|
case '&':
|
||||||
|
case '&&':
|
||||||
|
{
|
||||||
|
const op1 = commands[i-1];
|
||||||
|
const op2 = commands[i+1];
|
||||||
|
commands[i] = {$and: [op1, op2]};
|
||||||
|
commands.splice(i-1, 1);
|
||||||
|
commands.splice(i, 1);
|
||||||
|
//changed = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'not':
|
||||||
|
case 'Not':
|
||||||
|
case 'NOT':
|
||||||
|
case '!':
|
||||||
|
{
|
||||||
|
const op1 = commands[i+1];
|
||||||
|
commands[i] = {$not: op1};
|
||||||
|
commands.splice(i+1, 1);
|
||||||
|
//changed = true;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue