Loading comments/app.js +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ app.get('/auth/:sdk/:version/comments_recent', function(req, res) { // Returns the most upvoted users. app.get('/auth/:sdk/:version/users', function(req, res) { new Request(req).getTopUsers(function(users) { new Request(req).getTopUsers(req.query.sortBy, function(users) { res.json(users); }); }); Loading comments/lib/api_adapter.js +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ module.exports = { return { id: user.id, username: user.username, vote: user.vote, score: user.score, moderator: user.moderator, emailHash: crypto.createHash('md5').update(user.email).digest("hex") }; Loading comments/lib/comments.js +11 −3 Original line number Diff line number Diff line Loading @@ -362,22 +362,30 @@ Comments.prototype = { /** * Retrieves users ordered by number of upvotes. * @param {String} sortBy Either "votes" or "comments" * @param {Function} callback Called when done. * @param {String} callback.err Error message when login failed. * @param {Object} callback.users The top users. */ getTopUsers: function(callback) { getTopUsers: function(sortBy, callback) { if (sortBy === "votes") { var score = "COALESCE(SUM(vote), 0) AS score"; } else { var score = "COUNT(*) AS score"; } var sql = [ "SELECT", "user_id AS id,", "username,", "email,", "moderator,", "COALESCE(SUM(vote), 0) AS vote", score, "FROM ", this.view, "WHERE domain = ?", "GROUP BY user_id", "ORDER BY vote DESC" "ORDER BY score DESC" ]; this.db.query(sql, [this.domain], callback); }, Loading comments/lib/request.js +2 −2 Original line number Diff line number Diff line Loading @@ -56,8 +56,8 @@ Request.prototype = { /** * Retrieves most upvoted users. */ getTopUsers: function(callback) { this.db.comments().getTopUsers(function(err, users) { getTopUsers: function(sortBy, callback) { this.db.comments().getTopUsers(sortBy, function(err, users) { callback(users.map(ApiAdapter.userToJson, ApiAdapter)); }); }, Loading template/app/controller/Comments.js +10 −4 Original line number Diff line number Diff line Loading @@ -138,6 +138,9 @@ Ext.define('Docs.controller.Comments', { 'commentindex': { settingChange: function() { this.fetchRecentComments(); }, usersTabChange: function(sortBy) { this.fetchUsers(sortBy); } }, Loading Loading @@ -167,15 +170,18 @@ Ext.define('Docs.controller.Comments', { if (!this.recentComments) { this.fetchRecentComments(); this.recentComments = true; this.fetchUsers(); this.fetchUsers("votes"); } this.callParent([true]); }, fetchUsers: function() { fetchUsers: function(sortBy) { this.request("jsonp", { url: '/users', method: 'GET', params: { sortBy: sortBy }, success: function(users) { this.renderUsers(users); }, Loading Loading @@ -650,7 +656,7 @@ Ext.define('Docs.controller.Comments', { '<ul>', '<tpl for=".">', '<li>', '<span class="score">{vote}</span>', '<span class="score">{score}</span>', '<img class="avatar" width="25" height="25" src="http://www.gravatar.com/avatar/{emailHash}', '?s=25&r=PG&d=http://www.sencha.com/img/avatar.png">', '<span class="username <tpl if="moderator">moderator</tpl>">{username}</span>', Loading @@ -658,7 +664,7 @@ Ext.define('Docs.controller.Comments', { '</tpl>', '</ul>' ); tpl.append(Ext.get("top-users"), users); tpl.overwrite(Ext.get("top-users"), users); }, renderComments: function(rows, id, opts) { Loading Loading
comments/app.js +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ app.get('/auth/:sdk/:version/comments_recent', function(req, res) { // Returns the most upvoted users. app.get('/auth/:sdk/:version/users', function(req, res) { new Request(req).getTopUsers(function(users) { new Request(req).getTopUsers(req.query.sortBy, function(users) { res.json(users); }); }); Loading
comments/lib/api_adapter.js +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ module.exports = { return { id: user.id, username: user.username, vote: user.vote, score: user.score, moderator: user.moderator, emailHash: crypto.createHash('md5').update(user.email).digest("hex") }; Loading
comments/lib/comments.js +11 −3 Original line number Diff line number Diff line Loading @@ -362,22 +362,30 @@ Comments.prototype = { /** * Retrieves users ordered by number of upvotes. * @param {String} sortBy Either "votes" or "comments" * @param {Function} callback Called when done. * @param {String} callback.err Error message when login failed. * @param {Object} callback.users The top users. */ getTopUsers: function(callback) { getTopUsers: function(sortBy, callback) { if (sortBy === "votes") { var score = "COALESCE(SUM(vote), 0) AS score"; } else { var score = "COUNT(*) AS score"; } var sql = [ "SELECT", "user_id AS id,", "username,", "email,", "moderator,", "COALESCE(SUM(vote), 0) AS vote", score, "FROM ", this.view, "WHERE domain = ?", "GROUP BY user_id", "ORDER BY vote DESC" "ORDER BY score DESC" ]; this.db.query(sql, [this.domain], callback); }, Loading
comments/lib/request.js +2 −2 Original line number Diff line number Diff line Loading @@ -56,8 +56,8 @@ Request.prototype = { /** * Retrieves most upvoted users. */ getTopUsers: function(callback) { this.db.comments().getTopUsers(function(err, users) { getTopUsers: function(sortBy, callback) { this.db.comments().getTopUsers(sortBy, function(err, users) { callback(users.map(ApiAdapter.userToJson, ApiAdapter)); }); }, Loading
template/app/controller/Comments.js +10 −4 Original line number Diff line number Diff line Loading @@ -138,6 +138,9 @@ Ext.define('Docs.controller.Comments', { 'commentindex': { settingChange: function() { this.fetchRecentComments(); }, usersTabChange: function(sortBy) { this.fetchUsers(sortBy); } }, Loading Loading @@ -167,15 +170,18 @@ Ext.define('Docs.controller.Comments', { if (!this.recentComments) { this.fetchRecentComments(); this.recentComments = true; this.fetchUsers(); this.fetchUsers("votes"); } this.callParent([true]); }, fetchUsers: function() { fetchUsers: function(sortBy) { this.request("jsonp", { url: '/users', method: 'GET', params: { sortBy: sortBy }, success: function(users) { this.renderUsers(users); }, Loading Loading @@ -650,7 +656,7 @@ Ext.define('Docs.controller.Comments', { '<ul>', '<tpl for=".">', '<li>', '<span class="score">{vote}</span>', '<span class="score">{score}</span>', '<img class="avatar" width="25" height="25" src="http://www.gravatar.com/avatar/{emailHash}', '?s=25&r=PG&d=http://www.sencha.com/img/avatar.png">', '<span class="username <tpl if="moderator">moderator</tpl>">{username}</span>', Loading @@ -658,7 +664,7 @@ Ext.define('Docs.controller.Comments', { '</tpl>', '</ul>' ); tpl.append(Ext.get("top-users"), users); tpl.overwrite(Ext.get("top-users"), users); }, renderComments: function(rows, id, opts) { Loading