Skip to content

Commit d5f70ee

Browse files
nikunj59davide-negretti
authored andcommitted
[DSC-854] implemented nested menu for menu response
1 parent f967f23 commit d5f70ee

4 files changed

Lines changed: 144 additions & 11 deletions

File tree

src/app/core/layout/models/section.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export class Section extends CacheableObject {
2929
@autoserialize
3030
componentRows: SectionComponent[][];
3131

32+
nestedSections: Section[];
33+
3234
/**
3335
* The {@link HALLink}s for this section
3436
*/

src/app/menu.resolver.spec.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,41 @@ const MENU_STATE = {
2525
id: 'some menu'
2626
};
2727
const EXPLORE_SECTIONS_DEFINITIONS = [
28+
{ id: 'definition1' },
29+
{
30+
id: 'definition2',
31+
nestedSections: [
32+
{ id: 'nested_definition1' },
33+
{ id: 'nested_definition2' }
34+
]
35+
},
36+
{ id: 'definition3' },
37+
];
38+
39+
const ALL_FLAT_MENUS = [
2840
{ id: 'definition1' },
2941
{ id: 'definition2' },
3042
{ id: 'definition3' },
3143
];
44+
const ALL_NESTED_MENUS = [
45+
{
46+
id: 'definition1',
47+
nestedSections: [
48+
{ id: 'nested_definition1' },
49+
]
50+
},{
51+
id: 'definition2',
52+
nestedSections: [
53+
{ id: 'nested_definition2' },
54+
]
55+
},{
56+
id: 'definition3',
57+
nestedSections: [
58+
{ id: 'nested_definition3' },
59+
]
60+
}
61+
];
62+
const NO_MENUS = [];
3263

3364
describe('MenuResolver', () => {
3465
let resolver: MenuResolver;
@@ -130,11 +161,80 @@ describe('MenuResolver', () => {
130161
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.PUBLIC, jasmine.objectContaining({
131162
id: 'explore_definition2', visible: true,
132163
}));
164+
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.PUBLIC, jasmine.objectContaining({
165+
id: 'explore_nested_definition2',
166+
parentID: 'explore_definition2',
167+
active: false,
168+
visible: true
169+
}));
133170
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.PUBLIC, jasmine.objectContaining({
134171
id: 'explore_definition3', visible: true,
135172
}));
136173
});
137174
});
175+
176+
describe('handle menus', () => {
177+
it('should show all flat menus', () => {
178+
sectionsService.findVisibleSections.and.returnValue(
179+
createSuccessfulRemoteDataObject$(createPaginatedList(ALL_FLAT_MENUS))
180+
);
181+
resolver.createPublicMenu$().subscribe();
182+
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.PUBLIC, jasmine.objectContaining({
183+
id: 'explore_definition1', visible: true,
184+
}));
185+
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.PUBLIC, jasmine.objectContaining({
186+
id: 'explore_definition2', visible: true,
187+
}));
188+
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.PUBLIC, jasmine.objectContaining({
189+
id: 'explore_definition3', visible: true,
190+
}));
191+
});
192+
193+
it('should show all nested menus', () => {
194+
sectionsService.findVisibleSections.and.returnValue(
195+
createSuccessfulRemoteDataObject$(createPaginatedList(ALL_NESTED_MENUS))
196+
);
197+
resolver.createPublicMenu$().subscribe();
198+
expect(menuService.addSection).toHaveBeenCalledWith(
199+
MenuID.PUBLIC,
200+
jasmine.objectContaining({
201+
id: 'explore_nested_definition1',
202+
parentID: 'explore_definition1',
203+
active: false,
204+
visible: true
205+
})
206+
);
207+
expect(menuService.addSection).toHaveBeenCalledWith(
208+
MenuID.PUBLIC,
209+
jasmine.objectContaining({
210+
id: 'explore_nested_definition2',
211+
parentID: 'explore_definition2',
212+
active: false,
213+
visible: true
214+
})
215+
);
216+
expect(menuService.addSection).toHaveBeenCalledWith(
217+
MenuID.PUBLIC,
218+
jasmine.objectContaining({
219+
id: 'explore_nested_definition3',
220+
parentID: 'explore_definition3',
221+
active: false,
222+
visible: true
223+
})
224+
);
225+
});
226+
227+
it('should show no menus', () => {
228+
sectionsService.findVisibleSections.and.returnValue(
229+
createSuccessfulRemoteDataObject$(createPaginatedList(NO_MENUS))
230+
);
231+
resolver.createPublicMenu$().subscribe();
232+
expect(menuService.addSection).toHaveBeenCalledWith(
233+
MenuID.PUBLIC,
234+
jasmine.objectContaining({})
235+
);
236+
});
237+
});
138238
});
139239

140240
describe('createAdminMenu$', () => {

src/app/menu.resolver.ts

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,44 @@ export class MenuResolver implements Resolve<boolean> {
123123
).subscribe( (sectionDefListRD: RemoteData<PaginatedList<Section>>) => {
124124
if (sectionDefListRD.hasSucceeded) {
125125
sectionDefListRD.payload.page.forEach((section) => {
126-
menuList.push({
126+
let parentMenu: any = {
127127
id: `explore_${section.id}`,
128128
active: false,
129129
visible: true,
130-
model: {
131-
type: MenuItemType.LINK,
132-
text: `menu.section.explore_${section.id}`,
133-
link: `/explore/${section.id}`
134-
} as LinkMenuItemModel
135-
});
136-
130+
};
131+
if (section.nestedSections) {
132+
section.nestedSections.forEach((nested) => {
133+
menuList.push({
134+
id: `explore_${nested.id}`,
135+
parentID: `explore_${section.id}`,
136+
active: false,
137+
visible: true,
138+
model: {
139+
type: MenuItemType.LINK,
140+
text: `menu.section.explore_${nested.id}`,
141+
link: `/explore/${nested.id}`
142+
} as LinkMenuItemModel
143+
});
144+
});
145+
parentMenu = {
146+
...parentMenu,
147+
index: 1,
148+
model: {
149+
type: MenuItemType.TEXT,
150+
text: `menu.section.explore_${section.id}`
151+
} as TextMenuItemModel,
152+
};
153+
} else {
154+
parentMenu = {
155+
...parentMenu,
156+
model: {
157+
type: MenuItemType.LINK,
158+
text: `menu.section.explore_${section.id}`,
159+
link: `/explore/${section.id}`
160+
} as LinkMenuItemModel
161+
};
162+
}
163+
menuList.push(parentMenu);
137164
});
138165
}
139166
menuList.forEach((menuSection) => this.menuService.addSection(MenuID.PUBLIC, Object.assign(menuSection, {

src/assets/i18n/en.json5

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,9 @@
20782078

20792079
"explore.infrastructure.breadcrumbs": "Infrastructure",
20802080

2081-
"explore.fundings.breadcrumbs": "Projects",
2081+
"explore.fundings.breadcrumbs": "Fundings",
2082+
2083+
"explore.projects.breadcrumbs": "Projects",
20822084

20832085
"explore.fundings_and_projects.breadcrumbs": "Projects",
20842086

@@ -3476,9 +3478,11 @@
34763478

34773479
"menu.section.explore_orgunits": "Organizations",
34783480

3479-
"menu.section.explore_fundings": "Projects",
3481+
"menu.section.explore_fundings": "Fundings",
3482+
3483+
"menu.section.explore_projects": "Projects",
34803484

3481-
"menu.section.explore_fundings_and_projects": "Projects",
3485+
"menu.section.explore_fundings_and_projects": "Fundings & Projects",
34823486

34833487
"menu.section.communities_and_collections": "Communities & Collections",
34843488

0 commit comments

Comments
 (0)