Skip to content

Commit 2a5d779

Browse files
authored
Merge pull request #3345 from 4Science/task/dspace-8_x/CST-15077
[Port dspace-8_x] Add orcid icon with tooltip
2 parents 7f1a21b + 44b900f commit 2a5d779

File tree

7 files changed

+169
-1
lines changed

7 files changed

+169
-1
lines changed

src/app/entity-groups/research-entities/metadata-representations/person/person-item-metadata-list-element.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@
1212
<a [routerLink]="[itemPageRoute]"
1313
[innerHTML]="mdRepresentation.getValue()"
1414
[ngbTooltip]="mdRepresentation.allMetadata(['person.jobTitle']).length > 0 ? descTemplate : null"></a>
15+
<ds-orcid-badge-and-tooltip class="ml-1"
16+
*ngIf="mdRepresentation.firstMetadata('person.identifier.orcid')"
17+
[orcid]="mdRepresentation.firstMetadata('person.identifier.orcid')"
18+
[authenticatedTimestamp]="mdRepresentation.firstMetadata('dspace.orcid.authenticated')">
19+
</ds-orcid-badge-and-tooltip>
1520
</ds-truncatable>

src/app/entity-groups/research-entities/metadata-representations/person/person-item-metadata-list-element.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { RouterLink } from '@angular/router';
77
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
88

99
import { ItemMetadataRepresentationListElementComponent } from '../../../../shared/object-list/metadata-representation-list-element/item/item-metadata-representation-list-element.component';
10+
import { OrcidBadgeAndTooltipComponent } from '../../../../shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component';
1011
import { TruncatableComponent } from '../../../../shared/truncatable/truncatable.component';
1112

1213
@Component({
1314
selector: 'ds-person-item-metadata-list-element',
1415
templateUrl: './person-item-metadata-list-element.component.html',
1516
standalone: true,
16-
imports: [NgIf, NgFor, TruncatableComponent, RouterLink, NgbTooltipModule],
17+
imports: [NgIf, NgFor, TruncatableComponent, RouterLink, NgbTooltipModule, OrcidBadgeAndTooltipComponent],
1718
})
1819
/**
1920
* The component for displaying an item of the type Person as a metadata field
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<img placement="top"
2+
[ngbTooltip]="orcidTooltipTemplate"
3+
class="orcid-icon"
4+
[ngClass]="{'not-authenticated': !authenticatedTimestamp}"
5+
alt="ORCID {{ orcidTooltip }}"
6+
src="assets/images/orcid.logo.icon.svg"
7+
data-test="orcidIcon"/>
8+
9+
<ng-template #orcidTooltipTemplate>
10+
<span class="text-muted">{{ orcidTooltip }}</span>
11+
</ng-template>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:host {
2+
display: inline-block;
3+
}
4+
5+
.orcid-icon {
6+
height: 1.2rem;
7+
8+
&.not-authenticated {
9+
filter: grayscale(100%);
10+
}
11+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {
2+
NgClass,
3+
NgIf,
4+
} from '@angular/common';
5+
import {
6+
ComponentFixture,
7+
TestBed,
8+
} from '@angular/core/testing';
9+
import { By } from '@angular/platform-browser';
10+
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
11+
import { TranslateService } from '@ngx-translate/core';
12+
13+
import { MetadataValue } from '../../core/shared/metadata.models';
14+
import { OrcidBadgeAndTooltipComponent } from './orcid-badge-and-tooltip.component';
15+
16+
describe('OrcidBadgeAndTooltipComponent', () => {
17+
let component: OrcidBadgeAndTooltipComponent;
18+
let fixture: ComponentFixture<OrcidBadgeAndTooltipComponent>;
19+
let translateService: TranslateService;
20+
21+
beforeEach(async () => {
22+
await TestBed.configureTestingModule({
23+
imports: [
24+
OrcidBadgeAndTooltipComponent,
25+
NgbTooltipModule,
26+
NgClass,
27+
NgIf,
28+
],
29+
providers: [
30+
{ provide: TranslateService, useValue: { instant: (key: string) => key } },
31+
],
32+
}).compileComponents();
33+
34+
fixture = TestBed.createComponent(OrcidBadgeAndTooltipComponent);
35+
component = fixture.componentInstance;
36+
translateService = TestBed.inject(TranslateService);
37+
38+
component.orcid = { value: '0000-0002-1825-0097' } as MetadataValue;
39+
component.authenticatedTimestamp = { value: '2023-10-01' } as MetadataValue;
40+
41+
fixture.detectChanges();
42+
});
43+
44+
it('should create', () => {
45+
expect(component).toBeTruthy();
46+
});
47+
48+
it('should set orcidTooltip when authenticatedTimestamp is provided', () => {
49+
component.ngOnInit();
50+
expect(component.orcidTooltip).toBe('person.orcid-tooltip.authenticated');
51+
});
52+
53+
it('should set orcidTooltip when authenticatedTimestamp is not provided', () => {
54+
component.authenticatedTimestamp = null;
55+
component.ngOnInit();
56+
expect(component.orcidTooltip).toBe('person.orcid-tooltip.not-authenticated');
57+
});
58+
59+
it('should display the ORCID icon', () => {
60+
const badgeIcon = fixture.debugElement.query(By.css('img[data-test="orcidIcon"]'));
61+
expect(badgeIcon).toBeTruthy();
62+
});
63+
64+
it('should display the ORCID icon in greyscale if there is no authenticated timestamp', () => {
65+
component.authenticatedTimestamp = null;
66+
fixture.detectChanges();
67+
const badgeIcon = fixture.debugElement.query(By.css('img[data-test="orcidIcon"]'));
68+
expect(badgeIcon.nativeElement.classList).toContain('not-authenticated');
69+
});
70+
71+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {
2+
NgClass,
3+
NgIf,
4+
} from '@angular/common';
5+
import {
6+
Component,
7+
Input,
8+
OnInit,
9+
} from '@angular/core';
10+
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
11+
import { TranslateService } from '@ngx-translate/core';
12+
13+
import { MetadataValue } from '../../core/shared/metadata.models';
14+
15+
/**
16+
* Component to display an ORCID badge with a tooltip.
17+
* The tooltip text changes based on whether the ORCID is authenticated.
18+
*/
19+
@Component({
20+
selector: 'ds-orcid-badge-and-tooltip',
21+
standalone: true,
22+
imports: [
23+
NgIf,
24+
NgbTooltipModule,
25+
NgClass,
26+
],
27+
templateUrl: './orcid-badge-and-tooltip.component.html',
28+
styleUrl: './orcid-badge-and-tooltip.component.scss',
29+
})
30+
export class OrcidBadgeAndTooltipComponent implements OnInit {
31+
32+
/**
33+
* The ORCID value to be displayed.
34+
*/
35+
@Input() orcid: MetadataValue;
36+
37+
/**
38+
* The timestamp indicating when the ORCID was authenticated.
39+
*/
40+
@Input() authenticatedTimestamp: MetadataValue;
41+
42+
/**
43+
* The tooltip text to be displayed.
44+
*/
45+
orcidTooltip: string;
46+
47+
/**
48+
* Constructor to inject the TranslateService.
49+
* @param translateService - Service for translation.
50+
*/
51+
constructor(
52+
private translateService: TranslateService,
53+
) { }
54+
55+
/**
56+
* Initializes the component.
57+
* Sets the tooltip text based on the presence of the authenticated timestamp.
58+
*/
59+
ngOnInit() {
60+
this.orcidTooltip = this.authenticatedTimestamp ?
61+
this.translateService.instant('person.orcid-tooltip.authenticated', { orcid: this.orcid.value }) :
62+
this.translateService.instant('person.orcid-tooltip.not-authenticated', { orcid: this.orcid.value });
63+
}
64+
65+
}

src/assets/i18n/en.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6004,6 +6004,10 @@
60046004

60056005
"person.orcid.registry.auth": "ORCID Authorizations",
60066006

6007+
"person.orcid-tooltip.authenticated": "{{orcid}}",
6008+
6009+
"person.orcid-tooltip.not-authenticated": "{{orcid}} (unconfirmed)",
6010+
60076011
"home.recent-submissions.head": "Recent Submissions",
60086012

60096013
"listable-notification-object.default-message": "This object couldn't be retrieved",

0 commit comments

Comments
 (0)