@@ -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 }
@@ -609,6 +613,40 @@ 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+ observableCombineLatest ( [
621+ this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) ,
622+ this . getDLExporterURL ( ) ,
623+ this . getDLExporterAccessToken ( )
624+ ] ) . subscribe ( ( [ authorized , url , accesstoken ] ) => {
625+ console . log ( accesstoken ) ;
626+ const urlSegments = url . split ( '?' ) ;
627+ const queryParamSegments = urlSegments [ 1 ] . split ( '=' ) ;
628+ this . menuService . addSection ( MenuID . ADMIN ,
629+ {
630+ id : 'loginmiur_dlexporter_url' ,
631+ index : 15 ,
632+ active : false ,
633+ visible : authorized && ( hasValue ( url ) && url . length > 0 ) && ( hasValue ( accesstoken ) && accesstoken . length > 0 ) ,
634+ model : {
635+ type : MenuItemType . LINK ,
636+ text : 'menu.section.loginmiur_dlexporter_url' ,
637+ disabled : false ,
638+ link : urlSegments [ 0 ] ,
639+ queryParams : {
640+ [ queryParamSegments [ 0 ] ] : queryParamSegments [ 1 ]
641+ }
642+ } as LinkMenuItemModel ,
643+ icon : 'fa-solid fa-arrows-spin' ,
644+ shouldPersistOnRouteChange : true
645+ }
646+ ) ;
647+ } ) ;
648+ }
649+
612650 /**
613651 * Create menu sections dependent on whether or not the current user is a site administrator and on whether or not
614652 * the import scripts exist and the current user is allowed to execute them
@@ -974,4 +1012,25 @@ export class MenuResolver implements Resolve<boolean> {
9741012 const object = data . site ? data . site : data . dso ?. payload ;
9751013 return object ?. _links ?. self ?. href ;
9761014 }
1015+
1016+ /**
1017+ * Get the DL Exporter URL from the configuration
1018+ */
1019+ getDLExporterURL ( ) : Observable < string > {
1020+ return this . configService . findByPropertyName ( 'loginmiur.dlexporter.url' ) . pipe (
1021+ getFirstCompletedRemoteData ( ) ,
1022+ map ( ( res : RemoteData < ConfigurationProperty > ) => {
1023+ return res ?. payload ?. values [ 0 ] ;
1024+ } )
1025+ ) ;
1026+ }
1027+
1028+ private getDLExporterAccessToken ( ) {
1029+ return this . configService . findByPropertyName ( 'loginmiur.dlexporter.accesstoken' ) . pipe (
1030+ getFirstCompletedRemoteData ( ) ,
1031+ map ( ( res : RemoteData < ConfigurationProperty > ) => {
1032+ return res ?. payload ?. values [ 0 ] ;
1033+ } )
1034+ ) ;
1035+ }
9771036}
0 commit comments