|
| 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 | +} |
0 commit comments