@@ -16,11 +16,12 @@ import {
1616 map ,
1717} from 'rxjs/operators' ;
1818import { AccessStatusDataService } from 'src/app/core/data/access-status-data.service' ;
19+ import { Bitstream } from 'src/app/core/shared/bitstream.model' ;
20+ import { getFirstSucceededRemoteDataPayload } from 'src/app/core/shared/operators' ;
1921import { environment } from 'src/environments/environment' ;
2022
2123import { DSpaceObject } from '../../../../../core/shared/dspace-object.model' ;
2224import { Item } from '../../../../../core/shared/item.model' ;
23- import { ITEM } from '../../../../../core/shared/item.resource-type' ;
2425import { hasValue } from '../../../../empty.util' ;
2526import { AccessStatusObject } from './access-status.model' ;
2627
@@ -37,7 +38,9 @@ import { AccessStatusObject } from './access-status.model';
3738export class AccessStatusBadgeComponent implements OnDestroy , OnInit {
3839
3940 @Input ( ) object : DSpaceObject ;
41+
4042 accessStatus$ : Observable < string > ;
43+ embargoDate$ : Observable < string > ;
4144
4245 /**
4346 * Whether to show the access status badge or not
@@ -62,12 +65,32 @@ export class AccessStatusBadgeComponent implements OnDestroy, OnInit {
6265 constructor ( private accessStatusDataService : AccessStatusDataService ) { }
6366
6467 ngOnInit ( ) : void {
65- this . showAccessStatus = environment . item . showAccessStatuses ;
66- if ( this . object . type . toString ( ) !== ITEM . value || ! this . showAccessStatus || this . object == null ) {
67- // Do not show the badge if the feature is inactive or if the item is null.
68+ if ( ! hasValue ( this . object ) ) {
6869 return ;
6970 }
71+ switch ( ( this . object as any ) . type ) {
72+ case Item . type . value :
73+ this . handleItem ( ) ;
74+ break ;
75+ case Bitstream . type . value :
76+ this . handleBitstream ( ) ;
77+ break ;
78+ }
79+ }
7080
81+ ngOnDestroy ( ) : void {
82+ this . subs . filter ( ( sub ) => hasValue ( sub ) ) . forEach ( ( sub ) => sub . unsubscribe ( ) ) ;
83+ }
84+
85+ /**
86+ * Method to handle the object type Item
87+ */
88+ private handleItem ( ) {
89+ this . showAccessStatus = environment . item . showAccessStatuses ;
90+ if ( ! this . showAccessStatus ) {
91+ // Do not show the badge if the feature is inactive.
92+ return ;
93+ }
7194 const item = this . object as Item ;
7295 if ( item . accessStatus == null ) {
7396 // In case the access status has not been loaded, do it individually.
@@ -85,7 +108,6 @@ export class AccessStatusBadgeComponent implements OnDestroy, OnInit {
85108 map ( ( status : string ) => `access-status.${ status . toLowerCase ( ) } .listelement.badge` ) ,
86109 catchError ( ( ) => observableOf ( 'access-status.unknown.listelement.badge' ) ) ,
87110 ) ;
88-
89111 // stylesheet based on the access status value
90112 this . subs . push (
91113 this . accessStatus$ . pipe (
@@ -96,7 +118,31 @@ export class AccessStatusBadgeComponent implements OnDestroy, OnInit {
96118 ) ;
97119 }
98120
99- ngOnDestroy ( ) : void {
100- this . subs . filter ( ( sub ) => hasValue ( sub ) ) . forEach ( ( sub ) => sub . unsubscribe ( ) ) ;
121+ /**
122+ * Method to handle the object type Bitstream
123+ */
124+ private handleBitstream ( ) {
125+ this . showAccessStatus = environment . item . bitstream . showAccessStatuses ;
126+ if ( ! this . showAccessStatus ) {
127+ // Do not show the badge if the feature is inactive.
128+ return ;
129+ }
130+ const bitstream = this . object as Bitstream ;
131+ if ( bitstream . accessStatus == null ) {
132+ return ;
133+ }
134+ this . embargoDate$ = bitstream . accessStatus . pipe (
135+ getFirstSucceededRemoteDataPayload ( ) ,
136+ map ( ( accessStatus : AccessStatusObject ) => {
137+ if ( hasValue ( accessStatus . embargoDate ) ) {
138+ this . accessStatus$ = observableOf ( 'embargo.listelement.badge' ) ;
139+ return accessStatus . embargoDate ;
140+ } else {
141+ this . accessStatus$ = observableOf ( null ) ;
142+ return null ;
143+ }
144+ } ) ,
145+ catchError ( ( ) => observableOf ( null ) ) ,
146+ ) ;
101147 }
102148}
0 commit comments