@@ -4,22 +4,14 @@ import {
44 ILayoutRestorer ,
55} from "@jupyterlab/application" ;
66import { ILauncher } from "@jupyterlab/launcher" ;
7- import { PageConfig } from "@jupyterlab/coreutils" ;
8- import { IRunningSessionManagers , IRunningSessions } from "@jupyterlab/running" ;
7+ import { PageConfig , URLExt } from "@jupyterlab/coreutils" ;
8+ import { IRunningSessionManagers } from "@jupyterlab/running" ;
9+ import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
10+ import { ITranslator , TranslationBundle } from '@jupyterlab/translation' ;
911import { IFrame , MainAreaWidget , WidgetTracker } from "@jupyterlab/apputils" ;
10- import { LabIcon } from "@jupyterlab/ui-components" ;
1112import { ServerProxyManager } from "./manager" ;
1213import { IModel as IServerProxyModel } from "./serverproxy" ;
13- import serverProxyAppSvgstr from "../style/icons/proxy.svg" ;
14-
15- export const ServerProxyAppIcon = new LabIcon ( {
16- name : "server-proxy:proxyAppIcon" ,
17- svgstr : serverProxyAppSvgstr ,
18- } ) ;
19-
20- namespace CommandIDs {
21- export const open = "running-server-proxy:open" ;
22- }
14+ import { RunningServerProxyApp , CommandIDs } from "./running" ;
2315
2416function newServerProxyWidget (
2517 id : string ,
@@ -56,42 +48,20 @@ function addRunningSessionManager(
5648 managers : IRunningSessionManagers ,
5749 app : JupyterFrontEnd ,
5850 manager : ServerProxyManager ,
51+ trans : TranslationBundle
5952) : void {
6053 managers . add ( {
6154 name : "Server Proxy Apps" ,
6255 running : ( ) =>
6356 Array . from ( manager . running ( ) ) . map (
64- ( model ) => new RunningServerProxyApp ( model ) ,
57+ ( model ) => new RunningServerProxyApp ( model , manager , app ) ,
6558 ) ,
6659 shutdownAll : ( ) => manager . shutdownAll ( ) ,
6760 refreshRunning : ( ) => manager . refreshRunning ( ) ,
6861 runningChanged : manager . runningChanged ,
6962 shutdownAllConfirmationText :
70- "Are you sure you want to close all server proxy applications?" ,
63+ trans . __ ( "Are you sure you want to close all server proxy applications?" )
7164 } ) ;
72-
73- class RunningServerProxyApp implements IRunningSessions . IRunningItem {
74- constructor ( model : IServerProxyModel ) {
75- this . _model = model ;
76- }
77- open ( ) : void {
78- app . commands . execute ( CommandIDs . open , { sp : this . _model } ) ;
79- }
80- icon ( ) : LabIcon {
81- return ServerProxyAppIcon ;
82- }
83- label ( ) : string {
84- return `${ this . _model . name } ` ;
85- }
86- labelTitle ( ) : string {
87- return `cmd: ${ this . _model . cmd } \nport: ${ this . _model . port } \nmanaged: ${ this . _model . managed } ` ;
88- }
89- shutdown ( ) : Promise < void > {
90- return manager . shutdown ( this . _model . name ) ;
91- }
92-
93- private _model : IServerProxyModel ;
94- }
9565}
9666
9767/**
@@ -104,21 +74,28 @@ async function activate(
10474 app : JupyterFrontEnd ,
10575 launcher : ILauncher ,
10676 restorer : ILayoutRestorer ,
77+ settingRegistry : ISettingRegistry ,
78+ translator : ITranslator ,
10779 sessions : IRunningSessionManagers | null ,
10880) : Promise < void > {
81+ const trans = translator . load ( 'jupyter-server-proxy' ) ;
82+
10983 // Fetch configured server processes from {base_url}/server-proxy/servers-info
11084 const response = await fetch (
111- PageConfig . getBaseUrl ( ) + "api/ server-proxy/servers-info",
85+ URLExt . join ( PageConfig . getBaseUrl ( ) , " server-proxy/api/ servers-info") ,
11286 ) ;
11387 if ( ! response . ok ) {
11488 console . log (
115- "Could not fetch metadata about registered servers. Make sure jupyter-server-proxy is installed." ,
89+ trans . __ ( "Could not fetch metadata about registered servers. Make sure jupyter-server-proxy is installed." ) ,
11690 ) ;
11791 console . log ( response ) ;
11892 return ;
11993 }
12094 const data = await response . json ( ) ;
12195
96+ // Load application settings
97+ const settings = await settingRegistry . load ( extension . id ) ;
98+
12299 const namespace = "server-proxy" ;
123100 const tracker = new WidgetTracker < MainAreaWidget < IFrame > > ( {
124101 namespace,
@@ -142,8 +119,8 @@ async function activate(
142119
143120 // Add server proxy session manager to running sessions
144121 if ( sessions ) {
145- let manager = new ServerProxyManager ( ) ;
146- addRunningSessionManager ( sessions , app , manager ) ;
122+ let manager = new ServerProxyManager ( trans , settings ) ;
123+ addRunningSessionManager ( sessions , app , manager , trans ) ;
147124 }
148125
149126 commands . addCommand ( command , {
@@ -178,7 +155,7 @@ async function activate(
178155 commands . addCommand ( CommandIDs . open , {
179156 execute : ( args ) => {
180157 const model = args [ "sp" ] as IServerProxyModel ;
181- const url = PageConfig . getBaseUrl ( ) + model . url ;
158+ const url = URLExt . join ( PageConfig . getBaseUrl ( ) , model . url ) ;
182159 window . open ( url , "_blank" ) ;
183160 return ;
184161 } ,
@@ -189,8 +166,7 @@ async function activate(
189166 continue ;
190167 }
191168
192- const url =
193- PageConfig . getBaseUrl ( ) + server_process . launcher_entry . path_info ;
169+ const url = URLExt . join ( PageConfig . getBaseUrl ( ) , server_process . launcher_entry . path_info ) ;
194170 const title = server_process . launcher_entry . title ;
195171 const newBrowserTab = server_process . new_browser_tab ;
196172 const id = namespace + ":" + server_process . name ;
@@ -221,7 +197,7 @@ async function activate(
221197const extension : JupyterFrontEndPlugin < void > = {
222198 id : "@jupyterhub/jupyter-server-proxy:add-launcher-entries" ,
223199 autoStart : true ,
224- requires : [ ILauncher , ILayoutRestorer ] ,
200+ requires : [ ILauncher , ILayoutRestorer , ISettingRegistry , ITranslator ] ,
225201 optional : [ IRunningSessionManagers ] ,
226202 activate : activate ,
227203} ;
0 commit comments