From 57d1b2c3d254b6861c016e071b8ef51c796f3f71 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Tue, 29 Jun 2021 23:55:40 +0300 Subject: [PATCH] use querylist to get popup filters --- .../dossier-template-actions.component.html | 6 +- .../dossier-listing-screen.component.html | 4 - .../dossier-listing-screen.component.ts | 35 ++++---- .../dossier-overview-screen.component.html | 4 - .../dossier-overview-screen.component.ts | 84 +++++++------------ .../shared/base/base-listing.component.ts | 8 +- 6 files changed, 53 insertions(+), 88 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.html b/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.html index b8cc0482b..964d802d3 100644 --- a/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.html +++ b/apps/red-ui/src/app/modules/admin/components/dossier-template-actions/dossier-template-actions.component.html @@ -5,8 +5,7 @@ icon="red:trash" tooltip="dossier-templates-listing.action.delete" type="dark-bg" - > - + > - + > diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html b/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html index 0fe731f87..756c7e49c 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html @@ -3,21 +3,18 @@
; + @ViewChild(QuickFiltersComponent) + protected readonly _quickFiltersComponent: QuickFiltersComponent; + constructor( readonly permissionsService: PermissionsService, private readonly _translateChartService: TranslateChartService, @@ -95,16 +105,6 @@ export class DossierListingScreenComponent return this.allEntities.length - this.activeDossiersCount; } - protected get _filterComponents(): (PopupFilterComponent | QuickFiltersComponent)[] { - return [ - this._statusFilterComponent, - this._peopleFilterComponent, - this._needsWorkFilterComponent, - this._dossierTemplateFilterComponent, - this._quickFiltersComponent - ]; - } - protected get _filters(): { values: FilterModel[]; checker: Function; @@ -156,6 +156,7 @@ export class DossierListingScreenComponent this._lastScrollPosition = this.scrollViewport.measureScrollOffset('top'); } }); + this._filterComponents = [...this._filterList.toArray(), this._quickFiltersComponent]; } ngOnAttach() { diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.html b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.html index 895a5dcf6..d18157645 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-overview-screen/dossier-overview-screen.component.html @@ -3,21 +3,18 @@
; + @ViewChild(QuickFiltersComponent) + protected readonly _quickFiltersComponent: QuickFiltersComponent; + @ViewChild('fileInput') private _fileInput: ElementRef; constructor( @@ -110,15 +118,6 @@ export class DossierOverviewScreenComponent return this.quickFilters.filter(f => !f.required && f.checked); } - protected get _filterComponents(): (PopupFilterComponent | QuickFiltersComponent)[] { - return [ - this._statusFilterComponent, - this._peopleFilterComponent, - this._needsWorkFilterComponent, - this._quickFiltersComponent - ]; - } - protected get _filters(): { values: FilterModel[]; checker: Function; @@ -184,6 +183,8 @@ export class DossierOverviewScreenComponent this._lastScrollPosition = this.scrollViewport.measureScrollOffset('top'); } }); + + this._filterComponents = [...this._filterList.toArray(), this._quickFiltersComponent]; } ngOnDestroy(): void { @@ -223,10 +224,6 @@ export class DossierOverviewScreenComponent }); } - isPending(fileStatusWrapper: FileStatusWrapper) { - return fileStatusWrapper.status === FileStatus.StatusEnum.UNPROCESSED; - } - isError(fileStatusWrapper: FileStatusWrapper) { return fileStatusWrapper.status === FileStatus.StatusEnum.ERROR; } @@ -278,12 +275,7 @@ export class DossierOverviewScreenComponent fileLink(fileStatus: FileStatusWrapper) { return this.permissionsService.canOpenFile(fileStatus) - ? [ - '/main/dossiers/' + - this.activeDossier.dossier.dossierId + - '/file/' + - fileStatus.fileId - ] + ? [`/main/dossiers/${this.activeDossier.dossierId}/file/${fileStatus.fileId}`] : []; } @@ -347,28 +339,18 @@ export class DossierOverviewScreenComponent } private _computeAllFilters() { - if (!this.activeDossier) { - return; - } + if (!this.activeDossier) return; const allDistinctFileStatusWrapper = new Set(); const allDistinctPeople = new Set(); const allDistinctAddedDates = new Set(); const allDistinctNeedsWork = new Set(); - // All people - this.allEntities.forEach(file => allDistinctPeople.add(file.currentReviewer)); - - // File statuses - this.allEntities.forEach(file => allDistinctFileStatusWrapper.add(file.status)); - - // Added dates - this.allEntities.forEach(file => - allDistinctAddedDates.add(moment(file.added).format('DD/MM/YYYY')) - ); - - // Needs work this.allEntities.forEach(file => { + allDistinctPeople.add(file.currentReviewer); + allDistinctFileStatusWrapper.add(file.status); + allDistinctAddedDates.add(moment(file.added).format('DD/MM/YYYY')); + if (this.permissionsService.fileRequiresReanalysis(file)) allDistinctNeedsWork.add('analysis'); if (file.hintsOnly) allDistinctNeedsWork.add('hint'); @@ -379,13 +361,10 @@ export class DossierOverviewScreenComponent if (file.hasNone) allDistinctNeedsWork.add('none'); }); - const statusFilters = []; - allDistinctFileStatusWrapper.forEach(status => { - statusFilters.push({ - key: status, - label: this._translateService.instant(status) - }); - }); + const statusFilters = [...allDistinctFileStatusWrapper].map(item => ({ + key: item, + label: this._translateService.instant(item) + })); statusFilters.sort((a, b) => StatusSorter[a.key] - StatusSorter[b.key]); this.statusFilters = processFilters(this.statusFilters, statusFilters); @@ -407,13 +386,10 @@ export class DossierOverviewScreenComponent }); this.peopleFilters = processFilters(this.peopleFilters, peopleFilters); - const needsWorkFilters = []; - allDistinctNeedsWork.forEach(type => { - needsWorkFilters.push({ - key: type, - label: `filter.${type}` - }); - }); + const needsWorkFilters = [...allDistinctNeedsWork].map(item => ({ + key: item, + label: this._translateService.instant('filter.' + item) + })); needsWorkFilters.sort( (a, b) => RedactionFilterSorter[a.key] - RedactionFilterSorter[b.key] ); diff --git a/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts b/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts index 01be98b5c..96db88b82 100644 --- a/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts +++ b/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts @@ -30,6 +30,8 @@ export abstract class BaseListingComponent { protected readonly _searchKey: string; protected readonly _selectionKey: string; protected readonly _sortKey: ScreenName; + // Overwrite this in ngOnInit + protected _filterComponents: (PopupFilterComponent | QuickFiltersComponent)[] = []; protected constructor(protected readonly _injector: Injector) { this._formBuilder = this._injector.get(FormBuilder); @@ -41,7 +43,7 @@ export abstract class BaseListingComponent { get hasActiveFilters() { return ( this._filterComponents - .filter(f => !!f) + ?.filter(f => !!f) .reduce((prev, component) => prev || component?.hasActiveFilters, false) || this.searchForm.get('query').value ); @@ -71,10 +73,6 @@ export abstract class BaseListingComponent { return []; } - protected get _filterComponents(): (PopupFilterComponent | QuickFiltersComponent)[] { - return []; - } - // ---- private get _getSearchKey(): string {