Skip to content

Commit

Permalink
Add Author Tools sidebar to scriptViewSourcePage (OpenUserJS#1291)
Browse files Browse the repository at this point in the history
* Move/show relevant author tools there

Applies to OpenUserJS#389 and post OpenUserJS#438

Auto-merge
  • Loading branch information
Martii committed Nov 29, 2017
1 parent decfa0e commit b1e9f02
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 18 deletions.
12 changes: 0 additions & 12 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var isDbg = require('../libs/debug').isDbg;
var async = require('async');
var _ = require('underscore');
var SPDX = require('spdx-license-ids');
var SPDXOSI = require('spdx-osi'); // NOTE: Sub-dep of `spdx-is-osi`

//--- Model inclusions
var Discussion = require('../models/discussion').Discussion;
Expand Down Expand Up @@ -43,8 +42,6 @@ var pageMetadata = require('../libs/templateHelpers').pageMetadata;
//--- Configuration inclusions
var removeReasons = require('../views/includes/scriptModals.json').removeReasons;

var blockSPDX = require('./blockSPDX');

//---

// Let controllers know this is a `new` route
Expand Down Expand Up @@ -400,15 +397,6 @@ exports.view = function (aReq, aRes, aNext) {
script.scriptPermalinkMetaPageUrl = 'https://' + aReq.get('host') +
script.scriptMetaPageUrl;

script.scriptAcceptableOSILicense = [];
SPDXOSI.forEach(function (aElement, aIndex, aArray) {
if (blockSPDX.indexOf(aElement) === -1) {
script.scriptAcceptableOSILicense.push({
shortIdSPDX: aElement
});
}
});

// Page metadata
pageMetadata(options, ['About', script.name, (script.isLib ? 'Libraries' : 'Userscripts')],
script.description);
Expand Down
55 changes: 54 additions & 1 deletion controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var async = require('async');
var _ = require('underscore');
var util = require('util');

var SPDX = require('spdx-license-ids');
var SPDXOSI = require('spdx-osi'); // NOTE: Sub-dep of `spdx-is-osi`

//--- Model inclusions
var Comment = require('../models/comment').Comment;
var Script = require('../models/script').Script;
Expand Down Expand Up @@ -56,6 +59,8 @@ var settings = require('../models/settings.json');

var removeReasons = require('../views/includes/userModals.json').removeReasons;

var blockSPDX = require('./blockSPDX');

//---

// WARNING: **Near** duplicate in scriptStorage.js for installName
Expand Down Expand Up @@ -1869,6 +1874,9 @@ exports.editScript = function (aReq, aRes, aNext) {
//
var script = null;
var scriptOpenIssueCountQuery = null;
var collaborators = null;
var licenses = null;
var licensePrimary = null;

//---
if (aErr || !aScript) {
Expand All @@ -1878,7 +1886,22 @@ exports.editScript = function (aReq, aRes, aNext) {

// Script
options.script = script = modelParser.parseScript(aScript);
options.isOwner = authedUser && authedUser._id == script._authorId;

collaborators = scriptStorage.findMeta(aScript.meta, 'OpenUserJS.collaborator.value');
if (!collaborators) {
collaborators = []; // NOTE: Watchpoint
}

licenses = scriptStorage.findMeta(aScript.meta, 'UserScript.license.value');
if (licenses) {
licensePrimary = licenses[licenses.length - 1];
script.licensePrimary = licensePrimary.substr(0, (licensePrimary.indexOf(';') > -1
? licensePrimary.indexOf(';')
: undefined)).replace(/\+$/, '');
}

options.isOwner = authedUser && (authedUser._id == script._authorId
|| collaborators.indexOf(authedUser.name) > -1);
modelParser.renderScript(script);
script.installNameSlug = installNameBase;
script.scriptPermalinkInstallPageUrl = 'https://' + aReq.get('host') +
Expand All @@ -1891,6 +1914,22 @@ exports.editScript = function (aReq, aRes, aNext) {
script.scriptRawPageXUrl = '/src/' + (isLib ? 'libs' : 'scripts') + '/'
+ scriptStorage.getInstallNameBase(aReq, { encoding: 'uri' }) +
(isLib ? '.min.js#' : '.min.user.js#');
script.scriptPermalinkMetaPageUrl = 'https://' + aReq.get('host') +
script.scriptMetaPageUrl;

script.scriptAcceptableOSILicense = [];
SPDXOSI.forEach(function (aElement, aIndex, aArray) {
if (blockSPDX.indexOf(aElement) === -1) {
script.scriptAcceptableOSILicense.push({
shortIdSPDX: aElement
});
}
});

// User
if (options.isOwner) {
options.authorTools = {};
}

// Page metadata
pageMetadata(options);
Expand All @@ -1908,6 +1947,20 @@ exports.editScript = function (aReq, aRes, aNext) {
async.parallel(tasks, asyncComplete);
});
} else {
options.authorTools = {};
options.isScriptViewSourcePage = true;

options.script = {};
options.script.licensePrimary = 'MIT'; // NOTE: Site default
options.script.scriptAcceptableOSILicense = [];
SPDXOSI.forEach(function (aElement, aIndex, aArray) {
if (blockSPDX.indexOf(aElement) === -1) {
options.script.scriptAcceptableOSILicense.push({
shortIdSPDX: aElement
});
}
});

//---
async.parallel(tasks, asyncComplete);
}
Expand Down
10 changes: 10 additions & 0 deletions views/includes/scriptAuthorToolsPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
<div class="panel-title"><i class="fa fa-fw fa-user"></i> Author Tools</div>
</div>
<div class="panel-body">
{{^isScriptViewSourcePage}}
<ul class="nav nav-pills nav-justified">
<li><a rel="nofollow" href="{{{script.scriptEditMetadataPageUrl}}}"><i class="fa fa-edit"></i> Edit Script Info</a></li>
<li><a rel="nofollow" href="{{{script.scriptEditSourcePageUrl}}}"><i class="fa fa-file-text"></i> Edit Script</a></li>
</ul>
{{/isScriptViewSourcePage}}
{{#isScriptViewSourcePage}}
{{^script.isLib}}
{{^newScript}}
<div class="form-group">
<div class="input-group col-xs-12">
<span class="input-group-btn">
Expand All @@ -24,6 +28,7 @@
</span>
</div>
</div>
{{/newScript}}
{{/script.isLib}}
<div class="input-group">
<div class="input-group-btn">
Expand All @@ -44,12 +49,16 @@
</a>
</span>
</div>
{{/isScriptViewSourcePage}}
{{^isScriptViewSourcePage}}
{{^script.isLib}}
<h4>Installs per Version <small>effective <time title='Tue Sep 2 2014'>Sep '14</time></small></h4>
<p><code>{{script.meta.version}}{{^script.meta.version}}Current{{/script.meta.version}}</code> <span class="label label-default">{{script.installsSinceUpdate}} installs</span></p>
{{/script.isLib}}
{{/isScriptViewSourcePage}}
</div>
</div>
{{^isScriptViewSourcePage}}
<div class="panel panel-danger">
<div class="panel-heading">
<div class="panel-title"><i class="fa fa-fw fa-bolt"></i> Danger Zone</div>
Expand All @@ -60,4 +69,5 @@ <h4>Installs per Version <small>effective <time title='Tue Sep 2 2014'>Sep '14</
</ul>
</div>
</div>
{{/isScriptViewSourcePage}}
{{/authorTools}}
4 changes: 2 additions & 2 deletions views/includes/scripts/selectSPDX.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

for (i = 0; thisOSISPDX = listOSISPDX[i++];) {
thisOSISPDX.addEventListener('click', onClick);
if (thisOSISPDX.textContent === 'MIT') {
// NOTE: Site default
if (thisOSISPDX.textContent === '{{script.licensePrimary}}') {
thisOSISPDX.classList.add('active');
thisOSISPDX.click();
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions views/pages/scriptPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,5 @@ <h4>Userscripts Using This Library</h4>
{{> includes/footer.html }}
{{> includes/scripts/lazyIconScript.html }}
{{> includes/scripts/clipboard.html }}
{{#authorTools}}
{{ > includes/scripts/selectSPDX.html}}
{{/authorTools}}
</body>
</html>
14 changes: 14 additions & 0 deletions views/pages/scriptViewSourcePage.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
{{> includes/header.html }}
<div class="container-fluid">
<div class="row">
{{#owner}}
<div class="container-fluid col-sm-8">
{{/owner}}
{{^owner}}
<div class="col-md-12">
{{/owner}}
{{^newScript}}{{> includes/scriptPageHeader.html }}{{/newScript}}
<pre id="editor">{{source}}</pre>
{{^readOnly}}
Expand All @@ -35,10 +40,19 @@
</form>
{{/readOnly}}
</div>
{{#owner}}
<div class="container-fluid col-sm-4">
{{> includes/scriptAuthorToolsPanel.html }}
</div>
{{/owner}}
</div>
</div>
{{> includes/footer.html }}
{{> includes/scripts/lazyIconScript.html }}
{{> includes/scripts/clipboard.html }}
{{#authorTools}}
{{ > includes/scripts/selectSPDX.html}}
{{/authorTools}}
{{> includes/scripts/scriptEditor.html }}
</body>
</html>

0 comments on commit b1e9f02

Please sign in to comment.