Skip to content

Commit 6858b4b

Browse files
committed
Add component to show CC license in the item page
1 parent a65f248 commit 6858b4b

10 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<div *ngIf="uri && name" class="item-page-field">
2+
<ds-metadata-field-wrapper [label]="'item.page.cc.license.title' | translate">
3+
<div [ngClass]="{'row': variant === 'full', 'col': variant === 'small'}">
4+
5+
<!-- 'img' tag is not rendered if any errors occurs when loading it -->
6+
<div *ngIf="showImage" [ngClass]="{'col-auto': variant === 'full', 'row': variant === 'small'}"
7+
style="align-content: center;"
8+
>
9+
<a [href]="uri" target="_blank" class="link-anchor dont-break-out ds-simple-metadata-link">
10+
<img (error)="showImage = false" [src]="imgSrc" [alt]="name" class="cc-image"
11+
[ngStyle]="{
12+
'width': 'var(--ds-thumbnail-max-width)',
13+
'margin-bottom': variant === 'small'? '1ch' : '0',
14+
}"
15+
/>
16+
</a>
17+
</div>
18+
19+
<!-- CC name is always displayed if the image fails to load -->
20+
<div [ngClass]="{ 'row': variant === 'small', 'col': variant === 'full' }">
21+
<span>
22+
{{ variant === 'full' && showDisclaimer ? ('item.page.cc.license.disclaimer' | translate) : '' }}
23+
<a *ngIf="showName || !showImage" [href]="uri" target="_blank" id="cc-name">{{ name }}</a>
24+
</span>
25+
</div>
26+
</div>
27+
</ds-metadata-field-wrapper>
28+
</div>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {
2+
NgClass,
3+
NgIf,
4+
NgStyle,
5+
} from '@angular/common';
6+
import {
7+
Component,
8+
Input,
9+
OnInit,
10+
} from '@angular/core';
11+
import { TranslateModule } from '@ngx-translate/core';
12+
import { Item } from 'src/app/core/shared/item.model';
13+
import { MetadataFieldWrapperComponent } from 'src/app/shared/metadata-field-wrapper/metadata-field-wrapper.component';
14+
15+
@Component({
16+
selector: 'ds-item-page-cc-license-field',
17+
templateUrl: './item-page-cc-license-field.component.html',
18+
standalone: true,
19+
imports: [NgIf, NgClass, NgStyle, TranslateModule, MetadataFieldWrapperComponent],
20+
})
21+
/**
22+
* Displays the item's Creative Commons license image in it's simple item page
23+
*/
24+
export class ItemPageCcLicenseFieldComponent implements OnInit {
25+
/**
26+
* The item to display the CC license image for
27+
*/
28+
@Input() item: Item;
29+
30+
/**
31+
* 'full' variant shows image, a disclaimer (optional) and name (always), better for the item page content.
32+
* 'small' variant shows image and name (optional), better for the item page sidebar
33+
*/
34+
@Input() variant?: 'small' | 'full' = 'small';
35+
36+
/**
37+
* Filed name containing the CC license URI, as configured in the back-end, in the 'dspace.cfg' file, propertie
38+
* 'cc.license.uri'
39+
*/
40+
@Input() ccLicenseUriField? = 'dc.rights.uri';
41+
42+
/**
43+
* Filed name containing the CC license name, as configured in the back-end, in the 'dspace.cfg' file, propertie
44+
* 'cc.license.name'
45+
*/
46+
@Input() ccLicenseNameField? = 'dc.rights';
47+
48+
/**
49+
* Shows the CC license name with the image. Always show if image fails to load
50+
*/
51+
@Input() showName? = true;
52+
53+
/**
54+
* Shows the disclaimer in the 'full' variant of the component
55+
*/
56+
@Input() showDisclaimer? = true;
57+
58+
uri: string;
59+
name: string;
60+
showImage = true;
61+
imgSrc: string;
62+
63+
ngOnInit() {
64+
this.uri = this.item.firstMetadataValue(this.ccLicenseUriField);
65+
this.name = this.item.firstMetadataValue(this.ccLicenseNameField);
66+
67+
// Extracts the CC license code from the URI
68+
const regex = /.*creativecommons.org\/(licenses|publicdomain)\/([^/]+)/gm;
69+
const matches = regex.exec(this.uri ?? '') ?? [];
70+
const ccCode = matches.length > 2 ? matches[2] : null;
71+
this.imgSrc = ccCode ? `assets/images/cc-licenses/${ccCode}.png` : null;
72+
}
73+
}

src/assets/i18n/en.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6657,4 +6657,8 @@
66576657
"search.filters.filter.notifyEndorsement.placeholder": "Notify Endorsement",
66586658

66596659
"search.filters.filter.notifyEndorsement.label": "Search Notify Endorsement",
6660+
6661+
"item.page.cc.license.title": "Creative Commons license",
6662+
6663+
"item.page.cc.license.disclaimer": "Except where otherwised noted, this item's license is described as",
66606664
}
20.4 KB
Loading
21.9 KB
Loading
17.2 KB
Loading
15.8 KB
Loading
17.2 KB
Loading
12.3 KB
Loading
6.3 KB
Loading

0 commit comments

Comments
 (0)