Skip to content

Commit 76f5a65

Browse files
authored
statusCodePage enhance further (#1289)
* Use some more *bootstrap* classes * Show which file erred out on repos that have multiple scripts. *(and singles)* Post #1284 Auto-merge
1 parent bd16545 commit 76f5a65

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

controllers/user.js

+52-7
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,9 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
12041204
var authedUser = aReq.session.user;
12051205
var githubUserId = null;
12061206
var githubRepoName = null;
1207+
var githubDefaultBranch = null;
1208+
var githubPathName = null;
1209+
var githubPathExt = null;
12071210
var githubBlobPath = null;
12081211

12091212
// Session
@@ -1218,6 +1221,9 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
12181221
options.isOwnRepo = authedUser.ghUsername && authedUser.ghUsername === options.githubUserId;
12191222

12201223
options.githubRepoName = githubRepoName = aReq.body.repo || aReq.query.repo;
1224+
options.githubDefaultBranch = githubDefaultBranch = aReq.body.default_branch || aReq.query.default_branch;
1225+
options.githubPathName = githubPathName = aReq.body.pathname || aReq.query.pathname;
1226+
options.githubPathExt = githubPathExt = aReq.body.pathext || aReq.query.pathext;
12211227
options.githubBlobPath = githubBlobPath = aReq.body.path || aReq.query.path;
12221228

12231229
if (!(githubUserId && githubRepoName && githubBlobPath)) {
@@ -1284,7 +1290,17 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
12841290
if (aErr) {
12851291
statusCodePage(aReq, aRes, aNext, {
12861292
statusCode: aErr.status.code,
1287-
statusMessage: aErr.status.message
1293+
statusMessage: aErr.status.message,
1294+
isCustomView: true,
1295+
statusData: {
1296+
isGHImport: true,
1297+
utf_pathname: githubPathName,
1298+
utf_pathext: githubPathExt,
1299+
user: encodeURIComponent(githubUserId),
1300+
repo: encodeURIComponent(githubRepoName),
1301+
default_branch: encodeURIComponent(githubDefaultBranch),
1302+
path: encodeURIComponent(githubBlobPath)
1303+
}
12881304
});
12891305
return;
12901306
}
@@ -1329,7 +1345,21 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
13291345
}
13301346
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
13311347
} else {
1332-
aCallback('Specified file does not contain the proper metadata blocks.');
1348+
statusCodePage(aReq, aRes, aNext, {
1349+
statusCode: 400,
1350+
statusMessage: 'Specified file does not contain the proper metadata blocks.',
1351+
isCustomView: true,
1352+
statusData: {
1353+
isGHImport: true,
1354+
utf_pathname: githubPathName,
1355+
utf_pathext: githubPathExt,
1356+
user: encodeURIComponent(githubUserId),
1357+
repo: encodeURIComponent(githubRepoName),
1358+
default_branch: encodeURIComponent(githubDefaultBranch),
1359+
path: encodeURIComponent(githubBlobPath)
1360+
}
1361+
});
1362+
return;
13331363
}
13341364

13351365
} else if (options.javascriptBlob.isJSLibrary) {
@@ -1360,11 +1390,23 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
13601390
}
13611391
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
13621392
} else {
1363-
aCallback('Specified file does not contain the proper metadata blocks.');
1393+
statusCodePage(aReq, aRes, aNext, {
1394+
statusCode: 400,
1395+
statusMessage: 'Specified file does not contain the proper metadata blocks.',
1396+
isCustomView: true,
1397+
statusData: {
1398+
isGHImport: true,
1399+
utf_pathname: githubPathName,
1400+
utf_pathext: githubPathExt,
1401+
user: encodeURIComponent(githubUserId),
1402+
repo: encodeURIComponent(githubRepoName),
1403+
default_branch: encodeURIComponent(githubDefaultBranch),
1404+
path: encodeURIComponent(githubBlobPath)
1405+
}
1406+
});
1407+
return;
13641408
}
13651409

1366-
1367-
13681410
} else {
13691411
aCallback('Invalid filetype.');
13701412
}
@@ -1373,8 +1415,11 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
13731415
var script = null;
13741416

13751417
if (aErr) {
1376-
console.error(aErr);
1377-
console.error(githubUserId, githubRepoName, githubBlobPath);
1418+
console.error([
1419+
aErr,
1420+
authedUser.name + ' ' + githubUserId + ' ' + githubRepoName + ' ' + githubBlobPath
1421+
1422+
].join('\n'));
13781423
statusCodePage(aReq, aRes, aNext, {
13791424
statusCode: 400,
13801425
statusMessage: aErr

views/pages/statusCodePage.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,20 @@ <h1 class="status-code text-center">{{statusCode}}</h1>
4444
{{#isAdminSessionLengthView}}
4545
Session Length: <strong>{{length}}</strong>
4646
{{/isAdminSessionLengthView}}
47+
{{#isGHImport}}
48+
{{{statusMessage}}}<br /><a href="https://github.com/{{user}}/{{repo}}/tree/{{default_branch}}/{{path}}"><b>{{utf_pathname}}</b>{{utf_pathext}}</a>
49+
{{/isGHImport}}
4750
{{/statusData}}
4851
{{/isCustomView}}
4952
{{^isCustomView}}
5053
{{{statusMessage}}}
5154
{{/isCustomView}}
5255
</p>
53-
<p class="text-center"> <a id="action" href="#"></a></p>
56+
<div class="text-center">
57+
<ul class="nav navpills">
58+
<li><a id="action" href="#"></a></li>
59+
</ul>
60+
</div>
5461
</div>
5562
</div>
5663
</div>

views/pages/userGitHubRepoPage.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ <h2><a href="{{{userGitHubRepoListPageUrl}}}" class="script-author">{{repo.owner
3333
<form action="{{{authedUser.userGitHubImportPageUrl}}}" method="post"{{#openImportInNewTab}} target="_blank"{{/openImportInNewTab}}>
3434
<input type="hidden" name="user" value="{{repo.owner.login}}">
3535
<input type="hidden" name="repo" value="{{repo.name}}">
36+
<input type="hidden" name="default_branch" value="{{repo.default_branch}}">
3637
<input type="hidden" name="path" value="{{path.full}}">
38+
<input type="hidden" name="pathname" value="{{path.name}}">
39+
<input type="hidden" name="pathext" value="{{path.ext}}">
3740
<button type="submit" class="btn btn-sm btn-{{^isOwnRepo}}warning{{/isOwnRepo}}{{#isOwnRepo}}success{{/isOwnRepo}} pull-right {{^canUpload}}disabled{{/canUpload}}"><i class="octicon octicon-fw octicon-repo-clone"></i> Import</a>
3841
</form>
3942
</div>
40-
4143
<p>
4244
<a href="https://github.com/{{repo.owner.login}}/{{repo.name}}/tree/{{repoAsEncoded.default_branch}}/{{pathAsEncoded.full}}" target="_blank">{{path.dir}}<b>{{path.name}}</b>{{path.ext}}</a>
4345
<span class="label label-default">{{size}} bytes</span>

0 commit comments

Comments
 (0)