From 91b4e77c2ed51adcffa4c7f0c46d8ce7c36e4bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Fri, 6 Nov 2020 00:30:09 +0200 Subject: [PATCH] Needs work filter --- .../app/common/filter/utils/filter-utils.ts | 25 +++++++++++++------ .../project-listing-screen.component.html | 2 +- .../project-overview-screen.component.html | 3 +-- .../project-overview-screen.component.ts | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/apps/red-ui/src/app/common/filter/utils/filter-utils.ts b/apps/red-ui/src/app/common/filter/utils/filter-utils.ts index 868ccddd7..71141a64d 100644 --- a/apps/red-ui/src/app/common/filter/utils/filter-utils.ts +++ b/apps/red-ui/src/app/common/filter/utils/filter-utils.ts @@ -16,18 +16,29 @@ export function handleCheckedValue(filter: FilterModel) { } } -export function checkFilter(entity: any, filters: FilterModel[], validate: Function) { +export function checkFilter( + entity: any, + filters: FilterModel[], + validate: Function, + matchAll: boolean = false +) { const hasChecked = filters.find((f) => f.checked); + if (!hasChecked) { return true; } - let filterMatched = false; + + let filterMatched = matchAll; for (const filter of filters) { - if (filter.checked && validate(entity, filter)) { - filterMatched = true; - break; + if (filter.checked) { + if (matchAll) { + filterMatched = filterMatched && validate(entity, filter); + } else { + filterMatched = filterMatched || validate(entity, filter); + } } } + return filterMatched; } @@ -57,13 +68,13 @@ export const addedDateChecker = (pw: ProjectWrapper, filter: FilterModel) => export function getFilteredEntities( entities: any[], - filters: { values: FilterModel[]; checker: Function }[] + filters: { values: FilterModel[]; checker: Function; matchAll?: boolean }[] ) { const filteredEntities = []; for (const entity of entities) { let add = true; for (const filter of filters) { - add = add && checkFilter(entity, filter.values, filter.checker); + add = add && checkFilter(entity, filter.values, filter.checker, filter.matchAll); } if (add) { filteredEntities.push(entity); diff --git a/apps/red-ui/src/app/screens/project-listing-screen/project-listing-screen.component.html b/apps/red-ui/src/app/screens/project-listing-screen/project-listing-screen.component.html index 1eef5059f..eaff2adb0 100644 --- a/apps/red-ui/src/app/screens/project-listing-screen/project-listing-screen.component.html +++ b/apps/red-ui/src/app/screens/project-listing-screen/project-listing-screen.component.html @@ -62,7 +62,7 @@ {{ 'project-listing.table-header.title' - | translate: { length: appStateService.allProjects?.length || 0 } + | translate: { length: displayedProjects.length || 0 } }} diff --git a/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.html b/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.html index ac2f72043..a3ff90a56 100644 --- a/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.html +++ b/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.html @@ -80,8 +80,7 @@ {{ 'project-overview.table-header.title' - | translate - : { length: appStateService.activeProject?.files.length || 0 } + | translate: { length: displayedFiles.length || 0 } }} diff --git a/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts b/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts index 7c83dca71..5be518bcc 100644 --- a/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts +++ b/apps/red-ui/src/app/screens/project-overview-screen/project-overview-screen.component.ts @@ -333,7 +333,7 @@ export class ProjectOverviewScreenComponent implements OnInit, OnDestroy { { values: this.statusFilters, checker: keyChecker('status') }, { values: this.peopleFilters, checker: keyChecker('currentReviewer') }, { values: this.addedDateFilters, checker: fileAddedFilterChecker }, - { values: this.needsWorkFilters, checker: annotationFilterChecker } + { values: this.needsWorkFilters, checker: annotationFilterChecker, matchAll: true } ]; this.displayedFiles = getFilteredEntities( this.appStateService.activeProject.files,