Skip to content

Commit bf02ec0

Browse files
committed
[DSC-648] Add orcid context menu entry
1 parent ca5908e commit bf02ec0

8 files changed

Lines changed: 148 additions & 13 deletions

src/app/profile-page/profile-page.component.html

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@ <h3 class="mb-4">{{'profile.head' | translate}}</h3>
88
<div class="mb-4">
99
<ds-profile-page-researcher-form [user]="user" ></ds-profile-page-researcher-form>
1010
</div>
11+
<ds-suggestions-notification></ds-suggestions-notification>
1112
</div>
1213
</div>
1314
</ng-container>
14-
<div class="card mb-4">
15-
<div class="card-header">{{'profile.card.researcher' | translate}}</div>
16-
<div class="card-body">
17-
<div class="mb-4">
18-
<ds-profile-page-researcher-form [user]="user"></ds-profile-page-researcher-form>
19-
</div>
20-
<ds-suggestions-notification></ds-suggestions-notification>
21-
</div>
22-
</div>
2315
<div class="card mb-4">
2416
<div class="card-header">{{'profile.card.identify' | translate}}</div>
2517
<div class="card-body">

src/app/shared/context-menu/context-menu-entry-type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export enum ContextMenuEntryType {
1212
Subscriptions = 'subscriptions',
1313
Report = 'report',
1414
ItemVersion = 'itemversion',
15-
FullItem = 'fullitem'
15+
FullItem = 'fullitem',
16+
OrcidView = 'orcidview',
1617
}

src/app/shared/context-menu/context-menu.module.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { SharedModule } from './../shared.module';
2-
import { Version } from './../../core/shared/version.model';
32
import { NgModule } from '@angular/core';
43
import { CommonModule } from '@angular/common';
54
import { RouterModule } from '@angular/router';
@@ -23,6 +22,7 @@ import { SubscriptionsModule } from '../subscriptions/subscriptions.module';
2322
import { ItemVersionMenuComponent } from './item-version/item-version-menu.component';
2423
import { ItemVersionContainerComponent } from './item-version/item-version-container/item-version-container.component';
2524
import { FullItemMenuComponent } from './full-item/full-item-menu.component';
25+
import { OrcidViewPageMenuComponent } from './orcid-view-page/orcid-view-page-menu.component';
2626

2727
const COMPONENTS = [
2828
BulkImportMenuComponent,
@@ -39,7 +39,8 @@ const COMPONENTS = [
3939
SubscriptionMenuComponent,
4040
ItemVersionMenuComponent,
4141
ItemVersionContainerComponent,
42-
FullItemMenuComponent
42+
FullItemMenuComponent,
43+
OrcidViewPageMenuComponent
4344
];
4445

4546
const ENTRY_COMPONENTS = [
@@ -55,7 +56,8 @@ const ENTRY_COMPONENTS = [
5556
StatisticsMenuComponent,
5657
SubscriptionMenuComponent,
5758
ItemVersionMenuComponent,
58-
FullItemMenuComponent
59+
FullItemMenuComponent,
60+
OrcidViewPageMenuComponent
5961
];
6062

6163
const MODULE = [
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<button *ngIf="isAuthorized | async" class="dropdown-item"
2+
[routerLink]="['/items', contextMenuObject.id, 'edit']"
3+
[innerHTML]="'context-menu.actions.orcid-view' | translate">
4+
</button>

src/app/shared/context-menu/orcid-view-page/orcid-view-page-menu.component.scss

Whitespace-only changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { By } from '@angular/platform-browser';
3+
import { RouterTestingModule } from '@angular/router/testing';
4+
5+
import { of as observableOf } from 'rxjs';
6+
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
7+
import { TranslateModule } from '@ngx-translate/core';
8+
9+
import { OrcidViewPageMenuComponent } from './orcid-view-page-menu.component';
10+
import { DsoPageOrcidButtonComponent } from '../../dso-page/dso-page-orcid-button/dso-page-orcid-button.component';
11+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
12+
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
13+
import { Item } from '../../../core/shared/item.model';
14+
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
15+
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
16+
17+
describe('OrcidViewPageMenuComponent', () => {
18+
let component: DsoPageOrcidButtonComponent;
19+
let fixture: ComponentFixture<DsoPageOrcidButtonComponent>;
20+
21+
let authorizationService: AuthorizationDataService;
22+
let dso: DSpaceObject;
23+
24+
beforeEach(waitForAsync(() => {
25+
dso = Object.assign(new Item(), {
26+
id: 'test-item',
27+
_links: {
28+
self: { href: 'test-item-selflink' }
29+
}
30+
});
31+
authorizationService = jasmine.createSpyObj('authorizationService', {
32+
isAuthorized: observableOf(true)
33+
});
34+
TestBed.configureTestingModule({
35+
declarations: [DsoPageOrcidButtonComponent],
36+
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NgbModule],
37+
providers: [
38+
{ provide: 'contextMenuObjectProvider', useValue: dso },
39+
{ provide: 'contextMenuObjectTypeProvider', useValue: DSpaceObjectType.ITEM },
40+
{ provide: AuthorizationDataService, useValue: authorizationService }
41+
]
42+
}).compileComponents();
43+
}));
44+
45+
beforeEach(() => {
46+
fixture = TestBed.createComponent(DsoPageOrcidButtonComponent);
47+
component = fixture.componentInstance;
48+
fixture.detectChanges();
49+
});
50+
51+
it('should check the authorization of the current user', () => {
52+
expect(authorizationService.isAuthorized).toHaveBeenCalledWith(FeatureID.CanSynchronizeWithORCID, dso.self);
53+
});
54+
55+
describe('when the user is authorized', () => {
56+
beforeEach(() => {
57+
(authorizationService.isAuthorized as jasmine.Spy).and.returnValue(observableOf(true));
58+
component.ngOnInit();
59+
fixture.detectChanges();
60+
});
61+
62+
it('should render a link', () => {
63+
const link = fixture.debugElement.query(By.css('button'));
64+
expect(link).not.toBeNull();
65+
});
66+
});
67+
68+
describe('when the user is not authorized', () => {
69+
beforeEach(() => {
70+
(authorizationService.isAuthorized as jasmine.Spy).and.returnValue(observableOf(false));
71+
component.ngOnInit();
72+
fixture.detectChanges();
73+
});
74+
75+
it('should not render a link', () => {
76+
const link = fixture.debugElement.query(By.css('button'));
77+
expect(link).toBeNull();
78+
});
79+
});
80+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Component, Inject, OnInit } from '@angular/core';
2+
3+
import { BehaviorSubject } from 'rxjs';
4+
import { take } from 'rxjs/operators';
5+
6+
import { ContextMenuEntryComponent } from '../context-menu-entry.component';
7+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
8+
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
9+
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
10+
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
11+
import { ContextMenuEntryType } from '../context-menu-entry-type';
12+
import { rendersContextMenuEntriesForType } from '../context-menu.decorator';
13+
14+
@Component({
15+
selector: 'ds-orcid-view-page',
16+
templateUrl: './orcid-view-page-menu.component.html',
17+
styleUrls: ['./orcid-view-page-menu.component.scss']
18+
})
19+
@rendersContextMenuEntriesForType(DSpaceObjectType.ITEM)
20+
export class OrcidViewPageMenuComponent extends ContextMenuEntryComponent implements OnInit {
21+
22+
/**
23+
* The prefix of the route to the edit page (before the object's UUID, e.g. "items")
24+
*/
25+
pageRoute: string;
26+
27+
/**
28+
* Whether the current user is authorized to edit the DSpaceObject
29+
*/
30+
isAuthorized: BehaviorSubject<boolean> = new BehaviorSubject(false);
31+
32+
/**
33+
* Initialize instance variables
34+
*
35+
* @param {DSpaceObject} injectedContextMenuObject
36+
* @param {DSpaceObjectType} injectedContextMenuObjectType
37+
* @param {AuthorizationDataService} authorizationService
38+
*/
39+
constructor(
40+
@Inject('contextMenuObjectProvider') protected injectedContextMenuObject: DSpaceObject,
41+
@Inject('contextMenuObjectTypeProvider') protected injectedContextMenuObjectType: DSpaceObjectType,
42+
protected authorizationService: AuthorizationDataService
43+
) {
44+
super(injectedContextMenuObject, injectedContextMenuObjectType, ContextMenuEntryType.OrcidView);
45+
}
46+
47+
ngOnInit() {
48+
this.authorizationService.isAuthorized(FeatureID.CanSynchronizeWithORCID, this.contextMenuObject.self).pipe(take(1))
49+
.subscribe((isAuthorized: boolean) => {
50+
this.isAuthorized.next(isAuthorized);
51+
});
52+
}
53+
54+
}

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,8 @@
15161516

15171517
"context-menu.actions.edit-item-relationships.btn.projects": "Manage Projects",
15181518

1519+
"context-menu.actions.orcid-view": "Open ORCID setting page",
1520+
15191521
"context-menu.actions.statistics.btn": "Statistics",
15201522

15211523
"context-menu.actions.subscription.title": "Subscription",

0 commit comments

Comments
 (0)