Commit 06d6f95c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add list of users sorted by comment counts.

Now the tab panel of users list makes sense.
parent 938acfe7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
    });
});
+1 −1
Original line number Diff line number Diff line
@@ -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")
        };
+11 −3
Original line number Diff line number Diff line
@@ -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);
    },
+2 −2
Original line number Diff line number Diff line
@@ -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));
        });
    },
+10 −4
Original line number Diff line number Diff line
@@ -138,6 +138,9 @@ Ext.define('Docs.controller.Comments', {
            'commentindex': {
                settingChange: function() {
                    this.fetchRecentComments();
                },
                usersTabChange: function(sortBy) {
                    this.fetchUsers(sortBy);
                }
            },

@@ -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);
            },
@@ -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&amp;r=PG&amp;d=http://www.sencha.com/img/avatar.png">',
                    '<span class="username <tpl if="moderator">moderator</tpl>">{username}</span>',
@@ -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