-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathexport.menu.ts
More file actions
87 lines (82 loc) · 2.98 KB
/
export.menu.ts
File metadata and controls
87 lines (82 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
import { Injectable } from '@angular/core';
import { AuthorizationDataService } from '@dspace/core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '@dspace/core/data/feature-authorization/feature-id';
import {
METADATA_EXPORT_SCRIPT_NAME,
ScriptDataService,
} from '@dspace/core/data/processes/script-data.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import {
combineLatest as observableCombineLatest,
map,
Observable,
} from 'rxjs';
import { ExportBatchSelectorComponent } from '../../dso-selector/modal-wrappers/export-batch-selector/export-batch-selector.component';
import { ExportMetadataSelectorComponent } from '../../dso-selector/modal-wrappers/export-metadata-selector/export-metadata-selector.component';
import { MenuItemType } from '../menu-item-type.model';
import { PartialMenuSection } from '../menu-provider.model';
import { AbstractExpandableMenuProvider } from './helper-providers/expandable-menu-provider';
/**
* Menu provider to create the "Export" menu (and subsections) in the admin sidebar
*/
@Injectable()
export class ExportMenuProvider extends AbstractExpandableMenuProvider {
constructor(
protected authorizationService: AuthorizationDataService,
protected scriptDataService: ScriptDataService,
protected modalService: NgbModal,
) {
super();
}
public getTopSection(): Observable<PartialMenuSection> {
return this.authorizationService.isAuthorized(FeatureID.AdministratorOf).pipe(
map((isSiteAdmin) => ({
accessibilityHandle: 'export',
model: {
type: MenuItemType.TEXT,
text: 'menu.section.export',
},
icon: 'file-export',
visible: isSiteAdmin,
})),
);
}
public getSubSections(): Observable<PartialMenuSection[]> {
return observableCombineLatest([
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_EXPORT_SCRIPT_NAME),
]).pipe(
map(([authorized, metadataExportScriptExists]: [boolean, boolean]) => {
return [
{
visible: authorized && metadataExportScriptExists,
model: {
type: MenuItemType.ONCLICK,
text: 'menu.section.export_metadata',
function: () => {
this.modalService.open(ExportMetadataSelectorComponent);
},
},
},
{
visible: authorized && metadataExportScriptExists,
model: {
type: MenuItemType.ONCLICK,
text: 'menu.section.export_batch',
function: () => {
this.modalService.open(ExportBatchSelectorComponent);
},
},
},
];
}),
);
}
}