diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-06-14 23:25:39 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-06-14 23:25:39 +0300 |
commit | 0034d2d3bedc5518513b89ebdb35d110e14c1e7e (patch) | |
tree | 1916de1258ddf2d224f9519b1b23f9220b671e93 /client/lib/filter.js | |
parent | 1214af04a9bdaad4390d6f3eb157f5dd430ab48a (diff) | |
parent | 880dcab0b15388eae10e7d17353c7fb5b4f190a9 (diff) | |
download | wekan-0034d2d3bedc5518513b89ebdb35d110e14c1e7e.tar.gz wekan-0034d2d3bedc5518513b89ebdb35d110e14c1e7e.tar.bz2 wekan-0034d2d3bedc5518513b89ebdb35d110e14c1e7e.zip |
Merge branch 'feuerball11-feature-custom-fields' into devel
Diffstat (limited to 'client/lib/filter.js')
-rw-r--r-- | client/lib/filter.js | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/client/lib/filter.js b/client/lib/filter.js index e3658e1e..a4e58692 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -109,12 +109,20 @@ class AdvancedFilter { const commands = []; let current = ''; let string = false; + let regex = false; let wasString = false; let ignore = false; for (let i = 0; i < this._filter.length; i++) { const char = this._filter.charAt(i); if (ignore) { ignore = false; + current += char; + continue; + } + if (char === '/'){ + string = !string; + if (string) regex = true; + current += char; continue; } if (char === '\'') { @@ -122,12 +130,12 @@ class AdvancedFilter { if (string) wasString = true; continue; } - if (char === '\\') { + if (char === '\\' && !string) { ignore = true; continue; } if (char === ' ' && !string) { - commands.push({ 'cmd': current, 'string': wasString }); + commands.push({ 'cmd': current, 'string': wasString, regex}); wasString = false; current = ''; continue; @@ -135,7 +143,7 @@ class AdvancedFilter { current += char; } if (current !== '') { - commands.push({ 'cmd': current, 'string': wasString }); + commands.push({ 'cmd': current, 'string': wasString, regex}); } return commands; } @@ -224,7 +232,20 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': {$in: [this._fieldValueToId(field, str), parseInt(str, 10)]} }; + if (commands[i + 1].regex) + { + const match = str.match(new RegExp('^/(.*?)/([gimy]*)$')); + let regex = null; + if (match.length > 2) + regex = new RegExp(match[1], match[2]); + else + regex = new RegExp(match[1]); + commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': regex }; + } + else + { + commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': {$in: [this._fieldValueToId(field, str), parseInt(str, 10)]} }; + } commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; @@ -236,7 +257,20 @@ class AdvancedFilter { { const field = commands[i - 1].cmd; const str = commands[i + 1].cmd; - commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $not: {$in: [this._fieldValueToId(field, str), parseInt(str, 10)]} } }; + if (commands[i + 1].regex) + { + const match = str.match(new RegExp('^/(.*?)/([gimy]*)$')); + let regex = null; + if (match.length > 2) + regex = new RegExp(match[1], match[2]); + else + regex = new RegExp(match[1]); + commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $not: regex } }; + } + else + { + commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $not: {$in: [this._fieldValueToId(field, str), parseInt(str, 10)]} } }; + } commands.splice(i - 1, 1); commands.splice(i, 1); //changed = true; |