Skip to content

Commit 244410e

Browse files
author
Andrea Barbasso
committed
[DSC-2676] migrate menu voices
1 parent d62e009 commit 244410e

9 files changed

Lines changed: 279 additions & 3 deletions

src/app/app.menus.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import { StatisticsMenuProvider } from './shared/menu/providers/statistics.menu'
3333
import { SystemWideAlertMenuProvider } from './shared/menu/providers/system-wide-alert.menu';
3434
import { WithdrawnReinstateItemMenuProvider } from './shared/menu/providers/withdrawn-reinstate-item.menu';
3535
import { WorkflowMenuProvider } from './shared/menu/providers/workflow.menu';
36+
import { ExploreMenuProvider } from './shared/menu/providers/explore.menu';
37+
import { UserAgreementMenuProvider } from './shared/menu/providers/user-agreement.menu';
38+
import { MetadataCmsMenuProvider } from './shared/menu/providers/metadata-cms.menu';
3639

3740
/**
3841
* Represents and builds the menu structure for the three available menus (public navbar, admin sidebar and the dso edit
@@ -53,7 +56,7 @@ import { WorkflowMenuProvider } from './shared/menu/providers/workflow.menu';
5356
export const MENUS = buildMenuStructure({
5457
[MenuID.PUBLIC]: [
5558
CommunityListMenuProvider,
56-
BrowseMenuProvider,
59+
ExploreMenuProvider,
5760
StatisticsMenuProvider,
5861
],
5962
[MenuID.ADMIN]: [
@@ -72,6 +75,8 @@ export const MENUS = buildMenuStructure({
7275
HealthMenuProvider,
7376
SystemWideAlertMenuProvider,
7477
CoarNotifyMenuProvider,
78+
UserAgreementMenuProvider,
79+
MetadataCmsMenuProvider,
7580
],
7681
[MenuID.DSO_EDIT]: [
7782
DsoOptionMenuProvider.withSubs([

src/app/shared/menu/providers/community-list.menu.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('CommunityListMenuProvider', () => {
1818
visible: true,
1919
model: {
2020
type: MenuItemType.LINK,
21-
text: `menu.section.browse_global_communities_and_collections`,
21+
text: `menu.section.communities_and_collections`,
2222
link: `/community-list`,
2323
},
2424
icon: 'diagram-project',

src/app/shared/menu/providers/community-list.menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class CommunityListMenuProvider extends AbstractMenuProvider {
2929
visible: true,
3030
model: {
3131
type: MenuItemType.LINK,
32-
text: `menu.section.browse_global_communities_and_collections`,
32+
text: `menu.section.communities_and_collections`,
3333
link: `/community-list`,
3434
},
3535
icon: 'diagram-project',
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
11+
import { APP_CONFIG } from '../../../../config/app-config.interface';
12+
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
13+
import { createPaginatedList } from '../../testing/utils.test';
14+
import { ExploreMenuProvider } from './explore.menu';
15+
import { environment } from '../../../../environments/environment';
16+
import { SectionDataService } from '../../../core/layout/section-data.service';
17+
18+
describe('ExploreMenuProvider', () => {
19+
20+
let provider: ExploreMenuProvider;
21+
let sectionDataServiceStub = {
22+
findVisibleSections: () => createSuccessfulRemoteDataObject$(createPaginatedList([])),
23+
}
24+
25+
beforeEach(() => {
26+
TestBed.configureTestingModule({
27+
providers: [
28+
ExploreMenuProvider,
29+
{ provide: APP_CONFIG, useValue: environment },
30+
{ provide: SectionDataService, useValue: sectionDataServiceStub },
31+
],
32+
});
33+
provider = TestBed.inject(ExploreMenuProvider);
34+
});
35+
36+
it('should be created', () => {
37+
expect(provider).toBeTruthy();
38+
});
39+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { Injectable } from '@angular/core';
10+
import { Observable } from 'rxjs';
11+
import { map } from 'rxjs/operators';
12+
13+
import { PaginatedList } from '../../../core/data/paginated-list.model';
14+
import { RemoteData } from '../../../core/data/remote-data';
15+
import { getFirstSucceededRemoteData } from '../../../core/shared/operators';
16+
import { MenuItemType } from '../menu-item-type.model';
17+
import { AbstractMenuProvider, PartialMenuSection } from '../menu-provider.model';
18+
import { SectionDataService } from '../../../core/layout/section-data.service';
19+
import { Section } from '../../../core/layout/models/section.model';
20+
21+
/**
22+
* Menu provider to create the explore menu sections in the public navbar
23+
*/
24+
@Injectable()
25+
export class ExploreMenuProvider extends AbstractMenuProvider {
26+
constructor(
27+
protected sectionDataService: SectionDataService,
28+
) {
29+
super();
30+
}
31+
32+
/**
33+
* Retrieves subsections by fetching the browse definitions from the backend and mapping them to partial menu sections.
34+
*/
35+
getSections(): Observable<PartialMenuSection[]> {
36+
return this.sectionDataService.findVisibleSections().pipe(
37+
getFirstSucceededRemoteData(),
38+
map((rd: RemoteData<PaginatedList<Section>>) => {
39+
return [
40+
...rd.payload.page.map((browseDef) => {
41+
return {
42+
visible: true,
43+
model: {
44+
type: MenuItemType.LINK,
45+
text: `menu.section.explore_${browseDef.id}`,
46+
link: `/explore/${browseDef.id}`,
47+
},
48+
};
49+
}),
50+
];
51+
}),
52+
);
53+
}
54+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
import { MetadataCmsMenuProvider } from './metadata-cms.menu';
11+
import { AuthorizationDataServiceStub } from '../../testing/authorization-service.stub';
12+
import { of } from 'rxjs';
13+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
14+
15+
describe('MetadataCmsMenuProvider', () => {
16+
17+
let provider: MetadataCmsMenuProvider;
18+
let authorizationServiceStub = new AuthorizationDataServiceStub();
19+
20+
beforeEach(() => {
21+
spyOn(authorizationServiceStub, 'isAuthorized').and.returnValue(
22+
of(true),
23+
);
24+
TestBed.configureTestingModule({
25+
providers: [
26+
MetadataCmsMenuProvider,
27+
{ provide: AuthorizationDataService, useValue: authorizationServiceStub },
28+
],
29+
});
30+
provider = TestBed.inject(MetadataCmsMenuProvider);
31+
});
32+
33+
it('should be created', () => {
34+
expect(provider).toBeTruthy();
35+
});
36+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { Injectable } from '@angular/core';
10+
import { combineLatest, Observable } from 'rxjs';
11+
import { map } from 'rxjs/operators';
12+
13+
import { MenuItemType } from '../menu-item-type.model';
14+
import { AbstractMenuProvider, PartialMenuSection } from '../menu-provider.model';
15+
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
16+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
17+
18+
/**
19+
* Menu provider to create the user agreement menu sections in the public navbar
20+
*/
21+
@Injectable()
22+
export class MetadataCmsMenuProvider extends AbstractMenuProvider {
23+
constructor(
24+
protected authorizationService: AuthorizationDataService,
25+
) {
26+
super();
27+
}
28+
29+
/**
30+
* Retrieves subsections by fetching the browse definitions from the backend and mapping them to partial menu sections.
31+
*/
32+
getSections(): Observable<PartialMenuSection[]> {
33+
return combineLatest([
34+
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
35+
]).pipe(
36+
map(([isSiteAdmin]) => {
37+
return [
38+
{
39+
id: 'metadata_cms_edit',
40+
active: false,
41+
visible: isSiteAdmin,
42+
model: {
43+
type: MenuItemType.LINK,
44+
text: 'menu.section.cms_metadata_edit',
45+
link: '/admin/edit-cms-metadata',
46+
},
47+
icon: 'edit',
48+
},
49+
] as PartialMenuSection[];
50+
}),
51+
);
52+
}
53+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
import { UserAgreementMenuProvider } from './user-agreement.menu';
11+
import { AuthorizationDataServiceStub } from '../../testing/authorization-service.stub';
12+
import { of } from 'rxjs';
13+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
14+
15+
describe('UserAgreementMenuProvider', () => {
16+
17+
let provider: UserAgreementMenuProvider;
18+
let authorizationServiceStub = new AuthorizationDataServiceStub();
19+
20+
beforeEach(() => {
21+
spyOn(authorizationServiceStub, 'isAuthorized').and.returnValue(
22+
of(true),
23+
);
24+
TestBed.configureTestingModule({
25+
providers: [
26+
UserAgreementMenuProvider,
27+
{ provide: AuthorizationDataService, useValue: authorizationServiceStub },
28+
],
29+
});
30+
provider = TestBed.inject(UserAgreementMenuProvider);
31+
});
32+
33+
it('should be created', () => {
34+
expect(provider).toBeTruthy();
35+
});
36+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { Injectable } from '@angular/core';
10+
import { combineLatest, Observable } from 'rxjs';
11+
import { map } from 'rxjs/operators';
12+
13+
import { MenuItemType } from '../menu-item-type.model';
14+
import { AbstractMenuProvider, PartialMenuSection } from '../menu-provider.model';
15+
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
16+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
17+
18+
/**
19+
* Menu provider to create the user agreement menu sections in the public navbar
20+
*/
21+
@Injectable()
22+
export class UserAgreementMenuProvider extends AbstractMenuProvider {
23+
constructor(
24+
protected authorizationService: AuthorizationDataService,
25+
) {
26+
super();
27+
}
28+
29+
/**
30+
* Retrieves subsections by fetching the browse definitions from the backend and mapping them to partial menu sections.
31+
*/
32+
getSections(): Observable<PartialMenuSection[]> {
33+
return combineLatest([
34+
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
35+
]).pipe(
36+
map(([isSiteAdmin]) => {
37+
return [
38+
{
39+
id: 'user_agreement_edit',
40+
active: false,
41+
visible: isSiteAdmin,
42+
model: {
43+
type: MenuItemType.LINK,
44+
text: 'menu.section.edit_user_agreement',
45+
link: '/admin/edit-user-agreement',
46+
},
47+
icon: 'list-alt',
48+
},
49+
] as PartialMenuSection[];
50+
}),
51+
);
52+
}
53+
}

0 commit comments

Comments
 (0)