1
1
// Pure function that generates an nbgitpuller URL
2
- function generateRegularUrl ( hubUrl , urlPath , repoUrl , branch , compressed ) {
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
9
if ( compressed ) {
10
- url . searchParams . set ( 'compressed ' , "true" ) ;
10
+ url . searchParams . set ( 'provider ' , source ) ;
11
11
}
12
12
13
13
if ( urlPath ) {
@@ -16,6 +16,8 @@ function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed) {
16
16
17
17
if ( branch ) {
18
18
url . searchParams . set ( 'branch' , branch ) ;
19
+ } else if ( source == "git" ) {
20
+ url . searchParams . set ( 'branch' , "main" ) ;
19
21
}
20
22
21
23
if ( ! url . pathname . endsWith ( '/' ) ) {
@@ -110,53 +112,42 @@ function clearLinks(){
110
112
document . getElementById ( 'canvas-link' ) . value = "" ;
111
113
}
112
114
113
- var stateSource = null ;
115
+
114
116
function changeTab ( div ) {
115
117
var hub = document . getElementById ( "hub" ) ;
116
118
var hub_help_text = document . getElementById ( "hub-help-text" ) ;
117
- var env_repo = document . getElementById ( "repo" ) ;
118
- var env_repo_branch = document . getElementById ( "branch" ) ;
119
+ var env_repo_group = document . getElementById ( "env-repo-group" ) ;
120
+ var env_repo = document . getElementById ( "env-repo" ) ;
121
+ var env_repo_branch = document . getElementById ( "env-branch" ) ;
119
122
var env_repo_help_text = document . getElementById ( "env-repo-help-text" ) ;
120
- var content_repo = document . getElementById ( "content-repo-group" ) ;
121
- var content_branch = document . getElementById ( "content-branch-group" ) ;
122
123
var id = div . id ;
123
124
var form = document . getElementById ( 'linkgenerator' ) ;
124
125
125
126
clearLinks ( ) ;
126
127
if ( id . includes ( "binder" ) ) {
127
- document . getElementById ( "app-source" ) . hidden = true ;
128
128
hub . placeholder = "https://mybinder.org" ;
129
129
hub . value = "https://mybinder.org" ;
130
130
hub_help_text . hidden = true ;
131
131
hub . labels [ 0 ] . innerHTML = "BinderHub URL" ;
132
- env_repo . labels [ 0 ] . innerHTML = "Git Environment Repository URL" ;
133
- env_repo_help_text . hidden = false ;
134
- env_repo_branch . required = true ;
135
- env_repo_branch . pattern = ".+" ;
136
- content_repo . hidden = false ;
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 ( ) ;
132
+
133
+ 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 = ".+";
139
+
142
140
} else {
143
- document . getElementById ( "app-source" ) . hidden = false ;
144
141
hub . placeholder = "https://hub.example.com" ;
145
142
hub . value = "" ;
146
143
hub_help_text . hidden = false ;
147
144
hub . labels [ 0 ] . innerHTML = "JupyterHub URL" ;
148
- env_repo . labels [ 0 ] . innerHTML = "Git Repository URL" ;
149
- env_repo_help_text . hidden = true ;
150
- env_repo_branch . required = false ;
151
- content_repo . hidden = true ;
152
- content_branch . hidden = true ;
153
145
154
- //if coming from binder tab restore state
155
- if ( stateSource )
156
- stateSource . checked = true ;
157
- stateSource = null
158
- displaySource ( ) ;
146
+ env_repo_group . style . display = 'none' ;
147
+ env_repo . required = false ;
148
+
159
149
}
150
+ displaySource ( ) ;
160
151
}
161
152
162
153
/**
@@ -167,6 +158,8 @@ function changeTab(div) {
167
158
* See https://github.com/git/git/blob/1c52ecf4ba0f4f7af72775695fee653f50737c71/builtin/clone.c#L276
168
159
*/
169
160
function generateCloneDirectoryName ( gitCloneUrl ) {
161
+ if ( gitCloneUrl . slice ( - 1 ) == "/" )
162
+ gitCloneUrl = gitCloneUrl . slice ( 0 , - 1 ) ;
170
163
var lastPart = gitCloneUrl . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
171
164
return lastPart . split ( ':' ) . slice ( - 1 ) [ 0 ] . replace ( / ( \. g i t | \. b u n d l e ) ? / , '' ) ;
172
165
}
@@ -178,11 +171,11 @@ function displayLink() {
178
171
form . classList . add ( 'was-validated' ) ;
179
172
if ( form . checkValidity ( ) ) {
180
173
var hubUrl = document . getElementById ( 'hub' ) . value ;
181
- var repoUrl = document . getElementById ( 'repo' ) . value ;
182
174
var driveUrl = document . getElementById ( 'drive-url' ) . value ;
183
175
var dropUrl = document . getElementById ( 'drop-url' ) . value ;
184
- var webUrl = document . getElementById ( 'web-url' ) . value ;
185
- var gitBranch = document . getElementById ( 'branch' ) . value ;
176
+ var webUrl = document . getElementById ( 'standard-url' ) . value ;
177
+ var envRepoUrl = document . getElementById ( 'env-repo' ) . value ;
178
+ var envGitBranch = document . getElementById ( 'env-branch' ) . value ;
186
179
var contentRepoUrl = document . getElementById ( 'content-repo' ) . value ;
187
180
var contentRepoBranch = document . getElementById ( 'content-branch' ) . value ;
188
181
var filePath = document . getElementById ( 'filepath' ) . value ;
@@ -193,7 +186,7 @@ function displayLink() {
193
186
if ( appName === 'custom' ) {
194
187
var urlPath = document . getElementById ( 'urlpath' ) . value ;
195
188
} else {
196
- var repoName = generateCloneDirectoryName ( repoUrl ) ;
189
+ var repoName = generateCloneDirectoryName ( contentRepoUrl ) ;
197
190
if ( source !== "git" ) {
198
191
repoName = ""
199
192
}
@@ -209,30 +202,30 @@ function displayLink() {
209
202
branch = "" ;
210
203
compressed = true ;
211
204
if ( source == "git" ) {
212
- sourceUrl = repoUrl ;
213
- branch = gitBranch ;
205
+ sourceUrl = contentRepoUrl ;
206
+ branch = contentRepoBranch ;
214
207
compressed = false ;
215
208
} else if ( source == "googledrive" ) {
216
209
sourceUrl = driveUrl ;
217
210
} else if ( source == "dropbox" ) {
218
211
sourceUrl = dropUrl ;
219
- } else if ( source == "web " ) {
212
+ } else if ( source == "standard " ) {
220
213
sourceUrl = webUrl ;
221
214
}
222
215
document . getElementById ( 'default-link' ) . value = generateRegularUrl (
223
- hubUrl , urlPath , sourceUrl , branch , compressed
216
+ hubUrl , urlPath , sourceUrl , branch , compressed , source
224
217
) ;
225
218
} else if ( activeTab === "tab-auth-canvas" ) {
226
219
document . getElementById ( 'canvas-link' ) . value = generateCanvasUrl (
227
- hubUrl , urlPath , repoUrl , gitBranch
220
+ hubUrl , urlPath , contentRepoUrl , contentRepoBranch
228
221
) ;
229
222
} else if ( activeTab === "tab-auth-binder" ) {
230
223
// FIXME: userName parsing using new URL(...) assumes a
231
224
// HTTP based repoUrl. Does it make sense to create a
232
225
// BinderHub link for SSH URLs? Then let's fix this parsing.
233
226
var userName = new URL ( repoUrl ) . pathname . split ( '/' ) [ 1 ] ;
234
227
document . getElementById ( 'binder-link' ) . value = generateBinderUrl (
235
- hubUrl , userName , repoName , gitBranch , urlPath , contentRepoUrl , contentRepoBranch
228
+ hubUrl , userName , repoName , envGitBranch , urlPath , contentRepoUrl , contentRepoBranch
236
229
) ;
237
230
}
238
231
} else {
@@ -272,18 +265,20 @@ function hideShowByClassName(cls, hideShow){
272
265
} ) ;
273
266
}
274
267
268
+
275
269
function displaySource ( ) {
276
270
var form = document . getElementById ( 'linkgenerator' ) ;
277
271
var source = form . querySelector ( 'input[name="source"]:checked' ) . value ;
278
272
hideShowByClassName ( ".source" , 'none' ) ;
273
+
279
274
if ( source == 'git' ) {
280
275
hideShowByClassName ( ".source-git" , '' ) ;
281
276
} else if ( source == 'googledrive' ) {
282
277
hideShowByClassName ( ".source-googledrive" , '' ) ;
283
278
} else if ( source == 'dropbox' ) {
284
279
hideShowByClassName ( ".source-dropbox" , '' ) ;
285
- } else if ( source == 'web' ) {
286
- hideShowByClassName ( ".source-web " , '' ) ;
280
+ } else if ( source == "standard" ) {
281
+ hideShowByClassName ( ".source-standard " , '' ) ;
287
282
}
288
283
}
289
284
@@ -298,7 +293,9 @@ function displaySource(){
298
293
function render ( ) {
299
294
var form = document . getElementById ( 'linkgenerator' ) ;
300
295
var appName = form . querySelector ( 'input[name="app"]:checked' ) . value ;
301
-
296
+ document . getElementById ( "env-repo-group" ) . style . display = 'none' ;
297
+ document . getElementById ( "env-repo" ) . disabled = true ;
298
+
302
299
if ( appName == 'custom' ) {
303
300
document . getElementById ( 'urlpath' ) . disabled = false ;
304
301
document . getElementById ( 'filepath' ) . disabled = true ;
@@ -312,8 +309,7 @@ function render() {
312
309
document . getElementById ( 'filepath' ) . disabled = false ;
313
310
}
314
311
}
315
-
316
-
312
+
317
313
displayLink ( ) ;
318
314
}
319
315
0 commit comments