@@ -12,6 +12,7 @@ import {
1212} from '@angular/core' ;
1313import { TranslateModule } from '@ngx-translate/core' ;
1414import {
15+ map ,
1516 Observable ,
1617 of ,
1718 Subscription ,
@@ -25,6 +26,7 @@ import {
2526 getRemoteDataPayload ,
2627} from 'src/app/core/shared/operators' ;
2728import { ItemPageCcLicenseFieldComponent } from 'src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component' ;
29+ import { hasValue } from 'src/app/shared/empty.util' ;
2830import { MetadataFieldWrapperComponent } from 'src/app/shared/metadata-field-wrapper/metadata-field-wrapper.component' ;
2931import { isCcLicense } from 'src/app/shared/utils/license.utils' ;
3032
@@ -43,7 +45,7 @@ import { isCcLicense } from 'src/app/shared/utils/license.utils';
4345 * appear. In any other case, all the 'dc.rights*' fields will be shown as a list (where the URIs
4446 * will be rendered as links).
4547 */
46- export class ItemPageLicenseFieldComponent implements OnInit , OnDestroy {
48+ export class ItemPageLicenseFieldComponent implements OnInit {
4749 /**
4850 * The item to display the license for
4951 */
@@ -67,28 +69,24 @@ export class ItemPageLicenseFieldComponent implements OnInit, OnDestroy {
6769 protected configService : ConfigurationDataService ,
6870 ) { }
6971
70- ngOnDestroy ( ) : void {
71- this . subscriptions . forEach ( ( sub : Subscription ) => sub . unsubscribe ( ) ) ;
72- }
73-
7472 ngOnInit ( ) {
7573 // First, retrieve from the back-end the configuration regarding CC fields...
76- this . subscriptions . push ( this . configService . findByPropertyName ( 'cc.license.uri ' ) . pipe (
74+ this . hasCcLicenseName$ = this . configService . findByPropertyName ( 'cc.license.name ' ) . pipe (
7775 getFirstCompletedRemoteData ( ) ,
7876 getRemoteDataPayload ( ) ,
79- ) . subscribe ( ( remoteData : ConfigurationProperty ) => {
80- const ccLicenseUriField = remoteData ?. values && remoteData ?. values ?. length > 0 ? remoteData . values [ 0 ] : 'dc.rights.uri' ;
81- this . hasCcLicenseUri$ = of ( isCcLicense ( this . item . firstMetadataValue ( ccLicenseUriField ) ) ) ;
82- } ) ,
77+ map ( ( configurationProperty : ConfigurationProperty ) => configurationProperty ?. values ?. [ 0 ] ) ,
78+ map ( ( metadataField : string ) => hasValue ( metadataField ) ? metadataField : 'dc.rights' ) ,
79+ map ( ( metadataField : string ) => this . item . firstMetadataValue ( metadataField ) ) ,
80+ map ( ( metadataValue : string ) => hasValue ( metadataValue ) ) ,
8381 ) ;
8482
85- this . subscriptions . push ( this . configService . findByPropertyName ( 'cc.license.name ' ) . pipe (
83+ this . hasCcLicenseUri$ = this . configService . findByPropertyName ( 'cc.license.uri ' ) . pipe (
8684 getFirstCompletedRemoteData ( ) ,
8785 getRemoteDataPayload ( ) ,
88- ) . subscribe ( ( remoteData : ConfigurationProperty ) => {
89- const ccLicenseNameField = remoteData ?. values && remoteData ?. values ?. length > 0 ? remoteData . values [ 0 ] : 'dc.rights' ;
90- this . hasCcLicenseName$ = of ( ! ! this . item . firstMetadataValue ( ccLicenseNameField ) ) ;
91- } ) ,
86+ map ( ( configurationProperty : ConfigurationProperty ) => configurationProperty ?. values ?. [ 0 ] ) ,
87+ map ( ( metadataField : string ) => hasValue ( metadataField ) ? metadataField : 'dc.rights' ) ,
88+ map ( ( metadataField : string ) => this . item . firstMetadataValue ( metadataField ) ) ,
89+ map ( ( metadataValue : string ) => isCcLicense ( metadataValue ) ) ,
9290 ) ;
9391
9492 // Now, get the data for this component, in case we need to render the license data as a generic license...
0 commit comments