Implement the job list filtering based on facet selection

This commit is contained in:
Michael Lange 2019-01-17 11:11:17 -08:00 committed by Preetha Appan
parent 8015605041
commit 09ae9fbfa3
No known key found for this signature in database
GPG key ID: 9F7C19990A50EAFC

View file

@ -110,6 +110,40 @@ export default Controller.extend(Sortable, Searchable, {
.filter(job => !job.get('parent.content'));
}),
filteredJobs: computed(
'visibleJobs.[]',
'facetSelectionType',
'facetSelectionStatus',
'facetSelectionDatacenter',
'facetSelectionPrefix',
function() {
const {
facetSelectionType: types,
facetSelectionStatus: statuses,
facetSelectionDatacenter: datacenters,
facetSelectionPrefix: prefixes,
} = this.getProperties(
'facetSelectionType',
'facetSelectionStatus',
'facetSelectionDatacenter',
'facetSelectionPrefix'
);
// A job must match ALL filter facets, but it can match ANY selection within a facet
// Always return early to prevent unnecessary facet predicates.
return this.get('visibleJobs').filter(job => {
if (types.length && !types.includes(job.get('displayType'))) return false;
if (statuses.length && !statuses.includes(job.get('status'))) return false;
if (datacenters.length && !job.get('datacenters').find(dc => datacenters.includes(dc)))
return false;
const name = job.get('name');
if (prefixes.length && !prefixes.find(prefix => name.startsWith(prefix))) return false;
return true;
});
}
),
listToSort: alias('filteredJobs'),
listToSearch: alias('listSorted'),
sortedJobs: alias('listSearched'),