1
1
// Pure function that generates an nbgitpuller URL
2
- function generateRegularUrl ( hubUrl , urlPath , repoUrl , branch ) {
2
+ function generateRegularUrl ( hubUrl , urlPath , repoUrl , branch , compressed ) {
3
3
4
4
// assume hubUrl is a valid URL
5
5
var url = new URL ( hubUrl ) ;
6
6
7
7
url . searchParams . set ( 'repo' , repoUrl ) ;
8
-
8
+
9
+ if ( compressed ) {
10
+ url . searchParams . set ( 'compressed' , "true" ) ;
11
+ }
12
+
9
13
if ( urlPath ) {
10
14
url . searchParams . set ( 'urlpath' , urlPath ) ;
11
15
}
@@ -100,6 +104,13 @@ var apps = {
100
104
}
101
105
}
102
106
107
+ function clearLinks ( ) {
108
+ document . getElementById ( 'default-link' ) . value = "" ;
109
+ document . getElementById ( 'binder-link' ) . value = "" ;
110
+ document . getElementById ( 'canvas-link' ) . value = "" ;
111
+ }
112
+
113
+ var stateSource = null ;
103
114
function changeTab ( div ) {
104
115
var hub = document . getElementById ( "hub" ) ;
105
116
var hub_help_text = document . getElementById ( "hub-help-text" ) ;
@@ -109,8 +120,11 @@ function changeTab(div) {
109
120
var content_repo = document . getElementById ( "content-repo-group" ) ;
110
121
var content_branch = document . getElementById ( "content-branch-group" ) ;
111
122
var id = div . id ;
112
-
123
+ var form = document . getElementById ( 'linkgenerator' ) ;
124
+
125
+ clearLinks ( ) ;
113
126
if ( id . includes ( "binder" ) ) {
127
+ document . getElementById ( "app-source" ) . hidden = true ;
114
128
hub . placeholder = "https://mybinder.org" ;
115
129
hub . value = "https://mybinder.org" ;
116
130
hub_help_text . hidden = true ;
@@ -121,15 +135,27 @@ function changeTab(div) {
121
135
env_repo_branch . pattern = ".+" ;
122
136
content_repo . hidden = false ;
123
137
content_branch . hidden = false ;
138
+ // if binder but in correct state
139
+ stateSource = form . querySelector ( 'input[name="source"]:checked' ) ;
140
+ document . getElementById ( "source-git" ) . checked = true ;
141
+ displaySource ( ) ;
124
142
} else {
143
+ document . getElementById ( "app-source" ) . hidden = false ;
125
144
hub . placeholder = "https://hub.example.com" ;
145
+ hub . value = "" ;
126
146
hub_help_text . hidden = false ;
127
147
hub . labels [ 0 ] . innerHTML = "JupyterHub URL" ;
128
148
env_repo . labels [ 0 ] . innerHTML = "Git Repository URL" ;
129
149
env_repo_help_text . hidden = true ;
130
150
env_repo_branch . required = false ;
131
151
content_repo . hidden = true ;
132
152
content_branch . hidden = true ;
153
+
154
+ //if coming from binder tab restore state
155
+ if ( stateSource )
156
+ stateSource . checked = true ;
157
+ stateSource = null
158
+ displaySource ( ) ;
133
159
}
134
160
}
135
161
@@ -145,24 +171,32 @@ function generateCloneDirectoryName(gitCloneUrl) {
145
171
return lastPart . split ( ':' ) . slice ( - 1 ) [ 0 ] . replace ( / ( \. g i t | \. b u n d l e ) ? / , '' ) ;
146
172
}
147
173
174
+
148
175
function displayLink ( ) {
149
176
var form = document . getElementById ( 'linkgenerator' ) ;
150
-
177
+
151
178
form . classList . add ( 'was-validated' ) ;
152
179
if ( form . checkValidity ( ) ) {
153
180
var hubUrl = document . getElementById ( 'hub' ) . value ;
154
181
var repoUrl = document . getElementById ( 'repo' ) . value ;
155
- var branch = document . getElementById ( 'branch' ) . value ;
182
+ var driveUrl = document . getElementById ( 'drive-url' ) . value ;
183
+ var dropUrl = document . getElementById ( 'drop-url' ) . value ;
184
+ var webUrl = document . getElementById ( 'web-url' ) . value ;
185
+ var gitBranch = document . getElementById ( 'branch' ) . value ;
156
186
var contentRepoUrl = document . getElementById ( 'content-repo' ) . value ;
157
187
var contentRepoBranch = document . getElementById ( 'content-branch' ) . value ;
158
188
var filePath = document . getElementById ( 'filepath' ) . value ;
159
189
var appName = form . querySelector ( 'input[name="app"]:checked' ) . value ;
160
190
var activeTab = document . querySelector ( ".nav-link.active" ) . id ;
161
-
191
+ var source = form . querySelector ( 'input[name="source"]:checked' ) . value ;
192
+
162
193
if ( appName === 'custom' ) {
163
194
var urlPath = document . getElementById ( 'urlpath' ) . value ;
164
195
} else {
165
196
var repoName = generateCloneDirectoryName ( repoUrl ) ;
197
+ if ( source !== "git" ) {
198
+ repoName = ""
199
+ }
166
200
var urlPath ;
167
201
if ( activeTab === "tab-auth-binder" ) {
168
202
var contentRepoName = new URL ( contentRepoUrl ) . pathname . split ( '/' ) . pop ( ) . replace ( / \. g i t $ / , '' ) ;
@@ -171,26 +205,41 @@ function displayLink() {
171
205
urlPath = apps [ appName ] . generateUrlPath ( repoName + '/' + filePath ) ;
172
206
}
173
207
}
174
-
175
208
if ( activeTab === "tab-auth-default" ) {
209
+ branch = "" ;
210
+ compressed = true ;
211
+ if ( source == "git" ) {
212
+ sourceUrl = repoUrl ;
213
+ branch = gitBranch ;
214
+ compressed = false ;
215
+ } else if ( source == "googledrive" ) {
216
+ sourceUrl = driveUrl ;
217
+ } else if ( source == "dropbox" ) {
218
+ sourceUrl = dropUrl ;
219
+ } else if ( source == "web" ) {
220
+ sourceUrl = webUrl ;
221
+ }
176
222
document . getElementById ( 'default-link' ) . value = generateRegularUrl (
177
- hubUrl , urlPath , repoUrl , branch
223
+ hubUrl , urlPath , sourceUrl , branch , compressed
178
224
) ;
179
225
} else if ( activeTab === "tab-auth-canvas" ) {
180
226
document . getElementById ( 'canvas-link' ) . value = generateCanvasUrl (
181
- hubUrl , urlPath , repoUrl , branch
227
+ hubUrl , urlPath , repoUrl , gitBranch
182
228
) ;
183
229
} else if ( activeTab === "tab-auth-binder" ) {
184
230
// FIXME: userName parsing using new URL(...) assumes a
185
231
// HTTP based repoUrl. Does it make sense to create a
186
232
// BinderHub link for SSH URLs? Then let's fix this parsing.
187
233
var userName = new URL ( repoUrl ) . pathname . split ( '/' ) [ 1 ] ;
188
234
document . getElementById ( 'binder-link' ) . value = generateBinderUrl (
189
- hubUrl , userName , repoName , branch , urlPath , contentRepoUrl , contentRepoBranch
235
+ hubUrl , userName , repoName , gitBranch , urlPath , contentRepoUrl , contentRepoBranch
190
236
) ;
191
237
}
238
+ } else {
239
+ clearLinks ( ) ;
192
240
}
193
241
}
242
+
194
243
function populateFromQueryString ( ) {
195
244
// preseed values if specified in the url
196
245
var params = new URLSearchParams ( window . location . search ) ;
@@ -213,6 +262,31 @@ function populateFromQueryString() {
213
262
}
214
263
}
215
264
265
+ function hideShowByClassName ( cls , hideShow ) {
266
+ [ ] . forEach . call ( document . querySelectorAll ( cls ) , function ( el ) {
267
+ el . style . display = hideShow ;
268
+ setDisabled = ( hideShow == 'none' )
269
+ $ ( el ) . find ( "input" ) . each ( function ( ) {
270
+ $ ( this ) . prop ( "disabled" , setDisabled ) ;
271
+ } ) ;
272
+ } ) ;
273
+ }
274
+
275
+ function displaySource ( ) {
276
+ var form = document . getElementById ( 'linkgenerator' ) ;
277
+ var source = form . querySelector ( 'input[name="source"]:checked' ) . value ;
278
+ hideShowByClassName ( ".source" , 'none' ) ;
279
+ if ( source == 'git' ) {
280
+ hideShowByClassName ( ".source-git" , '' ) ;
281
+ } else if ( source == 'googledrive' ) {
282
+ hideShowByClassName ( ".source-googledrive" , '' ) ;
283
+ } else if ( source == 'dropbox' ) {
284
+ hideShowByClassName ( ".source-dropbox" , '' ) ;
285
+ } else if ( source == 'web' ) {
286
+ hideShowByClassName ( ".source-web" , '' ) ;
287
+ }
288
+ }
289
+
216
290
/**
217
291
* Main loop of the program.
218
292
*
@@ -224,7 +298,7 @@ function populateFromQueryString() {
224
298
function render ( ) {
225
299
var form = document . getElementById ( 'linkgenerator' ) ;
226
300
var appName = form . querySelector ( 'input[name="app"]:checked' ) . value ;
227
-
301
+
228
302
if ( appName == 'custom' ) {
229
303
document . getElementById ( 'urlpath' ) . disabled = false ;
230
304
document . getElementById ( 'filepath' ) . disabled = true ;
@@ -238,6 +312,8 @@ function render() {
238
312
document . getElementById ( 'filepath' ) . disabled = false ;
239
313
}
240
314
}
315
+
316
+
241
317
displayLink ( ) ;
242
318
}
243
319
@@ -246,11 +322,21 @@ function render() {
246
322
*/
247
323
function main ( ) {
248
324
// Hook up any changes in form elements to call render()
249
- document . querySelectorAll ( '#linkgenerator input[type="radio "]' ) . forEach (
325
+ document . querySelectorAll ( '#linkgenerator input[name="app "]' ) . forEach (
250
326
function ( element ) {
251
327
element . addEventListener ( 'change' , render ) ;
252
328
}
253
329
)
330
+ document . querySelectorAll ( '#linkgenerator input[name="source"]' ) . forEach (
331
+ function ( element ) {
332
+ element . addEventListener ( 'change' , function ( ) {
333
+ displaySource ( ) ;
334
+ render ( ) ;
335
+ }
336
+ ) ;
337
+ }
338
+ )
339
+
254
340
document . querySelectorAll ( '#linkgenerator input[type="text"], #linkgenerator input[type="url"]' ) . forEach (
255
341
function ( element ) {
256
342
element . addEventListener ( 'input' , render ) ;
@@ -269,7 +355,9 @@ function main() {
269
355
}
270
356
}
271
357
358
+
272
359
// Do an initial render, to make sure our disabled / enabled properties are correctly set
360
+ displaySource ( ) ;
273
361
render ( ) ;
274
362
}
275
363
0 commit comments