From b00bd04baaa7cdad9b2162d13bff78d97d23f34a Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 18:38:48 +0200 Subject: first test for Advanced Filter --- client/components/sidebar/sidebarFilters.jade | 2 + client/components/sidebar/sidebarFilters.js | 5 ++ client/lib/filter.js | 113 +++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/client/components/sidebar/sidebarFilters.jade b/client/components/sidebar/sidebarFilters.jade index 5f9fcf72..00d8c87b 100644 --- a/client/components/sidebar/sidebarFilters.jade +++ b/client/components/sidebar/sidebarFilters.jade @@ -55,6 +55,8 @@ template(name="filterSidebar") {{ name }} if Filter.customFields.isSelected _id i.fa.fa-check + hr + input.js-field-advanced-filter(type="text") if Filter.isActive hr a.sidebar-btn.js-clear-all diff --git a/client/components/sidebar/sidebarFilters.js b/client/components/sidebar/sidebarFilters.js index ba2633de..6fb3f500 100644 --- a/client/components/sidebar/sidebarFilters.js +++ b/client/components/sidebar/sidebarFilters.js @@ -16,6 +16,11 @@ BlazeComponent.extendComponent({ Filter.customFields.toggle(this.currentData()._id); Filter.resetExceptions(); }, + 'input .js-field-advanced-filter'(evt) { + evt.preventDefault(); + Filter.advanced.set(this.find('.js-field-advanced-filter').value.trim()); + Filter.resetExceptions(); + }, 'click .js-clear-all'(evt) { evt.preventDefault(); Filter.reset(); diff --git a/client/lib/filter.js b/client/lib/filter.js index f68c9711..8b7f7574 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -79,6 +79,110 @@ class SetFilter { } } + +// Advanced filter forms a MongoSelector from a users String. +// Build by: Ignatz 19.05.2018 (github feuerball11) +class AdvancedFilter { + constructor() { + this._dep = new Tracker.Dependency(); + this._filter = ''; + } + + set(str) + { + this._filter = str; + this._dep.changed(); + } + + reset() { + this._filter = ''; + this._dep.changed(); + } + + _isActive() { + this._dep.depend(); + return this._filter !== ''; + } + + _filterToCommands(){ + const commands = []; + let current = ''; + let string = false; + let ignore = false; + for (let i = 0; i < this._filter.length; i++) + { + const char = this._filter.charAt(i); + if (ignore) + { + ignore = false; + continue; + } + if (char === '\'') + { + string = true; + continue; + } + if (char === '\\') + { + ignore = true; + continue; + } + if (char === ' ' && !string) + { + commands.push({'cmd':current, string}); + string = false; + current = ''; + continue; + } + current.push(char); + } + if (current !== '') + { + commands.push(current); + } + return commands; + } + + _arrayToSelector(commands) + { + try { + //let changed = false; + for (let i = 0; i < commands.length; i++) + { + if (!commands[i].string && commands[i].cmd) + { + switch (commands[i].cmd) + { + case '=': + case '==': + case '===': + { + const field = commands[i-1]; + const str = commands[i+1]; + commands[i] = {}[field]=str; + commands.splice(i-1, 1); + commands.splice(i, 1); + //changed = true; + i--; + break; + } + + } + } + } + } + catch (e){return { $in: [] };} + return commands; + } + + _getMongoSelector() { + this._dep.depend(); + const commands = this._filterToCommands(); + return this._arrayToSelector(commands); + } + +} + // The global Filter object. // XXX It would be possible to re-write this object more elegantly, and removing // the need to provide a list of `_fields`. We also should move methods into the @@ -90,6 +194,7 @@ Filter = { labelIds: new SetFilter(), members: new SetFilter(), customFields: new SetFilter('_id'), + advanced: new AdvancedFilter(), _fields: ['labelIds', 'members', 'customFields'], @@ -134,9 +239,13 @@ Filter = { this._exceptionsDep.depend(); if (includeEmptySelectors) - return {$or: [filterSelector, exceptionsSelector, emptySelector]}; + return { + $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector(), emptySelector], + }; else - return {$or: [filterSelector, exceptionsSelector]}; + return { + $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector()], + }; }, mongoSelector(additionalSelector) { -- cgit v1.2.3-1-g7c22 From 1854f5c0614637cb86616eced6af3a6dcc4d9fc8 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 19:00:20 +0200 Subject: correcting push not part of string --- client/lib/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 8b7f7574..81604705 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -134,7 +134,7 @@ class AdvancedFilter { current = ''; continue; } - current.push(char); + current += char; } if (current !== '') { -- cgit v1.2.3-1-g7c22 From 01cd2df3692a24b5789ee83b46137f5cdee2da58 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 19:16:10 +0200 Subject: correcting return type from constructed --- client/lib/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 81604705..f056b2e8 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -172,7 +172,7 @@ class AdvancedFilter { } } catch (e){return { $in: [] };} - return commands; + return {$or: commands}; } _getMongoSelector() { -- cgit v1.2.3-1-g7c22 From cd749bc38592d82d8c1dcfd5b0ad7c48909a576b Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 19:59:10 +0200 Subject: console log for debug --- client/lib/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index f056b2e8..eac23e47 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -237,7 +237,7 @@ Filter = { const exceptionsSelector = {_id: {$in: this._exceptions}}; this._exceptionsDep.depend(); - + console.log(this.advanced._getMongoSelector()); if (includeEmptySelectors) return { $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector(), emptySelector], -- cgit v1.2.3-1-g7c22 From 1d58e401338985b2c2dfa071d53c83b2c62e368d Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 20:17:52 +0200 Subject: this took me way too long --- client/lib/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index eac23e47..b971e4e0 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -157,8 +157,8 @@ class AdvancedFilter { case '==': case '===': { - const field = commands[i-1]; - const str = commands[i+1]; + const field = commands[i-1].cmd; + const str = commands[i+1].cmd; commands[i] = {}[field]=str; commands.splice(i-1, 1); commands.splice(i, 1); -- cgit v1.2.3-1-g7c22 From b9ead144fb88eb8e02c1d9ea9144873ce926ed96 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 20:33:49 +0200 Subject: javascript is confusing sometimes --- client/lib/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index b971e4e0..4a6dd2f3 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -159,7 +159,7 @@ class AdvancedFilter { { const field = commands[i-1].cmd; const str = commands[i+1].cmd; - commands[i] = {}[field]=str; + commands[i] = {[field]:str}; commands.splice(i-1, 1); commands.splice(i, 1); //changed = true; -- cgit v1.2.3-1-g7c22 From ba12b53e49852e92c6ed77df07f7576a9ed2b02c Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 20:53:25 +0200 Subject: correct way, wrong idea --- .eslintrc.json | 2 +- client/lib/filter.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 255e00ba..06d3f001 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -32,7 +32,7 @@ "comma-spacing": 2, "comma-style": 2, "eol-last": 2, - "linebreak-style": [2, "unix"], + "linebreak-style": [2, "windows"], "new-parens": 2, "no-lonely-if": 2, "no-multiple-empty-lines": 2, diff --git a/client/lib/filter.js b/client/lib/filter.js index 4a6dd2f3..749527fb 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -143,6 +143,11 @@ class AdvancedFilter { return commands; } + _fieldNameToId(name) + { + CustomFields.find({name})._id; + } + _arrayToSelector(commands) { try { @@ -159,7 +164,7 @@ class AdvancedFilter { { const field = commands[i-1].cmd; const str = commands[i+1].cmd; - commands[i] = {[field]:str}; + commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value':str}; commands.splice(i-1, 1); commands.splice(i, 1); //changed = true; @@ -207,7 +212,7 @@ Filter = { isActive() { return _.any(this._fields, (fieldName) => { return this[fieldName]._isActive(); - }); + }) || this.advanced._isActive(); }, _getMongoSelector() { -- cgit v1.2.3-1-g7c22 From 32058e8018b5f6e6829f6abceeec79c18f91c3ad Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 20:53:59 +0200 Subject: damm i got the eslint file again.... --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 06d3f001..255e00ba 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -32,7 +32,7 @@ "comma-spacing": 2, "comma-style": 2, "eol-last": 2, - "linebreak-style": [2, "windows"], + "linebreak-style": [2, "unix"], "new-parens": 2, "no-lonely-if": 2, "no-multiple-empty-lines": 2, -- cgit v1.2.3-1-g7c22 From 0bdc7efc8b2e9b51298d69b30e9b93d20966de40 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 21:06:53 +0200 Subject: another debug line --- client/lib/filter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/client/lib/filter.js b/client/lib/filter.js index 749527fb..70b6894b 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -150,6 +150,7 @@ class AdvancedFilter { _arrayToSelector(commands) { + console.log(commands); try { //let changed = false; for (let i = 0; i < commands.length; i++) -- cgit v1.2.3-1-g7c22 From 422424d21c2f286478e5ad3f104ce966301adda1 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 21:19:10 +0200 Subject: fixing string detection in advanced filter --- client/lib/filter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 70b6894b..bab04d48 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -119,7 +119,7 @@ class AdvancedFilter { } if (char === '\'') { - string = true; + string = !string; continue; } if (char === '\\') @@ -130,7 +130,6 @@ class AdvancedFilter { if (char === ' ' && !string) { commands.push({'cmd':current, string}); - string = false; current = ''; continue; } -- cgit v1.2.3-1-g7c22 From 811ccf0f102ce4b82efa2136a387e4c9e6b94456 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 21:31:43 +0200 Subject: i was constructing the wrong and the whole time.. *sigh* --- client/lib/filter.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index bab04d48..854ff446 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -108,6 +108,7 @@ class AdvancedFilter { const commands = []; let current = ''; let string = false; + let wasString = false; let ignore = false; for (let i = 0; i < this._filter.length; i++) { @@ -120,6 +121,7 @@ class AdvancedFilter { if (char === '\'') { string = !string; + if (string) wasString = true; continue; } if (char === '\\') @@ -129,7 +131,8 @@ class AdvancedFilter { } if (char === ' ' && !string) { - commands.push({'cmd':current, string}); + commands.push({'cmd':current, 'string':wasString}); + wasString = false; current = ''; continue; } @@ -137,7 +140,7 @@ class AdvancedFilter { } if (current !== '') { - commands.push(current); + commands.push({'cmd':current, 'string':wasString}); } return commands; } -- cgit v1.2.3-1-g7c22 From 17fcfd36973125bec369b5e74d9db092e0d8b7e0 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 21:42:11 +0200 Subject: correcting _fieldNameToId(field); --- client/lib/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 854ff446..2079d99a 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -145,9 +145,9 @@ class AdvancedFilter { return commands; } - _fieldNameToId(name) + _fieldNameToId(field) { - CustomFields.find({name})._id; + CustomFields.find({'name':field})[0]._id; } _arrayToSelector(commands) -- cgit v1.2.3-1-g7c22 From 382b14ea275deb94c0f2f8d5564e050b034aca8b Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 21:54:20 +0200 Subject: debugging _fieldNameToId --- client/lib/filter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 2079d99a..970aedea 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -147,7 +147,10 @@ class AdvancedFilter { _fieldNameToId(field) { - CustomFields.find({'name':field})[0]._id; + console.log("searching: "+field); + const found = CustomFields.find({'name':field}); + console.log(found); + return found._id; } _arrayToSelector(commands) -- cgit v1.2.3-1-g7c22 From 2bf13a50c4ad03b39b52257dd21e0be3d21dae8a Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 22:17:00 +0200 Subject: find to findOne --- client/lib/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 970aedea..3a174af6 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -148,7 +148,7 @@ class AdvancedFilter { _fieldNameToId(field) { console.log("searching: "+field); - const found = CustomFields.find({'name':field}); + const found = CustomFields.findOne({'name':field}); console.log(found); return found._id; } -- cgit v1.2.3-1-g7c22 From 4ff8989e8fe6aab9f67f0471d0986823293ddc9d Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sat, 19 May 2018 22:29:12 +0200 Subject: More Debugging --- client/lib/filter.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 3a174af6..9f42068b 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -248,7 +248,10 @@ Filter = { const exceptionsSelector = {_id: {$in: this._exceptions}}; this._exceptionsDep.depend(); - console.log(this.advanced._getMongoSelector()); + console.log("Final Filter:"); + console.log({ + $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector()], + }); if (includeEmptySelectors) return { $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector(), emptySelector], -- cgit v1.2.3-1-g7c22 From 39974c953247190fe373a583830d1ec3bc6899f7 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 09:33:51 +0200 Subject: rewrite Filter._getMongoSelecto to not include Empty Filter. --- client/lib/filter.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 9f42068b..790e4f49 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -248,18 +248,16 @@ Filter = { const exceptionsSelector = {_id: {$in: this._exceptions}}; this._exceptionsDep.depend(); - console.log("Final Filter:"); - console.log({ - $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector()], - }); - if (includeEmptySelectors) - return { - $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector(), emptySelector], - }; - else - return { - $or: [filterSelector, exceptionsSelector, this.advanced._getMongoSelector()], - }; + + const selectors = [exceptionsSelector]; + + if (_.any(this._fields, (fieldName) => { + return this[fieldName]._isActive(); + })) selectors.push(filterSelector); + if (includeEmptySelectors) selectors.push(emptySelector); + if (this.advanced._isActive()) selectors.push(this.advanced._getMongoSelector()); + + return {$or: selectors}; }, mongoSelector(additionalSelector) { -- cgit v1.2.3-1-g7c22 From 9ac1164440b70de6480d55a0814198aad5e6d779 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 09:47:20 +0200 Subject: Testing 'or' condition for advanced Filter --- client/lib/filter.js | 79 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 790e4f49..84b10648 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -147,7 +147,7 @@ class AdvancedFilter { _fieldNameToId(field) { - console.log("searching: "+field); + console.log(`searching: ${field}`); const found = CustomFields.findOne({'name':field}); console.log(found); return found._id; @@ -158,32 +158,67 @@ class AdvancedFilter { console.log(commands); try { //let changed = false; - for (let i = 0; i < commands.length; i++) + this._processConditions(commands); + this._processLogicalOperators(commands); + } + catch (e){return { $in: [] };} + return {$or: commands}; + } + + _processConditions(commands) + { + for (let i = 0; i < commands.length; i++) + { + if (!commands[i].string && commands[i].cmd) { - if (!commands[i].string && commands[i].cmd) + switch (commands[i].cmd) + { + case '=': + case '==': + case '===': { - switch (commands[i].cmd) - { - case '=': - case '==': - case '===': - { - const field = commands[i-1].cmd; - const str = commands[i+1].cmd; - commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value':str}; - commands.splice(i-1, 1); - commands.splice(i, 1); - //changed = true; - i--; - break; - } - - } + const field = commands[i-1].cmd; + const str = commands[i+1].cmd; + commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value':str}; + commands.splice(i-1, 1); + commands.splice(i, 1); + //changed = true; + i--; + break; + } + + } + } + } + } + + _processLogicalOperators(commands) + { + for (let i = 0; i < commands.length; i++) + { + if (!commands[i].string && commands[i].cmd) + { + switch (commands[i].cmd) + { + case 'or': + case 'Or': + case 'OR': + case '|': + case '||': + { + const op1 = commands[i-1].cmd; + const op2 = commands[i+1].cmd; + commands[i] = {$or: [op1, op2]}; + commands.splice(i-1, 1); + commands.splice(i, 1); + //changed = true; + i--; + break; + } + } } } - catch (e){return { $in: [] };} - return {$or: commands}; } _getMongoSelector() { -- cgit v1.2.3-1-g7c22 From eb859dac3a2e69fdc608c76af53881df0abb2ed5 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 09:57:40 +0200 Subject: More Debugging Logs --- client/lib/filter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 84b10648..5aae1b36 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -155,11 +155,13 @@ class AdvancedFilter { _arrayToSelector(commands) { - console.log(commands); + console.log('Parts: ', commands); try { //let changed = false; this._processConditions(commands); + console.log('Conditions: ', commands); this._processLogicalOperators(commands); + console.log('Operator: ', commands); } catch (e){return { $in: [] };} return {$or: commands}; -- cgit v1.2.3-1-g7c22 From 778a29855f3beac7b3915c76ced5f149c5fe306e Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 10:11:46 +0200 Subject: stringify console.logs becouse of asynchrone nature from chromes interpretation... WAT --- client/lib/filter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 5aae1b36..04edaa38 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -155,13 +155,13 @@ class AdvancedFilter { _arrayToSelector(commands) { - console.log('Parts: ', commands); + console.log('Parts: ', JSON.stringify(commands)); try { //let changed = false; this._processConditions(commands); - console.log('Conditions: ', commands); + console.log('Conditions: ', JSON.stringify(commands)); this._processLogicalOperators(commands); - console.log('Operator: ', commands); + console.log('Operator: ', JSON.stringify(commands)); } catch (e){return { $in: [] };} return {$or: commands}; -- cgit v1.2.3-1-g7c22 From c3044a6b8b91755042dc0b23abdd7192111ee73f Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 10:20:29 +0200 Subject: removing .cmd in oricessing Operators --- client/lib/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 04edaa38..c087ca78 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -208,8 +208,8 @@ class AdvancedFilter { case '|': case '||': { - const op1 = commands[i-1].cmd; - const op2 = commands[i+1].cmd; + const op1 = commands[i-1]; + const op2 = commands[i+1]; commands[i] = {$or: [op1, op2]}; commands.splice(i-1, 1); commands.splice(i, 1); -- cgit v1.2.3-1-g7c22 From 1c0c5bde0f39a1f3b7b6a125148f6dbda6803658 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 11:15:57 +0200 Subject: More conditions and logic Operators, Also Brackets. --- client/lib/filter.js | 152 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file 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; + } } } -- cgit v1.2.3-1-g7c22 From ecbb8ef07100f7af2387f8fb97712703eff32a06 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 11:27:22 +0200 Subject: correcting strings not part of subcommand --- client/lib/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index db2dd89f..60c2bc84 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -172,7 +172,7 @@ class AdvancedFilter { let start = -1; for (let i = 0; i < commands.length; i++) { - if (!commands[i].string && commands[i].cmd) + if (commands[i].cmd) { switch (commands[i].cmd) { -- cgit v1.2.3-1-g7c22 From bfac626fa46a9ecb525ea22bda14b66328e37724 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 11:40:32 +0200 Subject: showOnCard test implementation --- client/components/cards/minicard.jade | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index 9fa4dd57..04d57f15 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -24,6 +24,15 @@ template(name="minicard") .minicard-members.js-minicard-members each members +userAvatar(userId=this) + + .card-details-items + each customFieldsWD + if definition.showOnCard + .card-details-item.card-details-item-customfield + h3.card-details-item-title + = definition.name + +cardCustomField + .badges if comments.count .badge(title="{{_ 'card-comments-title' comments.count }}") -- cgit v1.2.3-1-g7c22 From f910b66ef27c53767dc123880c3bbec00e8daabd Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 11:49:49 +0200 Subject: correcting indent in jade --- client/components/cards/minicard.jade | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index 04d57f15..f89e66d4 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -28,10 +28,10 @@ template(name="minicard") .card-details-items each customFieldsWD if definition.showOnCard - .card-details-item.card-details-item-customfield - h3.card-details-item-title - = definition.name - +cardCustomField + .card-details-item.card-details-item-customfield + h3.card-details-item-title + = definition.name + +cardCustomField .badges if comments.count -- cgit v1.2.3-1-g7c22 From 43fe9ef34ac490ad6c141d2259ecc431dc47a81b Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 12:11:58 +0200 Subject: style correction for custom fields on minicard --- client/components/cards/minicard.jade | 9 +++++---- client/components/cards/minicard.styl | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index f89e66d4..fd3fb7b0 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -25,13 +25,14 @@ template(name="minicard") each members +userAvatar(userId=this) - .card-details-items + .minicard-custom-fields each customFieldsWD if definition.showOnCard - .card-details-item.card-details-item-customfield - h3.card-details-item-title + .minicard-custom-field + h3.minicard-custom-field-item = definition.name - +cardCustomField + .minicard-custom-field-item + +cardCustomField .badges if comments.count diff --git a/client/components/cards/minicard.styl b/client/components/cards/minicard.styl index d59f1f63..38f829d0 100644 --- a/client/components/cards/minicard.styl +++ b/client/components/cards/minicard.styl @@ -77,6 +77,13 @@ height: @width border-radius: 2px margin-left: 3px + .minicard-custom-fields + display:block; + .minicard-custom-field + display:flex; + .minicard-custom-field-item + max-width:50%; + flex-grow:1; .minicard-title p:last-child margin-bottom: 0 -- cgit v1.2.3-1-g7c22 From d9e291635af2827e8bb30e99780e191e714b397b Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 12:17:25 +0200 Subject: customFields bevore mebers on minicard --- client/components/cards/minicard.jade | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index fd3fb7b0..bd12a111 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -20,11 +20,6 @@ template(name="minicard") .date +cardSpentTime - if members - .minicard-members.js-minicard-members - each members - +userAvatar(userId=this) - .minicard-custom-fields each customFieldsWD if definition.showOnCard @@ -34,6 +29,11 @@ template(name="minicard") .minicard-custom-field-item +cardCustomField + if members + .minicard-members.js-minicard-members + each members + +userAvatar(userId=this) + .badges if comments.count .badge(title="{{_ 'card-comments-title' comments.count }}") -- cgit v1.2.3-1-g7c22 From 59046d448ffc4c24f94043346d930b67dfd9e138 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 12:24:07 +0200 Subject: making custom-fields uneditable on minicard --- client/components/cards/minicard.jade | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/components/cards/minicard.jade b/client/components/cards/minicard.jade index bd12a111..aa0708dd 100644 --- a/client/components/cards/minicard.jade +++ b/client/components/cards/minicard.jade @@ -24,10 +24,10 @@ template(name="minicard") each customFieldsWD if definition.showOnCard .minicard-custom-field - h3.minicard-custom-field-item + .minicard-custom-field-item = definition.name .minicard-custom-field-item - +cardCustomField + = value if members .minicard-members.js-minicard-members -- cgit v1.2.3-1-g7c22 From 6d9ac3ae488d66c4f2ce116f0861ad59faa49de2 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 13:19:18 +0200 Subject: testing theorie: subcommands are allways 1 entry --- client/lib/filter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 60c2bc84..73a0da99 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -205,7 +205,11 @@ class AdvancedFilter { if (start !== -1) { this._processSubCommands(subcommands); - commands.splice(start, 0, subcommands); + console.log ('subcommands: ', subcommands.length); + if (subcommands.length === 1) + commands.splice(start, 0, subcommands[0]); + else + commands.splice(start, 0, subcommands); } this._processConditions(commands); console.log('Conditions: ', JSON.stringify(commands)); -- cgit v1.2.3-1-g7c22 From 256ca129f0301765ce1b2522c9e4aef68eda9e8c Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 14:03:48 +0200 Subject: Correcting not Filter --- client/lib/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/filter.js b/client/lib/filter.js index 73a0da99..18d95ebd 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -243,7 +243,7 @@ class AdvancedFilter { { const field = commands[i-1].cmd; const str = commands[i+1].cmd; - commands[i] = {$not: {'customFields._id':this._fieldNameToId(field), 'customFields.value':str}}; + commands[i] = {'customFields._id':this._fieldNameToId(field), 'customFields.value': { $not: str }}; commands.splice(i-1, 1); commands.splice(i, 1); //changed = true; -- cgit v1.2.3-1-g7c22 From dd7c9997a937fde0c598188884db6690e77bfb11 Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 14:53:00 +0200 Subject: Removing Debug Lines, correcting behavior, caching las valide filter, and adding description --- client/components/sidebar/sidebarFilters.jade | 2 ++ client/components/sidebar/sidebarFilters.js | 2 +- client/lib/filter.js | 13 +++++-------- i18n/en.i18n.json | 2 ++ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client/components/sidebar/sidebarFilters.jade b/client/components/sidebar/sidebarFilters.jade index 00d8c87b..c0696391 100644 --- a/client/components/sidebar/sidebarFilters.jade +++ b/client/components/sidebar/sidebarFilters.jade @@ -56,7 +56,9 @@ template(name="filterSidebar") if Filter.customFields.isSelected _id i.fa.fa-check hr + span {{_ 'advanced-filter-label}} input.js-field-advanced-filter(type="text") + span {{_ 'advanced-filter-description'}} if Filter.isActive hr a.sidebar-btn.js-clear-all diff --git a/client/components/sidebar/sidebarFilters.js b/client/components/sidebar/sidebarFilters.js index 6fb3f500..fd8229e4 100644 --- a/client/components/sidebar/sidebarFilters.js +++ b/client/components/sidebar/sidebarFilters.js @@ -16,7 +16,7 @@ BlazeComponent.extendComponent({ Filter.customFields.toggle(this.currentData()._id); Filter.resetExceptions(); }, - 'input .js-field-advanced-filter'(evt) { + 'change .js-field-advanced-filter'(evt) { evt.preventDefault(); Filter.advanced.set(this.find('.js-field-advanced-filter').value.trim()); Filter.resetExceptions(); diff --git a/client/lib/filter.js b/client/lib/filter.js index 18d95ebd..c5f8fe7e 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -86,6 +86,7 @@ class AdvancedFilter { constructor() { this._dep = new Tracker.Dependency(); this._filter = ''; + this._lastValide={}; } set(str) @@ -96,6 +97,7 @@ class AdvancedFilter { reset() { this._filter = ''; + this._lastValide={}; this._dep.changed(); } @@ -147,26 +149,23 @@ class AdvancedFilter { _fieldNameToId(field) { - console.log(`searching: ${field}`); const found = CustomFields.findOne({'name':field}); - console.log(found); return found._id; } _arrayToSelector(commands) { - console.log('Parts: ', JSON.stringify(commands)); try { //let changed = false; this._processSubCommands(commands); } - catch (e){return { $in: [] };} + catch (e){return this._lastValide;} + this._lastValide = {$or: commands}; return {$or: commands}; } _processSubCommands(commands) { - console.log('SubCommands: ', JSON.stringify(commands)); const subcommands = []; let level = 0; let start = -1; @@ -205,16 +204,13 @@ class AdvancedFilter { if (start !== -1) { this._processSubCommands(subcommands); - console.log ('subcommands: ', subcommands.length); if (subcommands.length === 1) commands.splice(start, 0, subcommands[0]); else 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) @@ -458,6 +454,7 @@ Filter = { const filter = this[fieldName]; filter.reset(); }); + this.advanced.reset(); this.resetExceptions(); }, diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index e2d6ddce..f44dba23 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -246,6 +246,8 @@ "filter-on": "Filter is on", "filter-on-desc": "You are filtering cards on this board. Click here to edit filter.", "filter-to-selection": "Filter to selection", + "advanced-filter-label": "Advanced Filter", + "advanced-filter-description": "Advanced Filter allows to write a string containing following operators: == != <= >= && || ( ) A Space is used as seperator between the operators. You can filter for all custom fields by simply typing there names and values. For example: Field1 == Value1 Note: If fields or values contains spaces, you need to encapsulate them into single quetes. For example: 'Field 1' == 'Value 1' Also you can combine multiple Conditions. For Example: F1 == V1 || F1 = V2 Normaly all Operators are interpreted from left to right. You can change the order of that by placing brakets. For Example: F1 == V1 and ( F2 == V2 || F2 == V3 )", "fullname": "Full Name", "header-logo-title": "Go back to your boards page.", "hide-system-messages": "Hide system messages", -- cgit v1.2.3-1-g7c22 From 2119a6568b36591f84df29e0305fda9c12ec207a Mon Sep 17 00:00:00 2001 From: IgnatzHome Date: Sun, 20 May 2018 14:59:32 +0200 Subject: forgot a ' --- client/components/sidebar/sidebarFilters.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/sidebar/sidebarFilters.jade b/client/components/sidebar/sidebarFilters.jade index c0696391..514870b8 100644 --- a/client/components/sidebar/sidebarFilters.jade +++ b/client/components/sidebar/sidebarFilters.jade @@ -56,7 +56,7 @@ template(name="filterSidebar") if Filter.customFields.isSelected _id i.fa.fa-check hr - span {{_ 'advanced-filter-label}} + span {{_ 'advanced-filter-label'}} input.js-field-advanced-filter(type="text") span {{_ 'advanced-filter-description'}} if Filter.isActive -- cgit v1.2.3-1-g7c22