Skip to content

Commit d4e64e4

Browse files
committed
changes to get provider in
1 parent 0886c68 commit d4e64e4

File tree

2 files changed

+97
-98
lines changed

2 files changed

+97
-98
lines changed

_static/link_gen/link.js

+40-44
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Pure function that generates an nbgitpuller URL
2-
function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed) {
2+
function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed, source) {
33

44
// assume hubUrl is a valid URL
55
var url = new URL(hubUrl);
66

77
url.searchParams.set('repo', repoUrl);
88

99
if(compressed) {
10-
url.searchParams.set('compressed', "true");
10+
url.searchParams.set('provider', source);
1111
}
1212

1313
if (urlPath) {
@@ -16,6 +16,8 @@ function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed) {
1616

1717
if (branch) {
1818
url.searchParams.set('branch', branch);
19+
} else if(source == "git"){
20+
url.searchParams.set('branch', "main");
1921
}
2022

2123
if (!url.pathname.endsWith('/')) {
@@ -110,53 +112,42 @@ function clearLinks(){
110112
document.getElementById('canvas-link').value = "";
111113
}
112114

113-
var stateSource = null;
115+
114116
function changeTab(div) {
115117
var hub = document.getElementById("hub");
116118
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");
119122
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");
122123
var id = div.id;
123124
var form = document.getElementById('linkgenerator');
124125

125126
clearLinks();
126127
if (id.includes("binder")) {
127-
document.getElementById("app-source").hidden = true;
128128
hub.placeholder = "https://mybinder.org";
129129
hub.value = "https://mybinder.org";
130130
hub_help_text.hidden = true;
131131
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+
142140
} else {
143-
document.getElementById("app-source").hidden = false;
144141
hub.placeholder = "https://hub.example.com";
145142
hub.value = "";
146143
hub_help_text.hidden = false;
147144
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;
153145

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+
159149
}
150+
displaySource();
160151
}
161152

162153
/**
@@ -167,6 +158,8 @@ function changeTab(div) {
167158
* See https://github.com/git/git/blob/1c52ecf4ba0f4f7af72775695fee653f50737c71/builtin/clone.c#L276
168159
*/
169160
function generateCloneDirectoryName(gitCloneUrl) {
161+
if(gitCloneUrl.slice(-1) == "/")
162+
gitCloneUrl = gitCloneUrl.slice(0,-1);
170163
var lastPart = gitCloneUrl.split('/').slice(-1)[0];
171164
return lastPart.split(':').slice(-1)[0].replace(/(\.git|\.bundle)?/, '');
172165
}
@@ -178,11 +171,11 @@ function displayLink() {
178171
form.classList.add('was-validated');
179172
if (form.checkValidity()) {
180173
var hubUrl = document.getElementById('hub').value;
181-
var repoUrl = document.getElementById('repo').value;
182174
var driveUrl = document.getElementById('drive-url').value;
183175
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;
186179
var contentRepoUrl = document.getElementById('content-repo').value;
187180
var contentRepoBranch = document.getElementById('content-branch').value;
188181
var filePath = document.getElementById('filepath').value;
@@ -193,7 +186,7 @@ function displayLink() {
193186
if (appName === 'custom') {
194187
var urlPath = document.getElementById('urlpath').value;
195188
} else {
196-
var repoName = generateCloneDirectoryName(repoUrl);
189+
var repoName = generateCloneDirectoryName(contentRepoUrl);
197190
if(source !== "git"){
198191
repoName = ""
199192
}
@@ -209,30 +202,30 @@ function displayLink() {
209202
branch = "";
210203
compressed = true;
211204
if(source == "git"){
212-
sourceUrl = repoUrl;
213-
branch = gitBranch;
205+
sourceUrl = contentRepoUrl;
206+
branch = contentRepoBranch;
214207
compressed = false;
215208
} else if(source == "googledrive"){
216209
sourceUrl = driveUrl;
217210
} else if(source == "dropbox"){
218211
sourceUrl = dropUrl;
219-
} else if(source == "web"){
212+
} else if(source == "standard"){
220213
sourceUrl = webUrl;
221214
}
222215
document.getElementById('default-link').value = generateRegularUrl(
223-
hubUrl, urlPath, sourceUrl, branch, compressed
216+
hubUrl, urlPath, sourceUrl, branch, compressed, source
224217
);
225218
} else if (activeTab === "tab-auth-canvas"){
226219
document.getElementById('canvas-link').value = generateCanvasUrl(
227-
hubUrl, urlPath, repoUrl, gitBranch
220+
hubUrl, urlPath, contentRepoUrl, contentRepoBranch
228221
);
229222
} else if (activeTab === "tab-auth-binder"){
230223
// FIXME: userName parsing using new URL(...) assumes a
231224
// HTTP based repoUrl. Does it make sense to create a
232225
// BinderHub link for SSH URLs? Then let's fix this parsing.
233226
var userName = new URL(repoUrl).pathname.split('/')[1];
234227
document.getElementById('binder-link').value = generateBinderUrl(
235-
hubUrl, userName, repoName, gitBranch, urlPath, contentRepoUrl, contentRepoBranch
228+
hubUrl, userName, repoName, envGitBranch, urlPath, contentRepoUrl, contentRepoBranch
236229
);
237230
}
238231
} else {
@@ -272,18 +265,20 @@ function hideShowByClassName(cls, hideShow){
272265
});
273266
}
274267

268+
275269
function displaySource(){
276270
var form = document.getElementById('linkgenerator');
277271
var source = form.querySelector('input[name="source"]:checked').value;
278272
hideShowByClassName(".source", 'none');
273+
279274
if(source == 'git'){
280275
hideShowByClassName(".source-git", '');
281276
} else if(source == 'googledrive'){
282277
hideShowByClassName(".source-googledrive", '');
283278
} else if(source == 'dropbox'){
284279
hideShowByClassName(".source-dropbox", '');
285-
} else if(source == 'web'){
286-
hideShowByClassName(".source-web", '');
280+
} else if(source =="standard"){
281+
hideShowByClassName(".source-standard", '');
287282
}
288283
}
289284

@@ -298,7 +293,9 @@ function displaySource(){
298293
function render() {
299294
var form = document.getElementById('linkgenerator');
300295
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+
302299
if (appName == 'custom') {
303300
document.getElementById('urlpath').disabled = false;
304301
document.getElementById('filepath').disabled = true;
@@ -312,8 +309,7 @@ function render() {
312309
document.getElementById('filepath').disabled = false;
313310
}
314311
}
315-
316-
312+
317313
displayLink();
318314
}
319315

link.html

+57-54
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,34 @@ <h1>nbgitpuller link generator<a class="headerlink" href="#nbgitpuller-link-gene
222222
</div>
223223
</div>
224224

225+
<div class="form-group row source-env" id="env-repo-group" >
226+
<label for="env-repo" class="col-sm-2 col-form-label">Git Environment Repository URL</label>
227+
<div class="col-sm-6">
228+
<input class="form-control" type="text" id="env-repo" placeholder="https://github.com/example/test"
229+
oninput="displayLink()" required pattern="((git|https?)://.+|git@.+:.+)">
230+
<div class="invalid-feedback">
231+
Must be a valid git URL
232+
</div>
233+
<small class="form-text text-muted" id="env-repo-help-text" >
234+
The environment repository must have
235+
<a href="https://github.com/jupyterhub/nbgitpuller">nbgitpuller</a> installed.
236+
</small>
237+
</div>
238+
<div class="col-sm-4">
239+
<div class="input-group">
240+
<div class="input-group-prepend">
241+
<span class="input-group-text" id="branch-prepend-label">branch</span>
242+
</div>
243+
<input name="branch" id="env-branch" type="text" aria-label="Branch Name" aria-describedby="branch-prepend-label">
244+
<small id="default-repo-message" class="form-text text-muted">
245+
If left blank, the default branch of your repository is used. Also note, Github now names the default branch <code>main</code> instead of <code>master</code> on
246+
<a href="https://github.blog/changelog/2020-10-01-the-default-branch-for-newly-created-repositories-is-now-main/">
247+
new GitHub repositories</a>
248+
</small>
249+
</div>
250+
</div>
251+
</div>
252+
225253
<div class="form-group row" id="app-source">
226254
<div class="col-sm-2 col-form-label">
227255
<label for="app" class=>Notebook Source</label>
@@ -248,56 +276,31 @@ <h1>nbgitpuller link generator<a class="headerlink" href="#nbgitpuller-link-gene
248276
</label>
249277
</div>
250278
<div class="form-check">
251-
<input class="form-check-input" type="radio" name="source" id="source-web" value="web">
252-
<label class="form-check-label text-dark" for="source-web">
279+
<input class="form-check-input" type="radio" name="source" id="source-standard" value="standard">
280+
<label class="form-check-label text-dark" for="source-standard">
253281
Web(Public URL to archive)
254282
</label>
255283
</div>
256284
</div>
257285
</div>
258-
<div class="form-group row source source-git">
259-
<label for="repo" class="col-sm-2 col-form-label">Git Repository URL</label>
260-
<div class="col-sm-6">
261-
<input class="form-control" type="text" id="repo" placeholder="https://github.com/example/test"
262-
oninput="displayLink()" required pattern="((git|https?)://.+|git@.+:.+)">
263-
<div class="invalid-feedback">
264-
Must be a valid git URL
265-
</div>
266-
<small class="form-text text-muted" id="env-repo-help-text" hidden="true">
267-
The environment repository must have
268-
<a href="https://github.com/jupyterhub/nbgitpuller">nbgitpuller</a> installed.
269-
</small>
270-
</div>
271-
<div class="col-sm-4">
272-
<div class="input-group">
273-
<div class="input-group-prepend">
274-
<span class="input-group-text" id="branch-prepend-label">branch</span>
275-
</div>
276-
<input name="branch" id="branch" type="text" aria-label="Branch Name" aria-describedby="branch-prepend-label">
277-
<small id="default-repo-message" class="form-text text-muted">
278-
If left blank, the default branch of your repository is used. Also note, Github now names the default branch <code>main</code> instead of <code>master</code> on
279-
<a href="https://github.blog/changelog/2020-10-01-the-default-branch-for-newly-created-repositories-is-now-main/">
280-
new GitHub repositories</a>
281-
</small>
282-
</div>
283-
</div>
284-
</div>
285-
286-
<div class="form-group row source source-git" id="content-repo-group" hidden="true">
286+
287+
288+
289+
<div class="form-group row source source-git" id="content-repo-group">
287290
<label for="content-repo" class="col-sm-2 col-form-label">Git Content Repository URL</label>
288291
<div class="col-sm-6">
289292
<input class="form-control" type="text" id="content-repo" placeholder="https://github.com/example/test"
290-
oninput="displayLink()" pattern="((git|https?)://.+|git@.+:.+)">
293+
oninput="displayLink()" required pattern="((git|https?)://.+|git@.+:.+)">
291294
<div class="invalid-feedback">
292295
Must be a valid git URL
293296
</div>
294297
</div>
295298
<div class="col-sm-4">
296-
<div class="input-group" id="content-branch-group" hidden="true">
299+
<div class="input-group" id="content-branch-group" >
297300
<div class="input-group-prepend">
298301
<span class="input-group-text" id="content-branch-prepend-label">branch</span>
299302
</div>
300-
<input name="content-branch" id="content-branch" type="text" aria-label="Branch Name" aria-describedby="content-branch-prepend-label">
303+
<input name="content-branch" id="content-branch" type="text" placeholder="main" aria-label="Branch Name" aria-describedby="content-branch-prepend-label">
301304
<small id="default-content-message" class="form-text text-muted">
302305
If left blank, the default branch of your repository is used. Also note, Github now names the default branch <code>main</code> instead of <code>master</code> on
303306
<a href="https://github.blog/changelog/2020-10-01-the-default-branch-for-newly-created-repositories-is-now-main/">
@@ -307,50 +310,50 @@ <h1>nbgitpuller link generator<a class="headerlink" href="#nbgitpuller-link-gene
307310
</div>
308311
</div>
309312

310-
<div class="form-group row source source-git" id="filepath-container">
311-
<label for="filepath" class="col-sm-2 col-form-label">File to open</label>
312-
<div class="col-sm-10">
313-
<input class="form-control" type="text" id="filepath" placeholder="index.ipynb"
314-
oninput="displayLink()">
315-
<small class="form-text text-muted">
316-
This file or directory from within the repo will open when user clicks the link.
317-
</small>
318-
</div>
319-
</div>
320-
321313
<div class="form-group row source source-googledrive">
322-
<label for="repo" class="col-sm-2 col-form-label">Google Drive Shared Link</label>
314+
<label for="drive-url" class="col-sm-2 col-form-label">Google Drive Shared Link</label>
323315
<div class="col-sm-10">
324316
<input class="form-control" type="text" id="drive-url" placeholder="https://drive.google.com/file/d/1p3m0h5UGWdLkVVP0S1HpG2yeDlU/view?usp=sharing"
325-
oninput="displayLink()" required pattern="((https?)://.+|(drive.google).+:.+)">
317+
oninput="displayLink()" required pattern="https?:\/\/drive.google.com+">
326318
<div class="invalid-feedback">
327319
Must be a valid Google Drive URL
328320
</div>
329321
</div>
330322
</div>
331323

332324
<div class="form-group row source source-dropbox">
333-
<label for="repo" class="col-sm-2 col-form-label">Dropbox Shared Link</label>
325+
<label for="drop-url" class="col-sm-2 col-form-label">Dropbox Shared Link</label>
334326
<div class="col-sm-10">
335-
<input class="form-control" type="text" id="drop-url" placeholder="https://www.dropbox.com/s/w0q4eirtuht/example.tgz?dl=0"
336-
oninput="displayLink()" required pattern="((https?)://.+|(drive.google).+:.+)">
327+
<input class="form-control" type="text" id="drop-url" placeholder="https://www.dropbox.com/s/w0q4eirtuht/example.tgz?dl=0"
328+
oninput="displayLink()" required pattern="https?:\/\/.+dropbox.com+">
337329
<div class="invalid-feedback">
338330
Must be a valid Dropbox URL (Note: all the common compression formats work(e.g. zip, tar, tgz, etc))
339331
</div>
340332
</div>
341333
</div>
342334

343-
<div class="form-group row source source-web">
344-
<label for="repo" class="col-sm-2 col-form-label">Public URL to archive</label>
335+
<div class="form-group row source source-standard">
336+
<label for="standard-url" class="col-sm-2 col-form-label">Public URL to archive</label>
345337
<div class="col-sm-10">
346-
<input class="form-control" type="text" id="web-url" placeholder="https://example.com/materials-sp20-external.zip"
347-
oninput="displayLink()" required pattern="((https?)://.+|(drive.google).+:.+)">
338+
<input class="form-control" type="text" id="standard-url" placeholder="https://example.com/materials-sp20-external.zip"
339+
oninput="displayLink()" required pattern="https?://.+">
348340
<div class="invalid-feedback">
349341
Must be a valid public URL (Note: all the common compression formats work(e.g. zip, tar, tgz, etc))
350342
</div>
351343
</div>
352344
</div>
353345

346+
<div class="form-group row" id="filepath-container">
347+
<label for="filepath" class="col-sm-2 col-form-label">File to open</label>
348+
<div class="col-sm-10">
349+
<input class="form-control" type="text" id="filepath" placeholder="index.ipynb"
350+
oninput="displayLink()">
351+
<small class="form-text text-muted">
352+
This file or directory from within the repo will open when user clicks the link.
353+
</small>
354+
</div>
355+
</div>
356+
354357
<div class="form-group row" id="app-container">
355358
<div class="col-sm-2 col-form-label">
356359
<label for="app" class=>Application to Open</label>

0 commit comments

Comments
 (0)