Skip to content

Commit

Permalink
Add Script.installsSinceUpdate & show in author panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zren committed Sep 2, 2014
1 parent fbff03b commit 6621ee5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ exports.sendScript = function (aReq, aRes, aNext) {

// Update the install count
++aScript.installs;
++aScript.installsSinceUpdate;

aScript.save(function (aErr, aScript) { });
});
};
Expand Down Expand Up @@ -298,6 +300,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
if (aRemoved || (!aScript && (aUpdate || collaborators))) {
return aCallback(null);
} else if (!aScript) {
// New script
aScript = new Script({
name: isLibrary ? aMeta : aMeta.name,
author: aUser.name,
Expand All @@ -315,6 +318,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
_authorId: aUser._id
});
} else {
// Script already exists.
if (!aScript.isLib) {
if (collaborators && (aScript.meta.oujs && aScript.meta.oujs.author != aMeta.oujs.author
|| (aScript.meta.oujs && JSON.stringify(aScript.meta.oujs.collaborator) !=
Expand All @@ -325,6 +329,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) {
aScript.uses = libraries;
}
aScript.updated = new Date();
aScript.installsSinceUpdate = 0;
}

aScript.save(function (aErr, aScript) {
Expand Down
3 changes: 2 additions & 1 deletion models/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var scriptSchema = new Schema({
// Visible
name: String,
author: String,
installs: Number,
installs: { type: Number, default: 0 },
installsSinceUpdate: { type: Number, default: 0 },
rating: Number,
about: String,
updated: Date,
Expand Down
6 changes: 6 additions & 0 deletions views/includes/scriptAuthorToolsPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<li><a href="{{{script.scriptEditMetadataPageUrl}}}"><i class="fa fa-edit"></i> Edit Script Info</a></li>
<li><a href="{{{script.scriptEditSourcePageUrl}}}"><i class="fa fa-file-text"></i> Edit Script</a></li>
</ul>

<hr>

<h4>Installs per Version <small>since <time>2 Sept 2014</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>
</div>
</div>
<div class="panel panel-danger">
Expand Down

0 comments on commit 6621ee5

Please sign in to comment.