@@ -4,22 +4,14 @@ import {
4
4
ILayoutRestorer ,
5
5
} from "@jupyterlab/application" ;
6
6
import { 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' ;
9
11
import { IFrame , MainAreaWidget , WidgetTracker } from "@jupyterlab/apputils" ;
10
- import { LabIcon } from "@jupyterlab/ui-components" ;
11
12
import { ServerProxyManager } from "./manager" ;
12
13
import { 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" ;
23
15
24
16
function newServerProxyWidget (
25
17
id : string ,
@@ -56,42 +48,20 @@ function addRunningSessionManager(
56
48
managers : IRunningSessionManagers ,
57
49
app : JupyterFrontEnd ,
58
50
manager : ServerProxyManager ,
51
+ trans : TranslationBundle
59
52
) : void {
60
53
managers . add ( {
61
54
name : "Server Proxy Apps" ,
62
55
running : ( ) =>
63
56
Array . from ( manager . running ( ) ) . map (
64
- ( model ) => new RunningServerProxyApp ( model ) ,
57
+ ( model ) => new RunningServerProxyApp ( model , manager , app ) ,
65
58
) ,
66
59
shutdownAll : ( ) => manager . shutdownAll ( ) ,
67
60
refreshRunning : ( ) => manager . refreshRunning ( ) ,
68
61
runningChanged : manager . runningChanged ,
69
62
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?" )
71
64
} ) ;
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
- }
95
65
}
96
66
97
67
/**
@@ -104,21 +74,28 @@ async function activate(
104
74
app : JupyterFrontEnd ,
105
75
launcher : ILauncher ,
106
76
restorer : ILayoutRestorer ,
77
+ settingRegistry : ISettingRegistry ,
78
+ translator : ITranslator ,
107
79
sessions : IRunningSessionManagers | null ,
108
80
) : Promise < void > {
81
+ const trans = translator . load ( 'jupyter-server-proxy' ) ;
82
+
109
83
// Fetch configured server processes from {base_url}/server-proxy/servers-info
110
84
const response = await fetch (
111
- PageConfig . getBaseUrl ( ) + "api/ server-proxy/servers-info",
85
+ URLExt . join ( PageConfig . getBaseUrl ( ) , " server-proxy/api/ servers-info") ,
112
86
) ;
113
87
if ( ! response . ok ) {
114
88
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." ) ,
116
90
) ;
117
91
console . log ( response ) ;
118
92
return ;
119
93
}
120
94
const data = await response . json ( ) ;
121
95
96
+ // Load application settings
97
+ const settings = await settingRegistry . load ( extension . id ) ;
98
+
122
99
const namespace = "server-proxy" ;
123
100
const tracker = new WidgetTracker < MainAreaWidget < IFrame > > ( {
124
101
namespace,
@@ -142,8 +119,8 @@ async function activate(
142
119
143
120
// Add server proxy session manager to running sessions
144
121
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 ) ;
147
124
}
148
125
149
126
commands . addCommand ( command , {
@@ -178,7 +155,7 @@ async function activate(
178
155
commands . addCommand ( CommandIDs . open , {
179
156
execute : ( args ) => {
180
157
const model = args [ "sp" ] as IServerProxyModel ;
181
- const url = PageConfig . getBaseUrl ( ) + model . url ;
158
+ const url = URLExt . join ( PageConfig . getBaseUrl ( ) , model . url ) ;
182
159
window . open ( url , "_blank" ) ;
183
160
return ;
184
161
} ,
@@ -189,8 +166,7 @@ async function activate(
189
166
continue ;
190
167
}
191
168
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 ) ;
194
170
const title = server_process . launcher_entry . title ;
195
171
const newBrowserTab = server_process . new_browser_tab ;
196
172
const id = namespace + ":" + server_process . name ;
@@ -221,7 +197,7 @@ async function activate(
221
197
const extension : JupyterFrontEndPlugin < void > = {
222
198
id : "@jupyterhub/jupyter-server-proxy:add-launcher-entries" ,
223
199
autoStart : true ,
224
- requires : [ ILauncher , ILayoutRestorer ] ,
200
+ requires : [ ILauncher , ILayoutRestorer , ISettingRegistry , ITranslator ] ,
225
201
optional : [ IRunningSessionManagers ] ,
226
202
activate : activate ,
227
203
} ;
0 commit comments