Skip to content

Commit b5b1e8e

Browse files
committed
JupyterHub link gen working
1 parent d4e64e4 commit b5b1e8e

File tree

2 files changed

+60
-36
lines changed

2 files changed

+60
-36
lines changed

_static/link_gen/link.js

+55-31
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed, source
1919
} else if(source == "git"){
2020
url.searchParams.set('branch', "main");
2121
}
22-
22+
2323
if (!url.pathname.endsWith('/')) {
2424
url.pathname += '/'
2525
}
@@ -28,20 +28,26 @@ function generateRegularUrl(hubUrl, urlPath, repoUrl, branch, compressed, source
2828
return url.toString();
2929
}
3030

31-
function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
31+
function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch, compressed, source) {
3232
// assume hubUrl is a valid URL
3333
var url = new URL(hubUrl);
3434

3535
var nextUrlParams = new URLSearchParams();
3636

3737
nextUrlParams.append('repo', repoUrl);
38-
38+
39+
if(compressed) {
40+
nextUrlParams.append('provider', source);
41+
}
42+
3943
if (urlPath) {
4044
nextUrlParams.append('urlpath', urlPath);
4145
}
4246

4347
if (branch) {
4448
nextUrlParams.append('branch', branch);
49+
} else if(source == "git"){
50+
nextUrlParams.append('branch', "main");
4551
}
4652

4753
var nextUrl = '/hub/user-redirect/git-pull?' + nextUrlParams.toString();
@@ -56,20 +62,26 @@ function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
5662
}
5763

5864
function generateBinderUrl(hubUrl, userName, repoName, branch, urlPath,
59-
contentRepoUrl, contentRepoBranch) {
65+
contentRepoUrl, contentRepoBranch, compressed, source) {
6066

6167
var url = new URL(hubUrl);
6268

6369
var nextUrlParams = new URLSearchParams();
6470

6571
nextUrlParams.append('repo', contentRepoUrl);
6672

73+
if(compressed) {
74+
nextUrlParams.append('provider', source);
75+
}
76+
6777
if (urlPath) {
6878
nextUrlParams.append('urlpath', urlPath);
6979
}
7080

7181
if (contentRepoBranch) {
7282
nextUrlParams.append('branch', contentRepoBranch);
83+
} else if(source == "git"){
84+
nextUrlParams.append('branch', "main");
7385
}
7486

7587
var nextUrl = 'git-pull?' + nextUrlParams.toString();
@@ -118,8 +130,8 @@ function changeTab(div) {
118130
var hub_help_text = document.getElementById("hub-help-text");
119131
var env_repo_group = document.getElementById("env-repo-group");
120132
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");
123135
var id = div.id;
124136
var form = document.getElementById('linkgenerator');
125137

@@ -131,11 +143,7 @@ function changeTab(div) {
131143
hub.labels[0].innerHTML = "BinderHub URL";
132144

133145
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;
139147

140148
} else {
141149
hub.placeholder = "https://hub.example.com";
@@ -144,8 +152,7 @@ function changeTab(div) {
144152
hub.labels[0].innerHTML = "JupyterHub URL";
145153

146154
env_repo_group.style.display = 'none';
147-
env_repo.required = false;
148-
155+
env_repo.disabled = true;
149156
}
150157
displaySource();
151158
}
@@ -164,6 +171,28 @@ function generateCloneDirectoryName(gitCloneUrl) {
164171
return lastPart.split(':').slice(-1)[0].replace(/(\.git|\.bundle)?/, '');
165172
}
166173

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+
}
167196

168197
function displayLink() {
169198
var form = document.getElementById('linkgenerator');
@@ -198,34 +227,30 @@ function displayLink() {
198227
urlPath = apps[appName].generateUrlPath(repoName + '/' + filePath);
199228
}
200229
}
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)
201239
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-
}
215240
document.getElementById('default-link').value = generateRegularUrl(
216-
hubUrl, urlPath, sourceUrl, branch, compressed, source
241+
hubUrl, urlPath, config["sourceUrl"], config["branch"], config["compressed"], source
217242
);
218243
} else if (activeTab === "tab-auth-canvas"){
219244
document.getElementById('canvas-link').value = generateCanvasUrl(
220-
hubUrl, urlPath, contentRepoUrl, contentRepoBranch
245+
hubUrl, urlPath, config["sourceUrl"], config["branch"], config["compressed"], source
221246
);
222247
} else if (activeTab === "tab-auth-binder"){
223248
// FIXME: userName parsing using new URL(...) assumes a
224249
// HTTP based repoUrl. Does it make sense to create a
225250
// BinderHub link for SSH URLs? Then let's fix this parsing.
226251
var userName = new URL(repoUrl).pathname.split('/')[1];
227252
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
229254
);
230255
}
231256
} else {
@@ -293,8 +318,7 @@ function displaySource(){
293318
function render() {
294319
var form = document.getElementById('linkgenerator');
295320
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+
298322

299323
if (appName == 'custom') {
300324
document.getElementById('urlpath').disabled = false;

link.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ <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" >
225+
<div class="form-group row source-env" id="env-repo-group" style="display:none">
226226
<label for="env-repo" class="col-sm-2 col-form-label">Git Environment Repository URL</label>
227227
<div class="col-sm-6">
228-
<input class="form-control" type="text" id="env-repo" placeholder="https://github.com/example/test"
228+
<input class="form-control" type="text" id="env-repo" disabled placeholder="https://github.com/example/test"
229229
oninput="displayLink()" required pattern="((git|https?)://.+|git@.+:.+)">
230230
<div class="invalid-feedback">
231231
Must be a valid git URL
@@ -240,7 +240,7 @@ <h1>nbgitpuller link generator<a class="headerlink" href="#nbgitpuller-link-gene
240240
<div class="input-group-prepend">
241241
<span class="input-group-text" id="branch-prepend-label">branch</span>
242242
</div>
243-
<input name="branch" id="env-branch" type="text" aria-label="Branch Name" aria-describedby="branch-prepend-label">
243+
<input name="branch" id="env-branch" type="text" placeholder="main" aria-label="Branch Name" aria-describedby="branch-prepend-label">
244244
<small id="default-repo-message" class="form-text text-muted">
245245
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
246246
<a href="https://github.blog/changelog/2020-10-01-the-default-branch-for-newly-created-repositories-is-now-main/">
@@ -314,7 +314,7 @@ <h1>nbgitpuller link generator<a class="headerlink" href="#nbgitpuller-link-gene
314314
<label for="drive-url" class="col-sm-2 col-form-label">Google Drive Shared Link</label>
315315
<div class="col-sm-10">
316316
<input class="form-control" type="text" id="drive-url" placeholder="https://drive.google.com/file/d/1p3m0h5UGWdLkVVP0S1HpG2yeDlU/view?usp=sharing"
317-
oninput="displayLink()" required pattern="https?:\/\/drive.google.com+">
317+
oninput="displayLink()" required pattern="https?:\/\/drive.google.com.+">
318318
<div class="invalid-feedback">
319319
Must be a valid Google Drive URL
320320
</div>
@@ -325,7 +325,7 @@ <h1>nbgitpuller link generator<a class="headerlink" href="#nbgitpuller-link-gene
325325
<label for="drop-url" class="col-sm-2 col-form-label">Dropbox Shared Link</label>
326326
<div class="col-sm-10">
327327
<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+">
328+
oninput="displayLink()" required pattern="https?:\/\/.+dropbox.com.+">
329329
<div class="invalid-feedback">
330330
Must be a valid Dropbox URL (Note: all the common compression formats work(e.g. zip, tar, tgz, etc))
331331
</div>

0 commit comments

Comments
 (0)