1
1
// Pure function that generates an nbgitpuller URL
2
- function generateRegularUrl ( hubUrl , urlPath , repoUrl , branch ) {
2
+ function generateRegularUrl ( hubUrl , urlPath , repoUrl , branch , compressed , source ) {
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 ( 'provider' , source ) ;
11
+ }
12
+
9
13
if ( urlPath ) {
10
14
url . searchParams . set ( 'urlpath' , urlPath ) ;
11
15
}
12
16
13
17
if ( branch ) {
14
18
url . searchParams . set ( 'branch' , branch ) ;
19
+ } else if ( source == "git" ) {
20
+ url . searchParams . set ( 'branch' , "main" ) ;
15
21
}
16
-
22
+
17
23
if ( ! url . pathname . endsWith ( '/' ) ) {
18
24
url . pathname += '/'
19
25
}
@@ -22,20 +28,26 @@ function generateRegularUrl(hubUrl, urlPath, repoUrl, branch) {
22
28
return url . toString ( ) ;
23
29
}
24
30
25
- function generateCanvasUrl ( hubUrl , urlPath , repoUrl , branch ) {
31
+ function generateCanvasUrl ( hubUrl , urlPath , repoUrl , branch , compressed , source ) {
26
32
// assume hubUrl is a valid URL
27
33
var url = new URL ( hubUrl ) ;
28
34
29
35
var nextUrlParams = new URLSearchParams ( ) ;
30
36
31
37
nextUrlParams . append ( 'repo' , repoUrl ) ;
32
-
38
+
39
+ if ( compressed ) {
40
+ nextUrlParams . append ( 'provider' , source ) ;
41
+ }
42
+
33
43
if ( urlPath ) {
34
44
nextUrlParams . append ( 'urlpath' , urlPath ) ;
35
45
}
36
46
37
47
if ( branch ) {
38
48
nextUrlParams . append ( 'branch' , branch ) ;
49
+ } else if ( source == "git" ) {
50
+ nextUrlParams . append ( 'branch' , "main" ) ;
39
51
}
40
52
41
53
var nextUrl = '/hub/user-redirect/git-pull?' + nextUrlParams . toString ( ) ;
@@ -50,20 +62,26 @@ function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
50
62
}
51
63
52
64
function generateBinderUrl ( hubUrl , userName , repoName , branch , urlPath ,
53
- contentRepoUrl , contentRepoBranch ) {
65
+ contentRepoUrl , contentRepoBranch , compressed , source ) {
54
66
55
67
var url = new URL ( hubUrl ) ;
56
68
57
69
var nextUrlParams = new URLSearchParams ( ) ;
58
70
59
71
nextUrlParams . append ( 'repo' , contentRepoUrl ) ;
60
72
73
+ if ( compressed ) {
74
+ nextUrlParams . append ( 'provider' , source ) ;
75
+ }
76
+
61
77
if ( urlPath ) {
62
78
nextUrlParams . append ( 'urlpath' , urlPath ) ;
63
79
}
64
80
65
81
if ( contentRepoBranch ) {
66
82
nextUrlParams . append ( 'branch' , contentRepoBranch ) ;
83
+ } else if ( source == "git" ) {
84
+ nextUrlParams . append ( 'branch' , "main" ) ;
67
85
}
68
86
69
87
var nextUrl = 'git-pull?' + nextUrlParams . toString ( ) ;
@@ -100,37 +118,46 @@ var apps = {
100
118
}
101
119
}
102
120
121
+ function clearLinks ( ) {
122
+ document . getElementById ( 'default-link' ) . value = "" ;
123
+ document . getElementById ( 'binder-link' ) . value = "" ;
124
+ document . getElementById ( 'canvas-link' ) . value = "" ;
125
+ }
126
+
127
+
103
128
function changeTab ( div ) {
104
129
var hub = document . getElementById ( "hub" ) ;
105
130
var hub_help_text = document . getElementById ( "hub-help-text" ) ;
106
- var env_repo = document . getElementById ( "repo" ) ;
107
- var env_repo_branch = document . getElementById ( "branch" ) ;
108
- var env_repo_help_text = document . getElementById ( "env-repo-help-text" ) ;
109
- var content_repo = document . getElementById ( "content-repo-group" ) ;
110
- var content_branch = document . getElementById ( "content-branch-group" ) ;
131
+ var env_repo_group = document . getElementById ( "env-repo-group" ) ;
132
+ var env_repo = document . getElementById ( "env-repo" ) ;
133
+ < << << << HEAD
134
+ = === ===
135
+ // var env_repo_branch = document.getElementById("env-branch");
136
+ // var env_repo_help_text = document.getElementById("env-repo-help-text");
137
+ >>> >>> > b5b1e8e... JupyterHub link gen working
111
138
var id = div.id;
112
-
139
+ var form = document.getElementById('linkgenerator');
140
+
141
+ clearLinks();
113
142
if (id.includes("binder")) {
114
143
hub . placeholder = "https://mybinder.org" ;
115
144
hub . value = "https://mybinder.org" ;
116
145
hub_help_text . hidden = true ;
117
146
hub . labels [ 0 ] . innerHTML = "BinderHub URL" ;
118
- env_repo . labels [ 0 ] . innerHTML = "Git Environment Repository URL" ;
119
- env_repo_help_text . hidden = false ;
120
- env_repo_branch . required = true ;
121
- env_repo_branch . pattern = ".+" ;
122
- content_repo . hidden = false ;
123
- content_branch . hidden = false ;
147
+
148
+ env_repo_group . style . display = '' ;
149
+ env_repo . disabled = false ;
150
+
124
151
} else {
125
152
hub . placeholder = "https://hub.example.com" ;
153
+ hub . value = "" ;
126
154
hub_help_text . hidden = false ;
127
155
hub . labels [ 0 ] . innerHTML = "JupyterHub URL" ;
128
- env_repo . labels [ 0 ] . innerHTML = "Git Repository URL" ;
129
- env_repo_help_text . hidden = true ;
130
- env_repo_branch . required = false ;
131
- content_repo . hidden = true ;
132
- content_branch . hidden = true ;
156
+
157
+ env_repo_group . style . display = 'none' ;
158
+ env_repo . disabled = true ;
133
159
}
160
+ displaySource();
134
161
}
135
162
136
163
/**
@@ -141,28 +168,60 @@ function changeTab(div) {
141
168
* See https://github.com/git/git/blob/1c52ecf4ba0f4f7af72775695fee653f50737c71/builtin/clone.c#L276
142
169
*/
143
170
function generateCloneDirectoryName ( gitCloneUrl ) {
171
+ if ( gitCloneUrl . slice ( - 1 ) == "/" )
172
+ gitCloneUrl = gitCloneUrl . slice ( 0 , - 1 ) ;
144
173
var lastPart = gitCloneUrl . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
145
174
return lastPart . split ( ':' ) . slice ( - 1 ) [ 0 ] . replace ( / ( \. g i t | \. b u n d l e ) ? / , '' ) ;
146
175
}
147
176
177
+ function handleSource(args){
178
+ source = args [ "source" ] ;
179
+ branch = "" ;
180
+ compressed = true ;
181
+ sourceUrl = "" ;
182
+ if ( source == "git" ) {
183
+ sourceUrl = args [ "contentRepoUrl" ] ;
184
+ branch = args [ "contentRepoBranch" ] ;
185
+ compressed = false ;
186
+ } else if ( source == "googledrive" ) {
187
+ sourceUrl = args [ "driveUrl" ] ;
188
+ } else if ( source == "dropbox" ) {
189
+ sourceUrl = args [ "dropUrl" ] ;
190
+ } else if ( source == "standard" ) {
191
+ sourceUrl = args [ "webUrl" ] ;
192
+ }
193
+ return {
194
+ "branch" : branch ,
195
+ "sourceUrl" : sourceUrl ,
196
+ "compressed" : compressed
197
+ }
198
+ }
199
+
148
200
function displayLink() {
149
201
var form = document . getElementById ( 'linkgenerator' ) ;
150
-
202
+
151
203
form . classList . add ( 'was-validated' ) ;
152
204
if ( form . checkValidity ( ) ) {
153
205
var hubUrl = document . getElementById ( 'hub' ) . value ;
154
- var repoUrl = document . getElementById ( 'repo' ) . value ;
155
- var branch = document . getElementById ( 'branch' ) . value ;
206
+ var driveUrl = document . getElementById ( 'drive-url' ) . value ;
207
+ var dropUrl = document . getElementById ( 'drop-url' ) . value ;
208
+ var webUrl = document . getElementById ( 'standard-url' ) . value ;
209
+ var envRepoUrl = document . getElementById ( 'env-repo' ) . value ;
210
+ var envGitBranch = document . getElementById ( 'env-branch' ) . value ;
156
211
var contentRepoUrl = document . getElementById ( 'content-repo' ) . value ;
157
212
var contentRepoBranch = document . getElementById ( 'content-branch' ) . value ;
158
213
var filePath = document . getElementById ( 'filepath' ) . value ;
159
214
var appName = form . querySelector ( 'input[name="app"]:checked' ) . value ;
160
215
var activeTab = document . querySelector ( ".nav-link.active" ) . id ;
161
-
216
+ var source = form . querySelector ( 'input[name="source"]:checked' ) . value ;
217
+
162
218
if ( appName === 'custom' ) {
163
219
var urlPath = document . getElementById ( 'urlpath' ) . value ;
164
220
} else {
165
- var repoName = generateCloneDirectoryName ( repoUrl ) ;
221
+ var repoName = generateCloneDirectoryName ( contentRepoUrl ) ;
222
+ if ( source !== "git" ) {
223
+ repoName = ""
224
+ }
166
225
var urlPath ;
167
226
if ( activeTab === "tab-auth-binder" ) {
168
227
var contentRepoName = new URL ( contentRepoUrl ) . pathname . split ( '/' ) . pop ( ) . replace ( / \. g i t $ / , '' ) ;
@@ -171,26 +230,37 @@ function displayLink() {
171
230
urlPath = apps [ appName ] . generateUrlPath ( repoName + '/' + filePath ) ;
172
231
}
173
232
}
174
-
233
+ args = {
234
+ "source" : source ,
235
+ "contentRepoUrl" : contentRepoUrl ,
236
+ "contentRepoBranch" : contentRepoBranch ,
237
+ "driveUrl" : driveUrl ,
238
+ "dropUrl" : dropUrl ,
239
+ "webUrl" : webUrl
240
+ }
241
+ config = handleSource ( args )
175
242
if ( activeTab === "tab-auth-default" ) {
176
243
document . getElementById ( 'default-link' ) . value = generateRegularUrl (
177
- hubUrl , urlPath , repoUrl , branch
244
+ hubUrl , urlPath , config [ "sourceUrl" ] , config [ " branch" ] , config [ "compressed" ] , source
178
245
) ;
179
246
} else if ( activeTab === "tab - auth - canvas ") {
180
247
document . getElementById ( 'canvas - link ') . value = generateCanvasUrl (
181
- hubUrl , urlPath , repoUrl , branch
248
+ hubUrl , urlPath , config [ "sourceUrl" ] , config [ " branch" ] , config [ "compressed" ] , source
182
249
) ;
183
250
} else if ( activeTab === "tab - auth - binder ") {
184
251
// FIXME: userName parsing using new URL(...) assumes a
185
252
// HTTP based repoUrl. Does it make sense to create a
186
253
// BinderHub link for SSH URLs? Then let's fix this parsing.
187
- var userName = new URL ( repoUrl ) . pathname . split ( '/' ) [ 1 ] ;
254
+ var userName = new URL ( envRepoUrl ) . pathname . split ( '/' ) [ 1 ] ;
188
255
document . getElementById ( 'binder-link' ) . value = generateBinderUrl (
189
- hubUrl , userName , repoName , branch , urlPath , contentRepoUrl , contentRepoBranch
256
+ hubUrl , userName , repoName , envGitBranch , urlPath , config [ "sourceUrl" ] , config [ "branch" ] , config [ "compressed" ] , source
190
257
) ;
191
258
}
259
+ } else {
260
+ clearLinks ( ) ;
192
261
}
193
262
}
263
+
194
264
function populateFromQueryString ( ) {
195
265
// preseed values if specified in the url
196
266
var params = new URLSearchParams ( window . location . search ) ;
@@ -213,6 +283,33 @@ function populateFromQueryString() {
213
283
}
214
284
}
215
285
286
+ function hideShowByClassName ( cls , hideShow ) {
287
+ [ ] . forEach . call ( document . querySelectorAll ( cls ) , function ( el ) {
288
+ el . style . display = hideShow ;
289
+ setDisabled = ( hideShow == 'none' )
290
+ $ ( el ) . find ( "input" ) . each ( function ( ) {
291
+ $ ( this ) . prop ( "disabled" , setDisabled ) ;
292
+ } ) ;
293
+ } ) ;
294
+ }
295
+
296
+
297
+ function displaySource ( ) {
298
+ var form = document . getElementById ( 'linkgenerator' ) ;
299
+ var source = form . querySelector ( 'input[name="source"]:checked' ) . value ;
300
+ hideShowByClassName ( ".source" , 'none' ) ;
301
+
302
+ if ( source == 'git' ) {
303
+ hideShowByClassName ( ".source-git" , '' ) ;
304
+ } else if ( source = = 'googledrive' ) {
305
+ hideShowByClassName ( ".source-googledrive" , '' ) ;
306
+ } else if ( source = = 'dropbox' ) {
307
+ hideShowByClassName ( ".source-dropbox" , '' ) ;
308
+ } else if ( source = = "standard" ) {
309
+ hideShowByClassName ( ".source-standard" , '' ) ;
310
+ }
311
+ }
312
+
216
313
/**
217
314
* Main loop of the program.
218
315
*
@@ -225,6 +322,7 @@ function render() {
225
322
var form = document . getElementById ( 'linkgenerator' ) ;
226
323
var appName = form . querySelector ( 'input[name="app"]:checked' ) . value ;
227
324
325
+
228
326
if ( appName == 'custom' ) {
229
327
document . getElementById ( 'urlpath' ) . disabled = false ;
230
328
document . getElementById ( 'filepath' ) . disabled = true ;
@@ -238,6 +336,7 @@ function render() {
238
336
document . getElementById ( 'filepath' ) . disabled = false ;
239
337
}
240
338
}
339
+
241
340
displayLink ( ) ;
242
341
}
243
342
@@ -246,11 +345,21 @@ function render() {
246
345
*/
247
346
function main ( ) {
248
347
// Hook up any changes in form elements to call render()
249
- document . querySelectorAll ( '#linkgenerator input[type="radio "]' ) . forEach (
348
+ document . querySelectorAll ( '#linkgenerator input[name="app "]' ) . forEach (
250
349
function ( element ) {
251
350
element . addEventListener ( 'change' , render ) ;
252
351
}
253
352
)
353
+ document . querySelectorAll ( '#linkgenerator input[name="source"]' ) . forEach (
354
+ function ( element ) {
355
+ element . addEventListener ( 'change' , function ( ) {
356
+ displaySource ( ) ;
357
+ render ( ) ;
358
+ }
359
+ ) ;
360
+ }
361
+ )
362
+
254
363
document . querySelectorAll ( '#linkgenerator input[type="text"], #linkgenerator input[type="url"]' ) . forEach (
255
364
function ( element ) {
256
365
element . addEventListener ( 'input' , render ) ;
@@ -269,7 +378,9 @@ function main() {
269
378
}
270
379
}
271
380
381
+
272
382
// Do an initial render, to make sure our disabled / enabled properties are correctly set
383
+ displaySource ( ) ;
273
384
render ( ) ;
274
385
}
275
386
0 commit comments