|
| 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 { |
| 11 | + combineLatest as observableCombineLatest, |
| 12 | + Observable, |
| 13 | +} from 'rxjs'; |
| 14 | +import { map } from 'rxjs/operators'; |
| 15 | + |
| 16 | +import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; |
| 17 | +import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; |
| 18 | +import { LinkMenuItemModel } from '../menu-item/models/link.model'; |
| 19 | +import { TextMenuItemModel } from '../menu-item/models/text.model'; |
| 20 | +import { MenuItemType } from '../menu-item-type.model'; |
| 21 | +import { PartialMenuSection } from '../menu-provider.model'; |
| 22 | +import { AbstractExpandableMenuProvider } from './helper-providers/expandable-menu-provider'; |
| 23 | + |
| 24 | +/** |
| 25 | + * Menu provider to create the "COAR Notify" menu (and subsections) in the admin sidebar |
| 26 | + */ |
| 27 | +@Injectable() |
| 28 | +export class CoarNotifyMenuProvider extends AbstractExpandableMenuProvider { |
| 29 | + constructor( |
| 30 | + protected authorizationService: AuthorizationDataService, |
| 31 | + ) { |
| 32 | + super(); |
| 33 | + } |
| 34 | + |
| 35 | + getSubSections(): Observable<PartialMenuSection[]> { |
| 36 | + return observableCombineLatest([ |
| 37 | + this.authorizationService.isAuthorized(FeatureID.CoarNotifyEnabled), |
| 38 | + this.authorizationService.isAuthorized(FeatureID.AdministratorOf), |
| 39 | + ]).pipe( |
| 40 | + map(([isCoarNotifyEnabled, isSiteAdmin]: [boolean, boolean]) => { |
| 41 | + return [{ |
| 42 | + visible: isSiteAdmin && isCoarNotifyEnabled, |
| 43 | + model: { |
| 44 | + type: MenuItemType.LINK, |
| 45 | + text: 'menu.section.notify_dashboard', |
| 46 | + link: '/admin/notify-dashboard', |
| 47 | + } as LinkMenuItemModel, |
| 48 | + }, |
| 49 | + /* LDN Services */ |
| 50 | + { |
| 51 | + visible: isSiteAdmin && isCoarNotifyEnabled, |
| 52 | + model: { |
| 53 | + type: MenuItemType.LINK, |
| 54 | + text: 'menu.section.services', |
| 55 | + link: '/admin/ldn/services', |
| 56 | + } as LinkMenuItemModel, |
| 57 | + }]; |
| 58 | + })); |
| 59 | + } |
| 60 | + |
| 61 | + getTopSection(): Observable<PartialMenuSection> { |
| 62 | + return observableCombineLatest([ |
| 63 | + this.authorizationService.isAuthorized(FeatureID.CoarNotifyEnabled), |
| 64 | + this.authorizationService.isAuthorized(FeatureID.AdministratorOf), |
| 65 | + ]).pipe( |
| 66 | + map(([isCoarNotifyEnabled, isSiteAdmin]: [boolean, boolean]) => { |
| 67 | + return { |
| 68 | + visible: isSiteAdmin && isCoarNotifyEnabled, |
| 69 | + model: { |
| 70 | + type: MenuItemType.TEXT, |
| 71 | + text: 'menu.section.coar_notify', |
| 72 | + } as TextMenuItemModel, |
| 73 | + icon: 'inbox', |
| 74 | + }; |
| 75 | + })); |
| 76 | + } |
| 77 | +} |
0 commit comments