Skip to content

Commit d4e6795

Browse files
FrancescoMolinaroAndrea Barbasso
authored andcommitted
Merged in task/dspace-cris-2025_02_x/DSC-2874 (pull request DSpace#4514)
[DSC-2874] fix item statistics missing menu, change translation - cherry picked from [UXP-484] Approved-by: Andrea Barbasso
2 parents 374fbdf + 01fa599 commit d4e6795

4 files changed

Lines changed: 114 additions & 0 deletions

File tree

src/app/app.menus.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { HealthMenuProvider } from './shared/menu/providers/health.menu';
2525
import { ImportMenuProvider } from './shared/menu/providers/import.menu';
2626
import { ClaimMenuProvider } from './shared/menu/providers/item-claim.menu';
2727
import { OrcidMenuProvider } from './shared/menu/providers/item-orcid.menu';
28+
import { ItemStatisticsMenuProvider } from './shared/menu/providers/item-statistics.menu';
2829
import { VersioningMenuProvider } from './shared/menu/providers/item-versioning.menu';
2930
import { MetadataCmsMenuProvider } from './shared/menu/providers/metadata-cms.menu';
3031
import { NewMenuProvider } from './shared/menu/providers/new.menu';
@@ -58,6 +59,7 @@ export const MENUS = buildMenuStructure({
5859
CommunityListMenuProvider,
5960
ExploreMenuProvider,
6061
StatisticsMenuProvider,
62+
ItemStatisticsMenuProvider,
6163
],
6264
[MenuID.ADMIN]: [
6365
AdminCommunityListMenuProvider,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
4+
import { Item } from '../../../core/shared/item.model';
5+
import { ITEM } from '../../../core/shared/item.resource-type';
6+
import { MenuItemType } from '../menu-item-type.model';
7+
import { PartialMenuSection } from '../menu-provider.model';
8+
import { ItemStatisticsMenuProvider } from './item-statistics.menu';
9+
10+
describe('ItemStatisticsMenuProvider', () => {
11+
12+
const item: Item = Object.assign(new Item(), {
13+
id: 'item-uuid',
14+
uuid: 'item-uuid',
15+
type: ITEM.value,
16+
_links: {
17+
self: {
18+
href: 'self-link',
19+
},
20+
},
21+
});
22+
23+
const expectedSections: PartialMenuSection[] = [
24+
{
25+
id: 'statistics_item_:item-uuid',
26+
active: true,
27+
visible: true,
28+
parentID: 'statistics',
29+
model: {
30+
type: MenuItemType.LINK,
31+
text: 'menu.section.statistics.item',
32+
link: '/statistics/items/item-uuid/',
33+
},
34+
},
35+
];
36+
37+
let provider: ItemStatisticsMenuProvider;
38+
39+
beforeEach(() => {
40+
TestBed.configureTestingModule({
41+
providers: [ItemStatisticsMenuProvider],
42+
});
43+
provider = TestBed.inject(ItemStatisticsMenuProvider);
44+
});
45+
46+
it('should be created', () => {
47+
expect(provider).toBeTruthy();
48+
});
49+
50+
describe('getSectionsForContext', () => {
51+
it('should return the expected item statistics section', (done) => {
52+
provider.getSectionsForContext(item).subscribe((sections) => {
53+
expect(sections).toEqual(expectedSections);
54+
done();
55+
});
56+
});
57+
});
58+
59+
describe('isApplicable', () => {
60+
it('should return true for an item', () => {
61+
expect((provider as any).isApplicable(item)).toBeTrue();
62+
});
63+
64+
it('should return false for a non-item dspace object', () => {
65+
const dso = Object.assign(new DSpaceObject(), { id: 'test-id' });
66+
expect((provider as any).isApplicable(dso)).toBeFalse();
67+
});
68+
});
69+
});
70+
71+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Injectable } from '@angular/core';
2+
import {
3+
Observable,
4+
of,
5+
} from 'rxjs';
6+
7+
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
8+
import { Item } from '../../../core/shared/item.model';
9+
import { MenuItemType } from '../menu-item-type.model';
10+
import { PartialMenuSection } from '../menu-provider.model';
11+
import { DSpaceObjectPageMenuProvider } from './helper-providers/dso.menu';
12+
13+
/**
14+
* Menu provider to create the item-specific statistics option in the public statistics menu.
15+
*/
16+
@Injectable()
17+
export class ItemStatisticsMenuProvider extends DSpaceObjectPageMenuProvider {
18+
19+
public getSectionsForContext(dso: DSpaceObject): Observable<PartialMenuSection[]> {
20+
return of([
21+
{
22+
id: `statistics_item_:${dso.id}`,
23+
active: true,
24+
visible: true,
25+
parentID: 'statistics',
26+
model: {
27+
type: MenuItemType.LINK,
28+
text: 'menu.section.statistics.item',
29+
link: `/statistics/items/${dso.id}/`,
30+
},
31+
},
32+
]);
33+
}
34+
35+
protected isApplicable(dso: DSpaceObject): boolean {
36+
return dso instanceof Item;
37+
}
38+
}
39+

src/assets/i18n/en.json5

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

46724672
"menu.section.statistics": "Statistics",
46734673

4674+
"menu.section.statistics.item": "Item Statistics",
4675+
46744676
"menu.section.statistics.workflow": "Workflow",
46754677

46764678
"menu.section.statistics.login": "Login",

0 commit comments

Comments
 (0)