From d7b19f3d52c1a99dfff9ad9868cc22ff159c170c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20G=C3=B3mez?= Date: Thu, 4 Jul 2024 21:07:20 +0200 Subject: [PATCH] Make the CC license field component configurable --- config/config.example.yml | 17 +++++++++- .../item-page-cc-license-field.component.ts | 23 ++++++++----- src/config/app-config.interface.ts | 2 ++ ...eative-commons-license-config.interface.ts | 34 +++++++++++++++++++ src/config/default-app-config.ts | 9 +++++ src/environments/environment.test.ts | 7 ++++ 6 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/config/creative-commons-license-config.interface.ts diff --git a/config/config.example.yml b/config/config.example.yml index 7695aed3a13..3b936d63974 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -510,7 +510,22 @@ notifyMetrics: config: 'NOTIFY.outgoing.delivered' description: 'admin-notify-dashboard.NOTIFY.outgoing.delivered.description' - +# Creative Commons metadata fields +ccLicense: + # Icon variant: + # 'full' variant shows image, a disclaimer (optional) and name (always), better for the item page content. + # 'small' (default) variant shows image and name (optional), better for the item page sidebar + variant: small + # Field name containing the CC license URI, as configured in the back-end, in the 'dspace.cfg' file, property 'cc.license.uri' + # Defaults to 'dc.rights.uri' + uriField: dc.rights.uri + # Field name containing the CC license name, as configured in the back-end, in the 'dspace.cfg' file, property 'cc.license' + # Defaults to 'dc.rights' + nameField: dc.rights + # Shows the CC license name with the image. Always show if image fails to load + showName: true + # Shows the disclaimer in the 'full' variant of the component + showDisclaimer: true diff --git a/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts b/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts index 19df1d2fb79..7cd742381a8 100644 --- a/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts +++ b/src/app/item-page/simple/field-components/specific-field/cc-license/item-page-cc-license-field.component.ts @@ -5,12 +5,14 @@ import { } from '@angular/common'; import { Component, + Inject, Input, OnInit, } from '@angular/core'; import { TranslateModule } from '@ngx-translate/core'; import { Item } from 'src/app/core/shared/item.model'; import { MetadataFieldWrapperComponent } from 'src/app/shared/metadata-field-wrapper/metadata-field-wrapper.component'; +import { APP_CONFIG, AppConfig } from 'src/config/app-config.interface'; @Component({ selector: 'ds-item-page-cc-license-field', @@ -31,35 +33,38 @@ export class ItemPageCcLicenseFieldComponent implements OnInit { * 'full' variant shows image, a disclaimer (optional) and name (always), better for the item page content. * 'small' variant shows image and name (optional), better for the item page sidebar */ - @Input() variant?: 'small' | 'full' = 'small'; + @Input() variant?: 'small' | 'full' = this.appConfig.ccLicense.variant; /** - * Filed name containing the CC license URI, as configured in the back-end, in the 'dspace.cfg' file, propertie - * 'cc.license.uri' + * Field name containing the CC license URI */ - @Input() ccLicenseUriField? = 'dc.rights.uri'; + @Input() ccLicenseUriField? = this.appConfig.ccLicense.uriField; /** - * Filed name containing the CC license name, as configured in the back-end, in the 'dspace.cfg' file, propertie - * 'cc.license.name' + * Field name containing the CC license name */ - @Input() ccLicenseNameField? = 'dc.rights.license'; + @Input() ccLicenseNameField? = this.appConfig.ccLicense.nameField; /** * Shows the CC license name with the image. Always show if image fails to load */ - @Input() showName? = true; + @Input() showName? = this.appConfig.ccLicense.showName; /** * Shows the disclaimer in the 'full' variant of the component */ - @Input() showDisclaimer? = true; + @Input() showDisclaimer? = this.appConfig.ccLicense.showDisclaimer; uri: string; name: string; showImage = true; imgSrc: string; + constructor( + @Inject(APP_CONFIG) public appConfig: AppConfig, + ) { + } + ngOnInit() { this.uri = this.item.firstMetadataValue(this.ccLicenseUriField); this.name = this.item.firstMetadataValue(this.ccLicenseNameField); diff --git a/src/config/app-config.interface.ts b/src/config/app-config.interface.ts index 64724324601..38632faaef4 100644 --- a/src/config/app-config.interface.ts +++ b/src/config/app-config.interface.ts @@ -15,6 +15,7 @@ import { CollectionPageConfig } from './collection-page-config.interface'; import { CommunityListConfig } from './community-list-config.interface'; import { CommunityPageConfig } from './community-page-config.interface'; import { Config } from './config.interface'; +import { CreativeCommonsLicenseConfig } from './creative-commons-license-config.interface'; import { DiscoverySortConfig } from './discovery-sort.config'; import { FilterVocabularyConfig } from './filter-vocabulary-config'; import { FormConfig } from './form-config.interfaces'; @@ -67,6 +68,7 @@ interface AppConfig extends Config { qualityAssuranceConfig: QualityAssuranceConfig; search: SearchConfig; notifyMetrics: AdminNotifyMetricsRow[]; + ccLicense: CreativeCommonsLicenseConfig; // BEGIN: Sistedes sistedes: SistedesConfig; // END: Sistedes diff --git a/src/config/creative-commons-license-config.interface.ts b/src/config/creative-commons-license-config.interface.ts new file mode 100644 index 00000000000..e4333251dc5 --- /dev/null +++ b/src/config/creative-commons-license-config.interface.ts @@ -0,0 +1,34 @@ +import { Config } from './config.interface'; + +export interface CreativeCommonsLicenseConfig extends Config { + + /** + * CC icon variant ('small' or 'full') + * Used by {@link ItemPageCcLicenseFieldComponent}. + */ + variant: 'small' | 'full'; + + /** + * Field name containing the CC license URI + * Used by {@link ItemPageCcLicenseFieldComponent}. + */ + uriField: string; + + /** + * Field name containing the CC license URI + * Used by {@link ItemPageCcLicenseFieldComponent}. + */ + nameField: string; + + /** + * Shows the CC license name with the image. Always show if image fails to load + * Used by {@link ItemPageCcLicenseFieldComponent}. + */ + showName: boolean; + + /** + * Show the disclaimer in the 'full' variant of the component + * Used by {@link ItemPageCcLicenseFieldComponent}. + */ + showDisclaimer: boolean; +} diff --git a/src/config/default-app-config.ts b/src/config/default-app-config.ts index 0586a20009a..fe0f50d1a8e 100644 --- a/src/config/default-app-config.ts +++ b/src/config/default-app-config.ts @@ -10,6 +10,7 @@ import { CacheConfig } from './cache-config.interface'; import { CollectionPageConfig } from './collection-page-config.interface'; import { CommunityListConfig } from './community-list-config.interface'; import { CommunityPageConfig } from './community-page-config.interface'; +import { CreativeCommonsLicenseConfig } from './creative-commons-license-config.interface'; import { DiscoverySortConfig } from './discovery-sort.config'; import { FilterVocabularyConfig } from './filter-vocabulary-config'; import { FormConfig } from './form-config.interfaces'; @@ -597,6 +598,14 @@ export class DefaultAppConfig implements AppConfig { ], }, ]; + // Metadatafields to determine the CC license variant + ccLicense: CreativeCommonsLicenseConfig = { + variant: 'small', + uriField: 'dc.rights.uri', + nameField: 'dc.rights', + showName: true, + showDisclaimer: true, + }; // BEGIN: Sistedes sistedes: SistedesConfig = { highlightedCommunities: { diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index 3c24572e4de..de80597eb8c 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -424,6 +424,13 @@ export const environment: BuildConfig = { ], }, ], + ccLicense: { + variant: 'small', + uriField: 'dc.rights.uri', + nameField: 'dc.rights', + showName: true, + showDisclaimer: true, + }, // BEGIN: Sistedes sistedes: { highlightedCommunities: {