#407 Add collection filtering by field and value

This commit is contained in:
Luis Correia
2017-05-05 17:25:59 +01:00
committed by David Calavera
parent 6d5ff45e66
commit 544cb786ee
3 changed files with 38 additions and 5 deletions

View File

@ -84,6 +84,7 @@ class Backend {
listEntries(collection) {
const listMethod = this.implementation[selectListMethod(collection)];
const extension = selectFolderEntryExtension(collection);
const collectionFilter = collection.get('filter');
return listMethod.call(this.implementation, collection, extension)
.then(loadedEntries => (
loadedEntries.map(loadedEntry => createEntry(
@ -97,6 +98,14 @@ class Backend {
{
entries: entries.map(this.entryWithFormat(collection)),
}
))
// If this collection has a "filter" property, filter entries accordingly
.then(loadedCollection => (
{
entries: loadedCollection.entries.filter(
entry => (!collectionFilter || entry.data[collectionFilter.get('field')] === collectionFilter.get('value'))
),
}
));
}