@@ -19,7 +19,7 @@ function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed, source
19
19
} else if ( source == "git" ) {
20
20
url . searchParams . set ( 'branch' , "main" ) ;
21
21
}
22
-
22
+
23
23
if ( ! url . pathname . endsWith ( '/' ) ) {
24
24
url . pathname += '/'
25
25
}
@@ -28,20 +28,26 @@ function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed, source
28
28
return url . toString ( ) ;
29
29
}
30
30
31
- function generateCanvasUrl ( hubUrl , urlPath , repoUrl , branch ) {
31
+ function generateCanvasUrl ( hubUrl , urlPath , repoUrl , branch , compressed , source ) {
32
32
// assume hubUrl is a valid URL
33
33
var url = new URL ( hubUrl ) ;
34
34
35
35
var nextUrlParams = new URLSearchParams ( ) ;
36
36
37
37
nextUrlParams . append ( 'repo' , repoUrl ) ;
38
-
38
+
39
+ if ( compressed ) {
40
+ nextUrlParams . append ( 'provider' , source ) ;
41
+ }
42
+
39
43
if ( urlPath ) {
40
44
nextUrlParams . append ( 'urlpath' , urlPath ) ;
41
45
}
42
46
43
47
if ( branch ) {
44
48
nextUrlParams . append ( 'branch' , branch ) ;
49
+ } else if ( source == "git" ) {
50
+ nextUrlParams . append ( 'branch' , "main" ) ;
45
51
}
46
52
47
53
var nextUrl = '/hub/user-redirect/git-pull?' + nextUrlParams . toString ( ) ;
@@ -56,20 +62,26 @@ function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
56
62
}
57
63
58
64
function generateBinderUrl ( hubUrl , userName , repoName , branch , urlPath ,
59
- contentRepoUrl , contentRepoBranch ) {
65
+ contentRepoUrl , contentRepoBranch , compressed , source ) {
60
66
61
67
var url = new URL ( hubUrl ) ;
62
68
63
69
var nextUrlParams = new URLSearchParams ( ) ;
64
70
65
71
nextUrlParams . append ( 'repo' , contentRepoUrl ) ;
66
72
73
+ if ( compressed ) {
74
+ nextUrlParams . append ( 'provider' , source ) ;
75
+ }
76
+
67
77
if ( urlPath ) {
68
78
nextUrlParams . append ( 'urlpath' , urlPath ) ;
69
79
}
70
80
71
81
if ( contentRepoBranch ) {
72
82
nextUrlParams . append ( 'branch' , contentRepoBranch ) ;
83
+ } else if ( source == "git" ) {
84
+ nextUrlParams . append ( 'branch' , "main" ) ;
73
85
}
74
86
75
87
var nextUrl = 'git-pull?' + nextUrlParams . toString ( ) ;
@@ -118,8 +130,8 @@ function changeTab(div) {
118
130
var hub_help_text = document . getElementById ( "hub-help-text" ) ;
119
131
var env_repo_group = document . getElementById ( "env-repo-group" ) ;
120
132
var env_repo = document . getElementById ( "env-repo" ) ;
121
- var env_repo_branch = document . getElementById ( "env-branch" ) ;
122
- var env_repo_help_text = document . getElementById ( "env-repo-help-text" ) ;
133
+ // var env_repo_branch = document.getElementById("env-branch");
134
+ // var env_repo_help_text = document.getElementById("env-repo-help-text");
123
135
var id = div . id ;
124
136
var form = document . getElementById ( 'linkgenerator' ) ;
125
137
@@ -131,11 +143,7 @@ function changeTab(div) {
131
143
hub . labels [ 0 ] . innerHTML = "BinderHub URL" ;
132
144
133
145
env_repo_group . style . display = '' ;
134
- // env_repo_group.hidden = false;
135
- // env_repo.hidden = false;
136
- // env_repo_help_text.hidden = false;
137
- // env_repo_branch.required = true;
138
- // env_repo_branch.pattern = ".+";
146
+ env_repo . disabled = false ;
139
147
140
148
} else {
141
149
hub . placeholder = "https://hub.example.com" ;
@@ -144,8 +152,7 @@ function changeTab(div) {
144
152
hub . labels [ 0 ] . innerHTML = "JupyterHub URL" ;
145
153
146
154
env_repo_group . style . display = 'none' ;
147
- env_repo . required = false ;
148
-
155
+ env_repo . disabled = true ;
149
156
}
150
157
displaySource ( ) ;
151
158
}
@@ -164,6 +171,28 @@ function generateCloneDirectoryName(gitCloneUrl) {
164
171
return lastPart . split ( ':' ) . slice ( - 1 ) [ 0 ] . replace ( / ( \. g i t | \. b u n d l e ) ? / , '' ) ;
165
172
}
166
173
174
+ function handleSource ( args ) {
175
+ source = args [ "source" ] ;
176
+ branch = "" ;
177
+ compressed = true ;
178
+ sourceUrl = "" ;
179
+ if ( source == "git" ) {
180
+ sourceUrl = args [ "contentRepoUrl" ] ;
181
+ branch = args [ "contentRepoBranch" ] ;
182
+ compressed = false ;
183
+ } else if ( source == "googledrive" ) {
184
+ sourceUrl = args [ "driveUrl" ] ;
185
+ } else if ( source == "dropbox" ) {
186
+ sourceUrl = args [ "dropUrl" ] ;
187
+ } else if ( source == "standard" ) {
188
+ sourceUrl = args [ "webUrl" ] ;
189
+ }
190
+ return {
191
+ "branch" : branch ,
192
+ "sourceUrl" : sourceUrl ,
193
+ "compressed" : compressed
194
+ }
195
+ }
167
196
168
197
function displayLink ( ) {
169
198
var form = document . getElementById ( 'linkgenerator' ) ;
@@ -198,34 +227,30 @@ function displayLink() {
198
227
urlPath = apps [ appName ] . generateUrlPath ( repoName + '/' + filePath ) ;
199
228
}
200
229
}
230
+ args = {
231
+ "source" : source ,
232
+ "contentRepoUrl" : contentRepoUrl ,
233
+ "contentRepoBranch" : contentRepoBranch ,
234
+ "driveUrl" : driveUrl ,
235
+ "dropUrl" : dropUrl ,
236
+ "webUrl" : webUrl
237
+ }
238
+ config = handleSource ( args )
201
239
if ( activeTab === "tab-auth-default" ) {
202
- branch = "" ;
203
- compressed = true ;
204
- if ( source == "git" ) {
205
- sourceUrl = contentRepoUrl ;
206
- branch = contentRepoBranch ;
207
- compressed = false ;
208
- } else if ( source == "googledrive" ) {
209
- sourceUrl = driveUrl ;
210
- } else if ( source == "dropbox" ) {
211
- sourceUrl = dropUrl ;
212
- } else if ( source == "standard" ) {
213
- sourceUrl = webUrl ;
214
- }
215
240
document . getElementById ( 'default-link' ) . value = generateRegularUrl (
216
- hubUrl , urlPath , sourceUrl , branch , compressed , source
241
+ hubUrl , urlPath , config [ " sourceUrl" ] , config [ " branch" ] , config [ " compressed" ] , source
217
242
) ;
218
243
} else if ( activeTab === "tab-auth-canvas" ) {
219
244
document . getElementById ( 'canvas-link' ) . value = generateCanvasUrl (
220
- hubUrl , urlPath , contentRepoUrl , contentRepoBranch
245
+ hubUrl , urlPath , config [ "sourceUrl" ] , config [ "branch" ] , config [ "compressed" ] , source
221
246
) ;
222
247
} else if ( activeTab === "tab-auth-binder" ) {
223
248
// FIXME: userName parsing using new URL(...) assumes a
224
249
// HTTP based repoUrl. Does it make sense to create a
225
250
// BinderHub link for SSH URLs? Then let's fix this parsing.
226
251
var userName = new URL ( repoUrl ) . pathname . split ( '/' ) [ 1 ] ;
227
252
document . getElementById ( 'binder-link' ) . value = generateBinderUrl (
228
- hubUrl , userName , repoName , envGitBranch , urlPath , contentRepoUrl , contentRepoBranch
253
+ hubUrl , userName , repoName , envGitBranch , urlPath , config [ "sourceUrl" ] , config [ "branch" ] , config [ "compressed" ] , source
229
254
) ;
230
255
}
231
256
} else {
@@ -293,8 +318,7 @@ function displaySource(){
293
318
function render ( ) {
294
319
var form = document . getElementById ( 'linkgenerator' ) ;
295
320
var appName = form . querySelector ( 'input[name="app"]:checked' ) . value ;
296
- document . getElementById ( "env-repo-group" ) . style . display = 'none' ;
297
- document . getElementById ( "env-repo" ) . disabled = true ;
321
+
298
322
299
323
if ( appName == 'custom' ) {
300
324
document . getElementById ( 'urlpath' ) . disabled = false ;
0 commit comments