Filtering logic by empty labels/members

This commit is contained in:
Mario Orlicky 2016-11-13 20:38:14 +01:00
parent 300b40ed87
commit 5a23c962d2

View file

@ -61,7 +61,18 @@ class SetFilter {
_getMongoSelector() { _getMongoSelector() {
this._dep.depend(); this._dep.depend();
return { $in: this._selectedElements }; return { $in: this._selectedElements }
}
_getEmptySelector() {
this._dep.depend();
let includeEmpty = false
this._selectedElements.forEach((el) => {
if (el == undefined) {
includeEmpty = true;
}
});
return includeEmpty ? { $eq: [] } : null;
} }
} }
@ -95,16 +106,26 @@ Filter = {
return {}; return {};
const filterSelector = {}; const filterSelector = {};
const emptySelector = {};
let includeEmptySelectors = false;
this._fields.forEach((fieldName) => { this._fields.forEach((fieldName) => {
const filter = this[fieldName]; const filter = this[fieldName];
if (filter._isActive()) if (filter._isActive()) {
filterSelector[fieldName] = filter._getMongoSelector(); filterSelector[fieldName] = filter._getMongoSelector();
emptySelector[fieldName] = filter._getEmptySelector();
if (emptySelector[fieldName] != null) {
includeEmptySelectors = true;
}
}
}); });
const exceptionsSelector = {_id: {$in: this._exceptions}}; const exceptionsSelector = {_id: {$in: this._exceptions}};
this._exceptionsDep.depend(); this._exceptionsDep.depend();
return {$or: [filterSelector, exceptionsSelector]}; if (includeEmptySelectors)
return {$or: [filterSelector, exceptionsSelector, emptySelector]};
else
return {$or: [filterSelector, exceptionsSelector]};
}, },
mongoSelector(additionalSelector) { mongoSelector(additionalSelector) {