1- import { LayoutModeEnum , GridSection } from '../../../../core/layout/models/section.model' ;
2- import { Component , Input , OnInit } from '@angular/core' ;
1+ import { GridSection } from '../../../../core/layout/models/section.model' ;
2+ import { ChangeDetectorRef , Component , Input , OnInit } from '@angular/core' ;
33
44import { SortDirection , SortOptions } from '../../../../core/cache/models/sort-options.model' ;
55import { PaginationComponentOptions } from '../../../pagination/pagination-component-options.model' ;
@@ -16,6 +16,12 @@ import { Site } from '../../../../core/shared/site.model';
1616import { LocaleService } from '../../../../core/locale/locale.service' ;
1717import { Router } from '@angular/router' ;
1818import { TranslateService } from '@ngx-translate/core' ;
19+ import { BehaviorSubject , filter , from , map , mergeMap , scan , switchMap , take } from 'rxjs' ;
20+ import { BitstreamDataService } from 'src/app/core/data/bitstream-data.service' ;
21+ import { Item } from 'src/app/core/shared/item.model' ;
22+ import { Bitstream } from 'src/app/core/shared/bitstream.model' ;
23+ import { BitstreamFormat } from 'src/app/core/shared/bitstream-format.model' ;
24+ import { hasValue } from 'src/app/shared/empty.util' ;
1925
2026/**
2127 * Component representing the Grid component section.
@@ -41,8 +47,6 @@ export class GridSectionComponent implements OnInit {
4147
4248 paginatedSearchOptions : PaginatedSearchOptions ;
4349
44- layoutMode : LayoutModeEnum = LayoutModeEnum . CARD ;
45-
4650 maincontentBadge : string ;
4751
4852 maincontentTitle : string ;
@@ -53,13 +57,17 @@ export class GridSectionComponent implements OnInit {
5357
5458 maincontentLink : string ;
5559
56- searchResults ;
60+ searchResults : SearchResult < DSpaceObject > [ ] ;
61+
62+ itemToImageHrefMap$ = new BehaviorSubject < Map < string , string > > ( new Map < string , string > ( ) ) ;
5763
5864 constructor (
5965 private searchService : SearchService ,
6066 private locale : LocaleService ,
6167 private router : Router ,
62- private translateService : TranslateService
68+ private translateService : TranslateService ,
69+ private bitstreamDataService : BitstreamDataService ,
70+ private cdr : ChangeDetectorRef
6371 ) {
6472 }
6573
@@ -111,11 +119,46 @@ export class GridSectionComponent implements OnInit {
111119 . pipe ( getFirstCompletedRemoteData ( ) )
112120 . subscribe (
113121 ( response : RemoteData < PaginatedList < SearchResult < DSpaceObject > > > ) => {
114- this . searchResults = response . payload . page as any ;
122+ this . searchResults = response . payload . page ;
123+ this . getAllBitstreams ( ) ;
115124 }
116125 ) ;
117126 }
118127
128+ private getAllBitstreams ( ) {
129+ from ( this . searchResults ) . pipe (
130+ map ( ( itemSR ) => itemSR . indexableObject ) ,
131+ mergeMap ( ( item : Item ) => this . bitstreamDataService . showableByItem (
132+ item . uuid , 'ORIGINAL' , [ ] , { } , true , true , followLink ( 'format' )
133+ ) . pipe (
134+ getFirstCompletedRemoteData ( ) ,
135+ switchMap ( ( rd : RemoteData < PaginatedList < Bitstream > > ) => rd . hasSucceeded ? rd . payload . page : [ ] ) ,
136+ mergeMap ( ( bitstream : Bitstream ) => bitstream . format . pipe (
137+ getFirstCompletedRemoteData ( ) ,
138+ filter ( ( formatRemoteData : RemoteData < BitstreamFormat > ) =>
139+ formatRemoteData . hasSucceeded && hasValue ( formatRemoteData . payload ) && hasValue ( bitstream ) &&
140+ formatRemoteData . payload . mimetype . includes ( 'image/' )
141+ ) ,
142+ map ( ( ) => bitstream )
143+ ) ) ,
144+ take ( 1 ) ,
145+ map ( ( bitstream : Bitstream ) => {
146+ return [ item . uuid , bitstream . _links . content . href ] ;
147+ } )
148+ )
149+ ) ,
150+ scan ( ( acc : Map < string , string > , value : [ string , string ] ) => {
151+ acc . set ( value [ 0 ] , value [ 1 ] ) ;
152+ return acc ;
153+ } , new Map < string , string > ( ) )
154+ ) . subscribe ( ( res ) => {
155+ this . itemToImageHrefMap$ . next ( res ) ;
156+ this . cdr . detectChanges ( ) ;
157+ } ) ;
158+
159+ }
160+
161+
119162 goToMainContentLink ( ) {
120163 this . router . navigateByUrl ( this . maincontentLink ) ;
121164 }
0 commit comments