Skip to content

Commit 4b3d7e8

Browse files
committed
Merge branch 'refactor-menu-resolvers-7.6' into refactor-menu-resolvers-9.0
2 parents 2c49c04 + 276452e commit 4b3d7e8

4 files changed

Lines changed: 50 additions & 46 deletions

File tree

src/app/shared/menu/providers/helper-providers/dso.menu.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('DSpaceObjectPageMenuProvider', () => {
1414
const item: Item = Object.assign(new Item(), {
1515
uuid: 'test-item-uuid',
1616
type: ITEM.value,
17-
_links: { self: { href: 'self-link' } },
17+
_links: {self: {href: 'self-link'}},
1818
metadata: {
1919
'dc.title': [{
2020
'value': 'Untyped Item',
@@ -25,7 +25,7 @@ describe('DSpaceObjectPageMenuProvider', () => {
2525
const item2: Item = Object.assign(new Item(), {
2626
uuid: 'test-item2-uuid',
2727
type: ITEM.value,
28-
_links: { self: { href: 'self-link' } },
28+
_links: {self: {href: 'self-link'}},
2929
metadata: {
3030
'dc.title': [{
3131
'value': 'Untyped Item 2',
@@ -36,7 +36,7 @@ describe('DSpaceObjectPageMenuProvider', () => {
3636
const person: Item = Object.assign(new Item(), {
3737
uuid: 'test-uuid',
3838
type: ITEM.value,
39-
_links: { self: { href: 'self-link' } },
39+
_links: {self: {href: 'self-link'}},
4040
metadata: {
4141
'dc.title': [{
4242
'value': 'Person Entity',
@@ -50,7 +50,7 @@ describe('DSpaceObjectPageMenuProvider', () => {
5050
const collection: Collection = Object.assign(new Collection(), {
5151
uuid: 'test-collection-uuid',
5252
type: COLLECTION.value,
53-
_links: { self: { href: 'self-link' } },
53+
_links: {self: {href: 'self-link'}},
5454
metadata: {
5555
'dc.title': [{
5656
'value': 'Collection',
@@ -75,33 +75,33 @@ describe('DSpaceObjectPageMenuProvider', () => {
7575

7676
describe('getRouteContext', () => {
7777
it('should get the dso from the route', (done) => {
78-
const route = { data: { dso: createSuccessfulRemoteDataObject(item) } } as any;
78+
const route = {data: {dso: createSuccessfulRemoteDataObject(item)}} as any;
7979

8080
provider.getRouteContext(route, undefined).subscribe((dso) => {
8181
expect(dso).toEqual(item);
8282
done();
8383
});
8484
});
8585

86-
it('return undefined when no DSO is present on the current route', (done) => {
86+
it('return the first parent DSO when no DSO is present on the current route', (done) => {
8787
const route = {
8888
data: {},
8989
parent: {
9090
data: {},
9191
parent: {
92-
data: { dso: createSuccessfulRemoteDataObject(item) },
93-
parent: { data: { dso: createSuccessfulRemoteDataObject(item2) } },
92+
data: {dso: createSuccessfulRemoteDataObject(item)},
93+
parent: {data: {dso: createSuccessfulRemoteDataObject(item2)}},
9494
},
9595
},
9696
} as any;
9797

9898
provider.getRouteContext(route, undefined).subscribe((dso) => {
99-
expect(dso).toBeUndefined();
99+
expect(dso).toEqual(item);
100100
done();
101101
});
102102
});
103103
it('should return undefined when no dso is found in the route', (done) => {
104-
const route = { data: {}, parent: { data: {}, parent: { data: {}, parent: { data: {} } } } } as any;
104+
const route = {data: {}, parent: {data: {}, parent: {data: {}, parent: {data: {}}}}} as any;
105105

106106
provider.getRouteContext(route, undefined).subscribe((dso) => {
107107
expect(dso).toBeUndefined();

src/app/shared/menu/providers/helper-providers/dso.menu.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import { RemoteData } from '../../../../core/data/remote-data';
1818
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
19-
import { hasValue } from '../../../empty.util';
19+
import { hasNoValue, hasValue } from '../../../empty.util';
2020
import { AbstractRouteContextMenuProvider } from './route-context.menu';
2121

2222
/**
@@ -28,7 +28,13 @@ export abstract class DSpaceObjectPageMenuProvider extends AbstractRouteContextM
2828
* Retrieve the dso from the current route data
2929
*/
3030
public getRouteContext(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<DSpaceObject | undefined> {
31-
const dsoRD: RemoteData<DSpaceObject> = route.data.dso;
31+
let dsoRD: RemoteData<DSpaceObject> = route.data.dso;
32+
// Check if one of the parent routes has a DSO
33+
while (hasValue(route.parent) && hasNoValue(dsoRD)) {
34+
route = route.parent;
35+
dsoRD = route.data.dso;
36+
}
37+
3238
if (hasValue(dsoRD) && dsoRD.hasSucceeded && hasValue(dsoRD.payload)) {
3339
return of(dsoRD.payload);
3440
} else {

src/app/shared/menu/providers/statistics.menu.ts

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,31 @@
77
*/
88

99
import { Injectable } from '@angular/core';
10-
import {
11-
ActivatedRouteSnapshot,
12-
RouterStateSnapshot,
13-
} from '@angular/router';
14-
import {
15-
combineLatest,
16-
map,
17-
Observable,
18-
of,
19-
} from 'rxjs';
10+
import { combineLatest, map, Observable, } from 'rxjs';
2011

21-
import { getDSORoute } from '../../../app-routing-paths';
2212
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
2313
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
24-
import { RemoteData } from '../../../core/data/remote-data';
25-
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
26-
import {
27-
hasNoValue,
28-
hasValue,
29-
} from '../../empty.util';
14+
import { hasValue, } from '../../empty.util';
3015
import { MenuItemType } from '../menu-item-type.model';
3116
import { PartialMenuSection } from '../menu-provider.model';
32-
import { AbstractRouteContextMenuProvider } from './helper-providers/route-context.menu';
17+
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
18+
import { getDSORoute } from '../../../app-routing-paths';
19+
import { DSpaceObjectPageMenuProvider } from './helper-providers/dso.menu';
3320

3421
/**
3522
* Menu provider to create the statistics menu section depending on the page it is on
3623
* When the user is on a DSO page or a derivative, this menu section will contain a link to the statistics of that DSO
3724
* In all other cases the menu section will contain a link to the repository wide statistics
3825
*/
3926
@Injectable()
40-
export class StatisticsMenuProvider extends AbstractRouteContextMenuProvider<DSpaceObject> {
27+
export class StatisticsMenuProvider extends DSpaceObjectPageMenuProvider {
28+
4129
constructor(
4230
protected authorizationService: AuthorizationDataService,
4331
) {
4432
super();
4533
}
4634

47-
public getRouteContext(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<DSpaceObject> {
48-
let dsoRD: RemoteData<DSpaceObject> = route.data.dso;
49-
// Check if one of the parent routes has a DSO
50-
while (hasValue(route.parent) && hasNoValue(dsoRD)) {
51-
route = route.parent;
52-
dsoRD = route.data.dso;
53-
}
54-
55-
if (hasValue(dsoRD) && dsoRD.hasSucceeded && hasValue(dsoRD.payload)) {
56-
return of(dsoRD.payload);
57-
} else {
58-
return of(undefined);
59-
}
60-
}
61-
6235
public getSectionsForContext(dso: DSpaceObject): Observable<PartialMenuSection[]> {
6336
return combineLatest([
6437
this.authorizationService.isAuthorized(FeatureID.CanViewUsageStatistics, dso?._links.self.href),
@@ -88,4 +61,9 @@ export class StatisticsMenuProvider extends AbstractRouteContextMenuProvider<DSp
8861
}),
8962
);
9063
}
64+
65+
protected isApplicable(dso: DSpaceObject): boolean {
66+
return true;
67+
}
68+
9169
}

src/assets/i18n/en.json5

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,8 @@
13261326

13271327
"collection.page.news": "News",
13281328

1329+
"collection.page.options": "Options",
1330+
13291331
"collection.search.results.head": "Search Results",
13301332

13311333
"collection.select.confirm": "Confirm selected",
@@ -1562,6 +1564,8 @@
15621564

15631565
"community.page.news": "News",
15641566

1567+
"community.page.options": "Options",
1568+
15651569
"community.all-lists.head": "Subcommunities and Collections",
15661570

15671571
"community.search.results.head": "Search Results",
@@ -2764,6 +2768,8 @@
27642768

27652769
"item.page.link.simple": "Simple item page",
27662770

2771+
"item.page.options": "Options",
2772+
27672773
"item.page.orcid.title": "ORCID",
27682774

27692775
"item.page.orcid.tooltip": "Open ORCID setting page",
@@ -3092,6 +3098,8 @@
30923098

30933099
"journal.page.publisher": "Publisher",
30943100

3101+
"journal.page.options": "Options",
3102+
30953103
"journal.page.titleprefix": "Journal: ",
30963104

30973105
"journal.search.results.head": "Journal Search Results",
@@ -3116,6 +3124,8 @@
31163124

31173125
"journalissue.page.number": "Number",
31183126

3127+
"journalissue.page.options": "Options",
3128+
31193129
"journalissue.page.titleprefix": "Journal Issue: ",
31203130

31213131
"journalissue.search.results.head": "Journal Issue Search Results",
@@ -3128,6 +3138,8 @@
31283138

31293139
"journalvolume.page.issuedate": "Issue Date",
31303140

3141+
"journalvolume.page.options": "Options",
3142+
31313143
"journalvolume.page.titleprefix": "Journal Volume: ",
31323144

31333145
"journalvolume.page.volume": "Volume",
@@ -3678,6 +3690,8 @@
36783690

36793691
"orgunit.page.id": "ID",
36803692

3693+
"orgunit.page.options": "Options",
3694+
36813695
"orgunit.page.titleprefix": "Organizational Unit: ",
36823696

36833697
"orgunit.page.ror": "ROR Identifier",
@@ -3714,6 +3728,8 @@
37143728

37153729
"person.page.link.full": "Show all metadata",
37163730

3731+
"person.page.options": "Options",
3732+
37173733
"person.page.orcid": "ORCID",
37183734

37193735
"person.page.staffid": "Staff ID",
@@ -3956,6 +3972,8 @@
39563972

39573973
"project.page.keyword": "Keywords",
39583974

3975+
"project.page.options": "Options",
3976+
39593977
"project.page.status": "Status",
39603978

39613979
"project.page.titleprefix": "Research Project: ",
@@ -3976,6 +3994,8 @@
39763994

39773995
"publication.page.publisher": "Publisher",
39783996

3997+
"publication.page.options": "Options",
3998+
39793999
"publication.page.titleprefix": "Publication: ",
39804000

39814001
"publication.page.volume-title": "Volume Title",

0 commit comments

Comments
 (0)