summaryrefslogtreecommitdiffstats
path: root/client/lib
diff options
context:
space:
mode:
authorIgnatzHome <ignatz@maschath.de>2018-05-20 11:15:57 +0200
committerIgnatzHome <ignatz@maschath.de>2018-05-20 11:15:57 +0200
commit1c0c5bde0f39a1f3b7b6a125148f6dbda6803658 (patch)
tree71ce2869a7596f888f7825687b1a0bb689e733d4 /client/lib
parentc3044a6b8b91755042dc0b23abdd7192111ee73f (diff)
downloadwekan-1c0c5bde0f39a1f3b7b6a125148f6dbda6803658.tar.gz
wekan-1c0c5bde0f39a1f3b7b6a125148f6dbda6803658.tar.bz2
wekan-1c0c5bde0f39a1f3b7b6a125148f6dbda6803658.zip
More conditions and logic Operators, Also Brackets.
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/filter.js152
1 files changed, 148 insertions, 4 deletions
diff --git a/client/lib/filter.js b/client/lib/filter.js
index c087ca78..db2dd89f 100644
--- a/client/lib/filter.js
+++ b/client/lib/filter.js
@@ -158,15 +158,61 @@ class AdvancedFilter {
console.log('Parts: ', JSON.stringify(commands));
try {
//let changed = false;
- this._processConditions(commands);
- console.log('Conditions: ', JSON.stringify(commands));
- this._processLogicalOperators(commands);
- console.log('Operator: ', JSON.stringify(commands));
+ 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);
+ console.log('Conditions: ', JSON.stringify(commands));
+ this._processLogicalOperators(commands);
+ console.log('Operator: ', JSON.stringify(commands));
+ }
+
_processConditions(commands)
{
for (let i = 0; i < commands.length; i++)
@@ -188,6 +234,76 @@ class AdvancedFilter {
i--;
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--;
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;
+ }
}
}