@@ -60,26 +60,27 @@ export default class WebUtils {
6060 return ( resource && mapResourcePermissionId [ resource ] && mode ) ? `${ mode . toUpperCase ( ) } _${ mapResourcePermissionId [ resource ] } ` : "" ;
6161 }
6262
63- static getIVALink ( opencgaSession , tool , query = { } ) {
64- const baseUrl = ( new URL ( window . location . pathname , window . location . origin ) ) ;
65- let queryStr = "" ;
66- // Check if query object has been provided
67- if ( query ) {
68- queryStr = "?" + ( new URLSearchParams ( query ) ) . toString ( ) ;
69- }
70- return `${ baseUrl } #${ tool } /${ opencgaSession . project . id } /${ opencgaSession . study . id } ${ queryStr } ` ;
71- }
72-
73- static getInterpreterLink ( opencgaSession , caseId = "" ) {
63+ static getLink ( opencgaSession , app = "" , tool = "" , query = null ) {
7464 const hashItems = [
75- // ...window.location.hash.replace("#", "").split("/").slice(0, -3), // '#clinical/portal/project/study' --> ['clinical']
76- "clinical" ,
77- "interpreter" ,
65+ app ,
66+ tool ,
7867 opencgaSession ?. project ?. id || "" ,
7968 opencgaSession ?. study ?. id || "" ,
8069 ] ;
8170
82- return `#${ hashItems . filter ( Boolean ) . join ( "/" ) } ${ ! ! caseId ? "?id=" + caseId : "" } ` ;
71+ // build the querystring fragment of the URL if a query object is provided
72+ const queryStr = ( query && Object . keys ( query || { } ) . length > 0 ) ? "?" + ( new URLSearchParams ( query ) ) . toString ( ) : "" ;
73+
74+ // build and return the internal link
75+ return `#${ hashItems . filter ( Boolean ) . join ( "/" ) } ${ queryStr } ` ;
76+ }
77+
78+ static getIVALink ( opencgaSession , app , tool , query = null ) {
79+ return ( new URL ( window . location . pathname , window . location . origin ) ) + WebUtils . getLink ( opencgaSession , app , tool , query ) ;
80+ }
81+
82+ static getInterpreterLink ( opencgaSession , query = null ) {
83+ return WebUtils . getLink ( opencgaSession , "clinical" , "interpreter" , query ) ;
8384 }
8485
8586 static getClinicalAnalysisPriorityColour ( rank ) {
@@ -100,4 +101,13 @@ export default class WebUtils {
100101 } ) ;
101102 }
102103
104+ static getApplicationAndToolFromHash ( hash = "" ) {
105+ // '#clinical/portal/project/study' --> ['clinical', 'portal]
106+ // '#portal/project/study' --> ['portal']
107+ return ( hash || window . location . hash ) . replace ( "#" , "" ) . split ( "/" ) . slice ( 0 , - 2 ) ;
108+ }
109+
110+ static redirectTo ( opencgaSession , app = "" , tool = "" , query = { } ) {
111+ window . location . hash = WebUtils . getLink ( opencgaSession , app , tool , query ) ;
112+ }
103113}
0 commit comments