Mirador component multi-view based on count of image files in the default bundle.

This commit is contained in:
Michael Spalti
2021-09-29 22:03:23 -07:00
parent 670a0b8a26
commit d4a6ed6d08

View File

@@ -3,15 +3,21 @@ import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { Item } from '../../core/shared/item.model'; import { Item } from '../../core/shared/item.model';
import { environment } from '../../../environments/environment'; import { environment } from '../../../environments/environment';
import { BitstreamDataService } from '../../core/data/bitstream-data.service'; import { BitstreamDataService } from '../../core/data/bitstream-data.service';
import { getFirstCompletedRemoteData } from '../../core/shared/operators'; import {
getAllSucceededRemoteData,
getFirstCompletedRemoteData,
getFirstSucceededRemoteDataPayload
} from '../../core/shared/operators';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model'; import { PaginatedList } from '../../core/data/paginated-list.model';
import { Bitstream } from '../../core/shared/bitstream.model'; import { Bitstream } from '../../core/shared/bitstream.model';
import { hasValue } from '../../shared/empty.util'; import { hasValue } from '../../shared/empty.util';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import { map } from 'rxjs/operators'; import { filter, map, switchMap, take, takeUntil, takeWhile, tap } from 'rxjs/operators';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { isPlatformBrowser } from '@angular/common'; import { isPlatformBrowser } from '@angular/common';
import { BitstreamFormat } from '../../core/shared/bitstream-format.model';
import { followLink, FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
@Component({ @Component({
selector: 'ds-mirador-viewer', selector: 'ds-mirador-viewer',
@@ -33,6 +39,10 @@ export class MiradorViewerComponent implements OnInit {
notMobile = false; notMobile = false;
LINKS_TO_FOLLOW: FollowLinkConfig<Bitstream>[] = [
followLink('format'),
];
constructor(private sanitizer: DomSanitizer, constructor(private sanitizer: DomSanitizer,
private bitstreamDataService: BitstreamDataService, private bitstreamDataService: BitstreamDataService,
@Inject(PLATFORM_ID) private platformId: any) { @Inject(PLATFORM_ID) private platformId: any) {
@@ -68,6 +78,9 @@ export class MiradorViewerComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
/** /**
* Initializes the iframe url observable. * Initializes the iframe url observable.
*/ */
@@ -78,8 +91,8 @@ export class MiradorViewerComponent implements OnInit {
} }
// We need to set the multi property to true if the // We need to set the multi property to true if the
// item is searchable or the IIIF bundle contains more // item is searchable or the bundle contains more
// than 3 bitstreams. The multi property controls the // than 1 image bitstream. The multi property controls the
// Mirador side navigation panel. // Mirador side navigation panel.
if (this.searchable) { if (this.searchable) {
// If it's searchable set multi to true. // If it's searchable set multi to true.
@@ -91,19 +104,30 @@ export class MiradorViewerComponent implements OnInit {
}) })
); );
} else { } else {
this.iframeViewerUrl = this.bitstreamDataService let count = 0;
.findAllByItemAndBundleName(this.item, 'IIIF', {}) this.iframeViewerUrl = this.bitstreamDataService.findAllByItemAndBundleName(this.item, 'ORIGINAL', {
currentPage: 1,
elementsPerPage: 10
}, true, true, ...this.LINKS_TO_FOLLOW)
.pipe( .pipe(
getFirstCompletedRemoteData(), getFirstCompletedRemoteData(),
map((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => { map((bitstreamsRD: RemoteData<PaginatedList<Bitstream>>) => bitstreamsRD.payload),
if (hasValue(bitstreamsRD.payload)) { map((paginatedList: PaginatedList<Bitstream>) => paginatedList.page),
if (bitstreamsRD.payload.totalElements > 2) { switchMap((bitstreams: Bitstream[]) => bitstreams),
/* IIIF bundle contains multiple images and optionally a switchMap((bitstream: Bitstream) => bitstream.format.pipe(
* a single json file, so multi is true only when the count getFirstSucceededRemoteDataPayload(),
* is 3 or more. */ map((format: BitstreamFormat) => format)
this.multi = true; )),
} map((format) => {
if (format.mimetype.includes('image')) {
count++;
} }
return count;
}),
filter(currentCount => currentCount > 1),
take(1),
map(() => {
this.multi = true;
return this.setURL(); return this.setURL();
}) })
); );