diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts index 8461382d1..5572370f3 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts @@ -24,6 +24,7 @@ import { PageRotationService } from '../../../pdf-viewer/services/page-rotation. import { getLocalStorageDataByFileId } from '@utils/local-storage'; import { FilterService, INestedFilter } from '@iqser/common-ui/lib/filtering'; import { AutoUnsubscribe, bool, Debounce, IqserEventTarget } from '@iqser/common-ui/lib/utils'; +import { toObservable } from '@angular/core/rxjs-interop'; const COMMAND_KEY_ARRAY = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Escape']; const ALL_HOTKEY_ARRAY = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']; @@ -117,8 +118,8 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On } private get _displayedAnnotations$(): Observable[]>> { - const primary$ = this.filterService.getFilterModels$('primaryFilters'); - const secondary$ = this.filterService.getFilterModels$('secondaryFilters'); + const primary$ = toObservable(computed(() => this.filterService.getFilterModels('primaryFilters'))); + const secondary$ = toObservable(computed(() => this.filterService.getFilterModels('secondaryFilters'))); return combineLatest([ this.fileDataService.all$, @@ -360,7 +361,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On this.displayedAnnotations = this._annotationProcessingService.filterAndGroupAnnotations(annotations, primary, secondary); const pagesThatDisplayAnnotations = [...this.displayedAnnotations.keys()]; - const enabledFilters = this.filterService.enabledFlatFilters; + const enabledFilters = this.filterService.enabledFlatFilters(); if (enabledFilters.some(f => f.id === 'pages-without-annotations')) { if (enabledFilters.length === 1 && !onlyPageWithAnnotations) { this.displayedPages = this.#allPages.filter(page => !pagesThatDisplayAnnotations.includes(page)); diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index 7f122e60a..13e926882 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -819,16 +819,14 @@ export class FilePreviewScreenComponent } #restoreOldFilters() { - combineLatest([ - this._filterService.getGroup$('primaryFilters').pipe(first(filterGroup => !!filterGroup?.filters.length)), - this._filterService.getGroup$('secondaryFilters').pipe(first(secondaryFilters => !!secondaryFilters?.filters.length)), - ]).subscribe(([primaryFilters, secondaryFilters]) => { - const localStorageFiltersString = localStorage.getItem('workload-filters') ?? '{}'; - const localStorageFilters = JSON.parse(localStorageFiltersString)[this.fileId]; - if (localStorageFilters) { - copyLocalStorageFiltersValues(primaryFilters.filters, localStorageFilters.primaryFilters); - copyLocalStorageFiltersValues(secondaryFilters.filters, localStorageFilters.secondaryFilters); - } - }); + const primaryFilters = this._filterService.getGroup('primaryFilters'); + const secondaryFilters = this._filterService.getGroup('secondaryFilters'); + + const localStorageFiltersString = localStorage.getItem('workload-filters') ?? '{}'; + const localStorageFilters = JSON.parse(localStorageFiltersString)[this.fileId]; + if (localStorageFilters) { + copyLocalStorageFiltersValues(primaryFilters.filters, localStorageFilters.primaryFilters); + copyLocalStorageFiltersValues(secondaryFilters.filters, localStorageFilters.secondaryFilters); + } } } diff --git a/apps/red-ui/src/app/modules/search/search-screen/search-screen.component.ts b/apps/red-ui/src/app/modules/search/search-screen/search-screen.component.ts index 017076a13..2fb28c0d6 100644 --- a/apps/red-ui/src/app/modules/search/search-screen/search-screen.component.ts +++ b/apps/red-ui/src/app/modules/search/search-screen/search-screen.component.ts @@ -25,6 +25,7 @@ import { DossierTemplatesService } from '@services/dossier-templates/dossier-tem import { UserService } from '@users/user.service'; import { IFilterGroup, keyChecker, NestedFilter } from '@iqser/common-ui/lib/filtering'; import { SortingOrders } from '@iqser/common-ui/lib/sorting'; +import { toObservable } from '@angular/core/rxjs-interop'; @Component({ templateUrl: './search-screen.component.html', @@ -128,10 +129,8 @@ export class SearchScreenComponent extends ListingComponent imp } private get _filtersChanged$(): Observable<[string[], WorkflowFileStatus, string, string[], boolean]> { - const onlyActiveDossiers$ = this.#enabledArchive - ? this.filterService.getSingleFilter('onlyActiveDossiers').pipe(map(f => !!f.checked)) - : of(true); - const filterGroups$ = this.filterService.filterGroups$; + const onlyActiveDossiers$ = of(this.#enabledArchive ? this.filterService.getSingleFilter('onlyActiveDossiers').checked : true); + const filterGroups$ = toObservable(this.filterService.filterGroups); return combineLatest([filterGroups$, onlyActiveDossiers$]).pipe( map(([groups, onlyActive]) => { const dossierIds: string[] = groups[0].filters.filter(v => v.checked).map(v => v.id); diff --git a/apps/red-ui/src/app/modules/shared/components/donut-chart/donut-chart.component.html b/apps/red-ui/src/app/modules/shared/components/donut-chart/donut-chart.component.html index 2de1a0ff6..fd2d8a2af 100644 --- a/apps/red-ui/src/app/modules/shared/components/donut-chart/donut-chart.component.html +++ b/apps/red-ui/src/app/modules/shared/components/donut-chart/donut-chart.component.html @@ -35,8 +35,8 @@
; + readonly filters = computed(() => this.filterService?.getFilterModels(this.filterKey) ?? []); constructor(@Optional() readonly filterService: FilterService) { // TODO: move this component to a separate module, split into smaller components, improve filters @@ -52,15 +53,6 @@ export class DonutChartComponent implements OnChanges, OnInit { return this.totalType === 'sum' ? this.dataTotal : this.config.length; } - ngOnInit() { - const filterModels$ = this.filterService?.getFilterModels$(this.filterKey).pipe( - map(filters => filters ?? []), - shareLast(), - ); - - this.filters$ = filterModels$ ?? of([]); - } - ngOnChanges(): void { this.calculateChartData(); this.cx = this.radius + this.strokeWidth / 2; @@ -68,11 +60,8 @@ export class DonutChartComponent implements OnChanges, OnInit { this.size = this.strokeWidth + this.radius * 2; } - filterChecked$(key: string): Observable { - return this.filters$.pipe( - get(filter => filter.id === key), - map(filter => !!filter?.checked), - ); + filterChecked(key: string): boolean { + return !!this.filters().find(filter => filter.id === key)?.checked; } getFormattedValue(value: number): string { diff --git a/libs/common-ui b/libs/common-ui index 9e0c31992..41d19013a 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 9e0c31992a8185a90b161e7030272e48451761e7 +Subproject commit 41d19013adcfc678987d06b4c3e53f8bec7a67f8