-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3345 from 4Science/task/dspace-8_x/CST-15077
[Port dspace-8_x] Add orcid icon with tooltip
- Loading branch information
Showing
7 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<img placement="top" | ||
[ngbTooltip]="orcidTooltipTemplate" | ||
class="orcid-icon" | ||
[ngClass]="{'not-authenticated': !authenticatedTimestamp}" | ||
alt="ORCID {{ orcidTooltip }}" | ||
src="assets/images/orcid.logo.icon.svg" | ||
data-test="orcidIcon"/> | ||
|
||
<ng-template #orcidTooltipTemplate> | ||
<span class="text-muted">{{ orcidTooltip }}</span> | ||
</ng-template> |
11 changes: 11 additions & 0 deletions
11
src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:host { | ||
display: inline-block; | ||
} | ||
|
||
.orcid-icon { | ||
height: 1.2rem; | ||
|
||
&.not-authenticated { | ||
filter: grayscale(100%); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
NgClass, | ||
NgIf, | ||
} from '@angular/common'; | ||
import { | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
import { MetadataValue } from '../../core/shared/metadata.models'; | ||
import { OrcidBadgeAndTooltipComponent } from './orcid-badge-and-tooltip.component'; | ||
|
||
describe('OrcidBadgeAndTooltipComponent', () => { | ||
let component: OrcidBadgeAndTooltipComponent; | ||
let fixture: ComponentFixture<OrcidBadgeAndTooltipComponent>; | ||
let translateService: TranslateService; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
OrcidBadgeAndTooltipComponent, | ||
NgbTooltipModule, | ||
NgClass, | ||
NgIf, | ||
], | ||
providers: [ | ||
{ provide: TranslateService, useValue: { instant: (key: string) => key } }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(OrcidBadgeAndTooltipComponent); | ||
component = fixture.componentInstance; | ||
translateService = TestBed.inject(TranslateService); | ||
|
||
component.orcid = { value: '0000-0002-1825-0097' } as MetadataValue; | ||
component.authenticatedTimestamp = { value: '2023-10-01' } as MetadataValue; | ||
|
||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should set orcidTooltip when authenticatedTimestamp is provided', () => { | ||
component.ngOnInit(); | ||
expect(component.orcidTooltip).toBe('person.orcid-tooltip.authenticated'); | ||
}); | ||
|
||
it('should set orcidTooltip when authenticatedTimestamp is not provided', () => { | ||
component.authenticatedTimestamp = null; | ||
component.ngOnInit(); | ||
expect(component.orcidTooltip).toBe('person.orcid-tooltip.not-authenticated'); | ||
}); | ||
|
||
it('should display the ORCID icon', () => { | ||
const badgeIcon = fixture.debugElement.query(By.css('img[data-test="orcidIcon"]')); | ||
expect(badgeIcon).toBeTruthy(); | ||
}); | ||
|
||
it('should display the ORCID icon in greyscale if there is no authenticated timestamp', () => { | ||
component.authenticatedTimestamp = null; | ||
fixture.detectChanges(); | ||
const badgeIcon = fixture.debugElement.query(By.css('img[data-test="orcidIcon"]')); | ||
expect(badgeIcon.nativeElement.classList).toContain('not-authenticated'); | ||
}); | ||
|
||
}); |
65 changes: 65 additions & 0 deletions
65
src/app/shared/orcid-badge-and-tooltip/orcid-badge-and-tooltip.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
NgClass, | ||
NgIf, | ||
} from '@angular/common'; | ||
import { | ||
Component, | ||
Input, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
import { MetadataValue } from '../../core/shared/metadata.models'; | ||
|
||
/** | ||
* Component to display an ORCID badge with a tooltip. | ||
* The tooltip text changes based on whether the ORCID is authenticated. | ||
*/ | ||
@Component({ | ||
selector: 'ds-orcid-badge-and-tooltip', | ||
standalone: true, | ||
imports: [ | ||
NgIf, | ||
NgbTooltipModule, | ||
NgClass, | ||
], | ||
templateUrl: './orcid-badge-and-tooltip.component.html', | ||
styleUrl: './orcid-badge-and-tooltip.component.scss', | ||
}) | ||
export class OrcidBadgeAndTooltipComponent implements OnInit { | ||
|
||
/** | ||
* The ORCID value to be displayed. | ||
*/ | ||
@Input() orcid: MetadataValue; | ||
|
||
/** | ||
* The timestamp indicating when the ORCID was authenticated. | ||
*/ | ||
@Input() authenticatedTimestamp: MetadataValue; | ||
|
||
/** | ||
* The tooltip text to be displayed. | ||
*/ | ||
orcidTooltip: string; | ||
|
||
/** | ||
* Constructor to inject the TranslateService. | ||
* @param translateService - Service for translation. | ||
*/ | ||
constructor( | ||
private translateService: TranslateService, | ||
) { } | ||
|
||
/** | ||
* Initializes the component. | ||
* Sets the tooltip text based on the presence of the authenticated timestamp. | ||
*/ | ||
ngOnInit() { | ||
this.orcidTooltip = this.authenticatedTimestamp ? | ||
this.translateService.instant('person.orcid-tooltip.authenticated', { orcid: this.orcid.value }) : | ||
this.translateService.instant('person.orcid-tooltip.not-authenticated', { orcid: this.orcid.value }); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters