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,13 @@ 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' ;
25+ import { getItemPageRoute } from 'src/app/item-page/item-page-routing-paths' ;
1926
2027/**
2128 * Component representing the Grid component section.
@@ -41,8 +48,6 @@ export class GridSectionComponent implements OnInit {
4148
4249 paginatedSearchOptions : PaginatedSearchOptions ;
4350
44- layoutMode : LayoutModeEnum = LayoutModeEnum . CARD ;
45-
4651 maincontentBadge : string ;
4752
4853 maincontentTitle : string ;
@@ -53,13 +58,17 @@ export class GridSectionComponent implements OnInit {
5358
5459 maincontentLink : string ;
5560
56- searchResults ;
61+ searchResults : SearchResult < DSpaceObject > [ ] ;
62+
63+ itemToImageHrefMap$ = new BehaviorSubject < Map < string , string > > ( new Map < string , string > ( ) ) ;
5764
5865 constructor (
5966 private searchService : SearchService ,
6067 private locale : LocaleService ,
6168 private router : Router ,
62- private translateService : TranslateService
69+ private translateService : TranslateService ,
70+ private bitstreamDataService : BitstreamDataService ,
71+ private cdr : ChangeDetectorRef
6372 ) {
6473 }
6574
@@ -111,11 +120,55 @@ export class GridSectionComponent implements OnInit {
111120 . pipe ( getFirstCompletedRemoteData ( ) )
112121 . subscribe (
113122 ( response : RemoteData < PaginatedList < SearchResult < DSpaceObject > > > ) => {
114- this . searchResults = response . payload . page as any ;
123+ this . searchResults = response . payload . page ;
124+ this . getAllBitstreams ( ) ;
115125 }
116126 ) ;
117127 }
118128
129+ private getAllBitstreams ( ) {
130+ from ( this . searchResults ) . pipe (
131+ map ( ( itemSR ) => itemSR . indexableObject ) ,
132+ mergeMap ( ( item : Item ) => this . bitstreamDataService . showableByItem (
133+ item . uuid , 'ORIGINAL' , [ ] , { } , true , true , followLink ( 'format' )
134+ ) . pipe (
135+ getFirstCompletedRemoteData ( ) ,
136+ switchMap ( ( rd : RemoteData < PaginatedList < Bitstream > > ) => rd . hasSucceeded ? rd . payload . page : [ ] ) ,
137+ mergeMap ( ( bitstream : Bitstream ) => bitstream . format . pipe (
138+ getFirstCompletedRemoteData ( ) ,
139+ filter ( ( formatRemoteData : RemoteData < BitstreamFormat > ) =>
140+ formatRemoteData . hasSucceeded && hasValue ( formatRemoteData . payload ) && hasValue ( bitstream ) &&
141+ formatRemoteData . payload . mimetype . includes ( 'image/' )
142+ ) ,
143+ map ( ( ) => bitstream )
144+ ) ) ,
145+ take ( 1 ) ,
146+ map ( ( bitstream : Bitstream ) => {
147+ return [ item . uuid , bitstream . _links . content . href ] ;
148+ } )
149+ )
150+ ) ,
151+ scan ( ( acc : Map < string , string > , value : [ string , string ] ) => {
152+ acc . set ( value [ 0 ] , value [ 1 ] ) ;
153+ return acc ;
154+ } , new Map < string , string > ( ) )
155+ ) . subscribe ( ( res ) => {
156+ this . itemToImageHrefMap$ . next ( res ) ;
157+ this . cdr . detectChanges ( ) ;
158+ } ) ;
159+
160+ }
161+
162+
163+ /**
164+ * to get the route of the item
165+ * @param item
166+ * @returns route to the item as a string
167+ */
168+ getItemPageRoute ( item : DSpaceObject ) {
169+ return getItemPageRoute ( item as Item ) ;
170+ }
171+
119172 goToMainContentLink ( ) {
120173 this . router . navigateByUrl ( this . maincontentLink ) ;
121174 }
0 commit comments