diff options
author | Lauri Ojansivu <x@xet7.org> | 2016-11-15 23:46:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-15 23:46:58 +0200 |
commit | fa6267cf44c8648a828072dcf7c2138255f97bc7 (patch) | |
tree | d9060484993f469e702a21e9959614e6b62e6042 /client/lib | |
parent | 0733fd64eee199633092702bb6bd330a38352f19 (diff) | |
parent | 4dc0ec07b8560d0814ed5cb72b2cac93722bb93c (diff) | |
download | wekan-fa6267cf44c8648a828072dcf7c2138255f97bc7.tar.gz wekan-fa6267cf44c8648a828072dcf7c2138255f97bc7.tar.bz2 wekan-fa6267cf44c8648a828072dcf7c2138255f97bc7.zip |
Merge pull request #6 from mario-orlicky/filter-by-empty
Filter by empty
Diffstat (limited to 'client/lib')
-rw-r--r-- | client/lib/filter.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/client/lib/filter.js b/client/lib/filter.js index 74305284..afa992ab 100644 --- a/client/lib/filter.js +++ b/client/lib/filter.js @@ -63,6 +63,17 @@ class SetFilter { this._dep.depend(); return { $in: this._selectedElements }; } + + _getEmptySelector() { + this._dep.depend(); + let includeEmpty = false + this._selectedElements.forEach((el) => { + if (el == undefined) { + includeEmpty = true; + } + }); + return includeEmpty ? { $eq: [] } : null; + } } // The global Filter object. @@ -95,16 +106,26 @@ Filter = { return {}; const filterSelector = {}; + const emptySelector = {}; + let includeEmptySelectors = false; this._fields.forEach((fieldName) => { const filter = this[fieldName]; - if (filter._isActive()) + if (filter._isActive()) { filterSelector[fieldName] = filter._getMongoSelector(); + emptySelector[fieldName] = filter._getEmptySelector(); + if (emptySelector[fieldName] != null) { + includeEmptySelectors = true; + } + } }); const exceptionsSelector = {_id: {$in: this._exceptions}}; this._exceptionsDep.depend(); - return {$or: [filterSelector, exceptionsSelector]}; + if (includeEmptySelectors) + return {$or: [filterSelector, exceptionsSelector, emptySelector]}; + else + return {$or: [filterSelector, exceptionsSelector]}; }, mongoSelector(additionalSelector) { |