From 60bcfe8cf57f43413336889642813d51a8d0b2b3 Mon Sep 17 00:00:00 2001 From: Michael W Spalti Date: Wed, 28 Sep 2022 09:11:03 -0700 Subject: [PATCH] Correction in the image count method. --- .../mirador-viewer/mirador-viewer.service.ts | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/app/item-page/mirador-viewer/mirador-viewer.service.ts b/src/app/item-page/mirador-viewer/mirador-viewer.service.ts index 68be928cfa..06e5aa4ced 100644 --- a/src/app/item-page/mirador-viewer/mirador-viewer.service.ts +++ b/src/app/item-page/mirador-viewer/mirador-viewer.service.ts @@ -1,8 +1,10 @@ import { Injectable, isDevMode } from '@angular/core'; import { Observable } from 'rxjs'; import { Item } from '../../core/shared/item.model'; -import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from '../../core/shared/operators'; -import { filter, last, map, switchMap } from 'rxjs/operators'; +import { + getFirstCompletedRemoteData, +} from '../../core/shared/operators'; +import { filter, last, map, mergeMap, switchMap } from 'rxjs/operators'; import { RemoteData } from '../../core/data/remote-data'; import { PaginatedList } from '../../core/data/paginated-list.model'; import { Bitstream } from '../../core/shared/bitstream.model'; @@ -36,36 +38,44 @@ export class MiradorViewerService { * @returns the total image count */ getImageCount(item: Item, bitstreamDataService: BitstreamDataService, bundleDataService: BundleDataService): - Observable { - let count = 0; - return bundleDataService.findAllByItem(item).pipe( - getFirstCompletedRemoteData(), - map((bundlesRD: RemoteData>) => bundlesRD.payload), - map((paginatedList: PaginatedList) => paginatedList.page), - switchMap((bundles: Bundle[]) => bundles), - filter((b: Bundle) => this.isIiifBundle(b.name)), - switchMap((bundle: Bundle) => { - return bitstreamDataService.findAllByItemAndBundleName(item, bundle.name, { - currentPage: 1, - elementsPerPage: 5 - }, true, true, ...this.LINKS_TO_FOLLOW).pipe( + Observable { + let count = 0; + return bundleDataService.findAllByItem(item).pipe( getFirstCompletedRemoteData(), - map((bitstreamsRD: RemoteData>) => bitstreamsRD.payload), - map((paginatedList: PaginatedList) => paginatedList.page), - switchMap((bitstreams: Bitstream[]) => bitstreams), - switchMap((bitstream: Bitstream) => bitstream.format.pipe( - getFirstSucceededRemoteDataPayload(), - map((format: BitstreamFormat) => format) - )), - map((format: BitstreamFormat) => { - if (format.mimetype.includes('image')) { - count++; - } - return count; + map((bundlesRD: RemoteData>) => { + return bundlesRD.payload + }), + map((paginatedList: PaginatedList) => paginatedList.page), + switchMap((bundles: Bundle[]) => bundles), + filter((b: Bundle) => this.isIiifBundle(b.name)), + mergeMap((bundle: Bundle) => { + return bitstreamDataService.findAllByItemAndBundleName(item, bundle.name, { + currentPage: 1, + elementsPerPage: 5 + }, true, true, ...this.LINKS_TO_FOLLOW).pipe( + getFirstCompletedRemoteData(), + map((bitstreamsRD: RemoteData>) => { + return bitstreamsRD.payload; + }), + map((paginatedList: PaginatedList) => paginatedList.page), + switchMap((bitstreams: Bitstream[]) => bitstreams), + switchMap((bitstream: Bitstream) => bitstream.format.pipe( + getFirstCompletedRemoteData(), + map((formatRD: RemoteData) => { + return formatRD.payload + }), + map((format: BitstreamFormat) => { + if (format.mimetype.includes('image')) { + count++; + } + return count; + }), + ) + ) + ); }), last() - ); - })); + ); } isIiifBundle(bundleName: string): boolean {