@@ -11,7 +11,7 @@ import { RemoteData } from './core/data/remote-data';
1111import { TextMenuItemModel } from './shared/menu/menu-item/models/text.model' ;
1212import { MenuService } from './shared/menu/menu.service' ;
1313import { filter , find , map , switchMap , take } from 'rxjs/operators' ;
14- import { hasValue } from './shared/empty.util' ;
14+ import { hasValue , isNotEmpty } from './shared/empty.util' ;
1515import { FeatureID } from './core/data/feature-authorization/feature-id' ;
1616import {
1717 ThemedCreateCommunityParentSelectorComponent
@@ -52,6 +52,8 @@ import { environment } from '../environments/environment';
5252import { SectionDataService } from './core/layout/section-data.service' ;
5353import { Section } from './core/layout/models/section.model' ;
5454import { NOTIFICATIONS_RECITER_SUGGESTION_PATH } from './admin/admin-notifications/admin-notifications-routing-paths' ;
55+ import { ConfigurationDataService } from './core/data/configuration-data.service' ;
56+ import { ConfigurationProperty } from './core/shared/configuration-property.model' ;
5557
5658/**
5759 * Creates all of the app's menus
@@ -70,6 +72,7 @@ export class MenuResolver implements Resolve<boolean> {
7072 protected modalService : NgbModal ,
7173 protected scriptDataService : ScriptDataService ,
7274 protected sectionDataService : SectionDataService ,
75+ protected configService : ConfigurationDataService ,
7376 ) {
7477 }
7578
@@ -254,6 +257,7 @@ export class MenuResolver implements Resolve<boolean> {
254257 this . createExportMenuSections ( ) ;
255258 this . createImportMenuSections ( ) ;
256259 this . createAccessControlMenuSections ( ) ;
260+ this . createDLExporterMenuItem ( ) ;
257261
258262 return this . waitForMenu$ ( MenuID . ADMIN ) ;
259263 }
@@ -528,11 +532,11 @@ export class MenuResolver implements Resolve<boolean> {
528532 ] ;
529533 menuList . forEach ( ( menuSection ) => this . menuService . addSection ( MenuID . ADMIN , menuSection ) ) ;
530534
531- observableCombineLatest ( [
532- this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) ,
533- this . scriptDataService . scriptWithNameExistsAndCanExecute ( METADATA_EXPORT_SCRIPT_NAME )
534- ] ) . pipe (
535- filter ( ( [ authorized , metadataExportScriptExists ] : boolean [ ] ) => authorized && metadataExportScriptExists ) ,
535+ this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) . pipe (
536+ filter ( ( authorized : boolean ) => authorized ) ,
537+ take ( 1 ) ,
538+ switchMap ( ( ) => this . scriptDataService . scriptWithNameExistsAndCanExecute ( METADATA_EXPORT_SCRIPT_NAME ) ) ,
539+ filter ( ( metadataExportScriptExists : boolean ) => metadataExportScriptExists ) ,
536540 take ( 1 )
537541 ) . subscribe ( ( ) => {
538542 // Hides the export menu for unauthorised people
@@ -609,6 +613,44 @@ export class MenuResolver implements Resolve<boolean> {
609613 } ) ;
610614 }
611615
616+ /**
617+ * Add the DL Exporter menu item to the admin menu
618+ */
619+ createDLExporterMenuItem ( ) {
620+ this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) . pipe (
621+ filter ( ( authorized : boolean ) => authorized ) ,
622+ take ( 1 ) ,
623+ switchMap ( ( ) => observableCombineLatest ( [
624+ this . getDLExporterURL ( ) ,
625+ this . getDLExporterAccessToken ( )
626+ ] ) ) ,
627+ filter ( ( [ url , accesstoken ] ) => isNotEmpty ( url ) && isNotEmpty ( accesstoken ) ) ,
628+ take ( 1 )
629+ ) . subscribe ( ( [ url , accesstoken ] ) => {
630+ const urlSegments = url . split ( '?' ) ;
631+ const queryParamSegments = urlSegments [ 1 ] . split ( '=' ) ;
632+ this . menuService . addSection ( MenuID . ADMIN ,
633+ {
634+ id : 'loginmiur_dlexporter_url' ,
635+ index : 15 ,
636+ active : false ,
637+ visible : true ,
638+ model : {
639+ type : MenuItemType . LINK ,
640+ text : 'menu.section.loginmiur_dlexporter_url' ,
641+ disabled : false ,
642+ link : urlSegments [ 0 ] ,
643+ queryParams : {
644+ [ queryParamSegments [ 0 ] ] : queryParamSegments [ 1 ]
645+ }
646+ } as LinkMenuItemModel ,
647+ icon : 'fa-solid fa-arrows-spin' ,
648+ shouldPersistOnRouteChange : true
649+ }
650+ ) ;
651+ } ) ;
652+ }
653+
612654 /**
613655 * Create menu sections dependent on whether or not the current user is a site administrator and on whether or not
614656 * the import scripts exist and the current user is allowed to execute them
@@ -617,11 +659,11 @@ export class MenuResolver implements Resolve<boolean> {
617659 const menuList = [ ] ;
618660 menuList . forEach ( ( menuSection ) => this . menuService . addSection ( MenuID . ADMIN , menuSection ) ) ;
619661
620- observableCombineLatest ( [
621- this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) ,
622- this . scriptDataService . scriptWithNameExistsAndCanExecute ( METADATA_IMPORT_SCRIPT_NAME )
623- ] ) . pipe (
624- filter ( ( [ authorized , metadataImportScriptExists ] : boolean [ ] ) => authorized && metadataImportScriptExists ) ,
662+ this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) . pipe (
663+ filter ( ( authorized : boolean ) => authorized ) ,
664+ take ( 1 ) ,
665+ switchMap ( ( ) => this . scriptDataService . scriptWithNameExistsAndCanExecute ( METADATA_IMPORT_SCRIPT_NAME ) ) ,
666+ filter ( ( metadataImportScriptExists : boolean ) => metadataImportScriptExists ) ,
625667 take ( 1 )
626668 ) . subscribe ( ( ) => {
627669 // Hides the import menu for unauthorised people
@@ -974,4 +1016,25 @@ export class MenuResolver implements Resolve<boolean> {
9741016 const object = data . site ? data . site : data . dso ?. payload ;
9751017 return object ?. _links ?. self ?. href ;
9761018 }
1019+
1020+ /**
1021+ * Get the DL Exporter URL from the configuration
1022+ */
1023+ getDLExporterURL ( ) : Observable < string > {
1024+ return this . configService . findByPropertyName ( 'loginmiur.dlexporter.url' ) . pipe (
1025+ getFirstCompletedRemoteData ( ) ,
1026+ map ( ( res : RemoteData < ConfigurationProperty > ) => {
1027+ return res ?. payload ?. values [ 0 ] ;
1028+ } )
1029+ ) ;
1030+ }
1031+
1032+ private getDLExporterAccessToken ( ) {
1033+ return this . configService . findByPropertyName ( 'loginmiur.dlexporter.accesstoken' ) . pipe (
1034+ getFirstCompletedRemoteData ( ) ,
1035+ map ( ( res : RemoteData < ConfigurationProperty > ) => {
1036+ return res ?. payload ?. values [ 0 ] ;
1037+ } )
1038+ ) ;
1039+ }
9771040}
0 commit comments