Skip to content

Commit

Permalink
Start removing old views. Hide unauthed panels. Fixup voting/flagging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zren committed Jun 5, 2014
1 parent 4e182b3 commit df552c7
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 290 deletions.
9 changes: 4 additions & 5 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ var getScriptPageTasks = function(options) {

// Setup the voting UI
tasks.push(function (callback) {
var voteUrl = script.url + '/vote/';
options.voteUpUrl = voteUrl + 'up';
options.voteDownUrl = voteUrl + 'down';
var voteUrl = '/vote' + script.scriptPageUrl;
options.voteUpUrl = voteUrl + '/up';
options.voteDownUrl = voteUrl + '/down';
options.unvoteUrl = voteUrl + '/unvote';

options.voteable = false;
options.votedUp = false;
Expand All @@ -141,10 +142,8 @@ var getScriptPageTasks = function(options) {
if (voteModel) {
if (voteModel.vote) {
options.votedUp = true;
options.voteUpUrl = voteUrl + 'unvote';
} else {
options.votedDown = true;
options.voteDownUrl = voteUrl + 'unvote';
}
}

Expand Down
5 changes: 3 additions & 2 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ var setupFlagUserUITask = function(options) {
return function(callback) {
var flagUrl = '/flag/users/' + user.name;

// Can't flag when not logged in or when user owns the script.
if (!user || options.isOwner) {
// Can't flag when not logged in or when is authedUser.
if (!authedUser || options.isYou) {
callback();
return;
}
flagLib.flaggable(User, user, authedUser, function (canFlag, author, flag) {
console.log(canFlag, author, flag);
if (flag) {
flagUrl += '/unflag';
options.flagged = true;
Expand Down
9 changes: 4 additions & 5 deletions libs/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ var maxKarma = 10;
// This is heavily commented so that my logic and
// reasoning is documented for myself and others.
function flaggable (model, content, user, callback) {
// Not logged in or role is above moderator
// No one above a moderator is part of the moderation system
// since they can just remove content directly
if (!user || user.role < 3) { return callback(false); }
// Not logged in.
if (!user) { return callback(false); }


// You can't flag yourself
// Only someone less than an admin can be flagged
Expand Down Expand Up @@ -69,7 +68,7 @@ function getThreshold (model, content, author, callback) {
var threshold = thresholds[model.modelName] * (author.role < 4 ? 2 : 1);

// Calculate karma and add it to the threshold
getKarma(author, maxKarma, function (karma) {
getKarma(author, maxKarma, function (karma) {
return callback(threshold + karma);
});
}
Expand Down
4 changes: 2 additions & 2 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ exports.parseScript = function(scriptData) {
var script = scriptData.toObject ? scriptData.toObject() : scriptData;

// Script Good/Bad bar.
// script.votes = upvotes
// script.flags = downvotes + flags?
// script.votes = count(upvotes) + count(downvotes)
// script.flags = flags - count(upvotes)
var sumVotesAndFlags = script.votes + script.flags;
var votesRatio = sumVotesAndFlags > 0 ? script.votes / sumVotesAndFlags : 0;
var flagsRatio = sumVotesAndFlags > 0 ? script.flags / sumVotesAndFlags : 0;
Expand Down
18 changes: 13 additions & 5 deletions libs/modelQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,28 @@ var parseUserSearchQuery = function(userListQuery, query) {
exports.parseCommentSearchQuery = parseCommentSearchQuery;


var applyHideFlaggedFromModelListQuery = function(modelListQuery, options) {
var applyModelListQueryFlaggedFilter = function(modelListQuery, options, flaggedQuery) {
// Only list flagged items if authedUser >= moderator or if authedUser owns the item.
if (options.isYou || options.isMod) {
// Show
// Mod
if (flaggedQuery) {
if (flaggedQuery == 'true') {
modelListQuery.find({flagged: true});
} else if (flaggedQuery == false) {
modelListQuery.find({flagged: {$ne: true}});
}
}
} else {
// Hide
// Script.flagged is undefined by default.
modelListQuery.find({flagged: {$ne: true}});
modelListQuery.find({flagged: {$ne: true}});
}
};
exports.applyHideFlaggedFromModelListQuery = applyHideFlaggedFromModelListQuery;
exports.applyModelListQueryFlaggedFilter = applyModelListQueryFlaggedFilter;

var applyModelListQueryDefaults = function(modelListQuery, options, req, defaultOptions) {
// flagged
applyHideFlaggedFromModelListQuery(modelListQuery, options);
applyModelListQueryFlaggedFilter(modelListQuery, options, req.query.flagged);

// Search
if (req.query.q) {
Expand Down
6 changes: 0 additions & 6 deletions views/404.html

This file was deleted.

17 changes: 0 additions & 17 deletions views/apiAdmin.html

This file was deleted.

21 changes: 0 additions & 21 deletions views/commentsList.html

This file was deleted.

45 changes: 0 additions & 45 deletions views/discussion.html

This file was deleted.

16 changes: 0 additions & 16 deletions views/discussionCreate.html

This file was deleted.

20 changes: 0 additions & 20 deletions views/discussions.html

This file was deleted.

28 changes: 0 additions & 28 deletions views/discussionsList.html

This file was deleted.

14 changes: 14 additions & 0 deletions views/includes/flagModelSnippet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-4 control-label">Flags</label>
<div class="col-sm-8">
<p class="form-control-static">{{flags}}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Threshold</label>
<div class="col-sm-8">
<p class="form-control-static">{{#threshold}}{{threshold}}{{/threshold}}</p>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions views/includes/scriptAdminToolsPanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{#isAdmin}}
{{/isAdmin}}
6 changes: 4 additions & 2 deletions views/includes/scriptAuthorToolsPanel.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{{#isOwner}}
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">Author Tools</div>
</div>
<div class="panel-body">
<ul class="nav nav-pills nav-justified">
<li><a href="{{{scriptEditMetadataPageUrl}}}" class=""><i class="fa fa-edit"></i> Edit Script Info</a></li>
<li><a href="{{{scruptEditSourcePageUrl}}}" class=""><i class="fa fa-file-text"></i> Edit Script</a></li>
<li><a href="{{{script.scriptEditMetadataPageUrl}}}" class=""><i class="fa fa-edit"></i> Edit Script Info</a></li>
<li><a href="{{{script.scriptEditSourcePageUrl}}}" class=""><i class="fa fa-file-text"></i> Edit Script</a></li>
</ul>
</div>
</div>
{{/isOwner}}
6 changes: 3 additions & 3 deletions views/includes/scriptModToolsPanel.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{{#isMod}}
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">Mod Tools</div>
</div>
<div class="panel-body">
<ul class="nav nav-pills nav-justified">
<li><a href="#" class="disabled"><i class="fa fa-trash-o"></i> Spam</a></li>
</ul>
{{> includes/flagModelSnippet.html }}
</div>
</div>
{{/isMod}}
2 changes: 0 additions & 2 deletions views/includes/scriptSidePanel.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{#script}}
{{> includes/scriptUserToolsPanel.html }}
{{> includes/scriptAuthorToolsPanel.html }}
{{> includes/scriptModToolsPanel.html }}
{{> includes/scriptAdminToolsPanel.html }}
{{/script}}
10 changes: 5 additions & 5 deletions views/includes/scriptUserToolsPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<div class="panel-body">
<div class="row">
<div class="pull-left vote-area">
<a href="{{{voteUpUrl}}}" class="btn-vote {{^voteable}}disabled{{/voteable}} {{#votedUp}}active{{/votedUp}}"><i class="fa fa-2x fa-caret-up"></i></a>
<a href="{{{voteDownUrl}}}" class="btn-vote {{^voteable}}disabled{{/voteable}} {{#votedDown}}active{{/votedDown}}"><i class="fa fa-2x fa-caret-down"></i></a>
<a href="{{^votedUp}}{{{voteUpUrl}}}{{/votedUp}}{{#votedUp}}{{{unvoteUrl}}}{{/votedUp}}" class="btn-vote {{^voteable}}disabled{{/voteable}} {{#votedUp}}active{{/votedUp}}"><i class="fa fa-2x fa-caret-up"></i></a>
<a href="{{^votedDown}}{{{voteDownUrl}}}{{/votedDown}}{{#votedDown}}{{{unvoteUrl}}}{{/votedDown}}" class="btn-vote {{^voteable}}disabled{{/voteable}} {{#votedDown}}active{{/votedDown}}"><i class="fa fa-2x fa-caret-down"></i></a>
</div>
<p><i class="fa fa-fw fa-signal"></i> <b>Rating:</b> {{rating}}</p>
<p><i class="fa fa-fw fa-signal"></i> <b>Rating:</b> {{script.rating}}</p>
<div class="progress">
<div style="width: {{votesPercent}}%" class="progress-bar progress-bar-good">{{#votes}}{{votes}}<i class="fa fa-fw fa-caret-up"></i>{{/votes}}</div>
<div style="width: {{flagsPercent}}%" class="progress-bar progress-bar-danger">{{#flags}}{{flags}}<i class="fa fa-fw fa-caret-down"></i>{{/flags}}</div>
<div style="width: {{script.votesPercent}}%" class="progress-bar progress-bar-good">{{#script.votes}}{{script.votes}}<i class="fa fa-fw fa-caret-up"></i>{{/script.votes}}</div>
<div style="width: {{script.flagsPercent}}%" class="progress-bar progress-bar-danger">{{#script.flags}}{{script.flags}}<i class="fa fa-fw fa-caret-down"></i>{{/script.flags}}</div>
</div>
</div>
<ul class="nav nav-pills nav-justified">
Expand Down
4 changes: 1 addition & 3 deletions views/includes/userModToolsPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
</div>
</div>
<div class="panel-body">
<ul class="nav nav-pills nav-justified">
<li><a href="{{{flagUrl}}}" class="{{^canFlag}}disabled{{/canFlag}}"><i class="fa fa-flag{{^flagged}}-o{{/flagged}}"></i> {{#flagged}}Unflag{{/flagged}}{{^flagged}}Flag{{/flagged}}</a></a></li>
</ul>
{{> includes/flagModelSnippet.html }}
</div>
</div>
{{/modTools}}
1 change: 1 addition & 0 deletions views/includes/userSidePanel.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{> includes/userToolsPanel.html }}
{{> includes/userUserToolsPanel.html }}
{{> includes/userModToolsPanel.html }}
{{> includes/userAdminToolsPanel.html }}
7 changes: 7 additions & 0 deletions views/includes/userUserToolsPanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="panel panel-default">
<div class="panel-body">
<ul class="nav nav-pills nav-justified">
<li><a href="{{{flagUrl}}}" class="{{^canFlag}}disabled{{/canFlag}}"><i class="fa fa-flag{{^flagged}}-o{{/flagged}}"></i> {{#flagged}}Unflag{{/flagged}}{{^flagged}}Flag{{/flagged}}</a></a></li>
</ul>
</div>
</div>
30 changes: 0 additions & 30 deletions views/index.html

This file was deleted.

Loading

0 comments on commit df552c7

Please sign in to comment.