Commit 6e526be1 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Filter comments by selected user.

Allow selection of user from users list and then filter the comments
list to show only comments of that user.

The selection of user is not saved into settings, but is stored until
the next page refresh.
parent 3704922f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -99,7 +99,8 @@ app.get('/auth/:sdk/:version/comments_recent', function(req, res) {
        limit: parseInt(req.query.limit, 10),
        orderBy: req.query.sortByScore ? "vote" : "created_at",
        hideCurrentUser: req.query.hideCurrentUser,
        hideRead: req.query.hideRead
        hideRead: req.query.hideRead,
        username: req.query.username
    };
    new Request(req).getRecentComments(query, function(comments) {
        res.json(comments);
+5 −0
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ Comments.prototype = {
     * Two possible options here: "created_at" and "vote".
     * @param {Number} [opts.hideUser=undefined] A user_id to hide.
     * @param {Number} [opts.hideRead=false] True to hide comments marked as read.
     * @param {Number} [opts.username=undefined] The name of the user who's comments to show.
     *
     * @param {Function} callback Called with the result.
     * @param {Error} callback.err The error object.
@@ -138,6 +139,7 @@ Comments.prototype = {
     *
     * @param {Object} opts Options for the query:
     * @param {Number} [opts.hideUser=undefined] A user_id to hide.
     * @param {Number} [opts.username=undefined] The name of the user who's comments to show.
     *
     * @param {Function} callback Called with the result.
     * @param {Error} callback.err The error object.
@@ -164,6 +166,9 @@ Comments.prototype = {
        if (opts.hideRead) {
            where.push(this.getReadExpression() + " = 0");
        }
        if (opts.username) {
            where.push(this.db.format("username = ?", [opts.username]));
        }
        return where.join(" AND ");
    },

+14 −0
Original line number Diff line number Diff line
@@ -163,6 +163,13 @@ describe("Comments", function() {
        });
    });

    it("#findRecent with username:renku includes only comments by that user", function(done) {
        comments.findRecent({username: "renku"}, function(err, rows) {
            expect(rows.every(function(r){return r.username === "renku";})).toEqual(true);
            done();
        });
    });

    it("#count gets total number of comments in current domain", function(done) {
        comments.count({}, function(err, cnt) {
            expect(cnt).toEqual(24);
@@ -206,6 +213,13 @@ describe("Comments", function() {
        });
    });

    it("#count with username:renku includes only comments of that user", function(done) {
        comments.count({username: "renku"}, function(err, cnt) {
            expect(cnt).toEqual(5);
            done();
        });
    });

    it("#countPerTarget gets number of comments for each target", function(done) {
        comments.countsPerTarget(function(err, counts) {
            var line = counts.filter(function(row) { return row._id === "class__Ext__"; })[0];
+12 −1
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ Ext.define('Docs.controller.Comments', {
        }
    ],

    // Recent comments query parameters that aren't saved into cookies.
    recentCommentsSettings: {},

    init: function() {
        this.addEvents(
            /**
@@ -145,6 +148,13 @@ Ext.define('Docs.controller.Comments', {
                }
            },

            'topusers': {
                select: function(username) {
                    this.recentCommentsSettings.username = username;
                    this.fetchRecentComments();
                }
            },

            'classoverview toolbar': {
                commentcountclick: function(cmp) {
                    var commentsDiv = Ext.get(Ext.query('.comments-section .comments-div')[0]);
@@ -287,7 +297,8 @@ Ext.define('Docs.controller.Comments', {
            limit: 100,
            hideRead: settings.hideRead ? 1 : undefined,
            hideCurrentUser: settings.hideCurrentUser ? 1 : undefined,
            sortByScore: settings.sortByScore ? 1 : undefined
            sortByScore: settings.sortByScore ? 1 : undefined,
            username: this.recentCommentsSettings.username
        };

        this.getCommentsList().setMasked(true);
+26 −1
Original line number Diff line number Diff line
@@ -60,6 +60,31 @@ Ext.define('Docs.view.comments.TopUsers', {
    afterRender: function() {
        this.callParent(arguments);
        this.fetchUsers("votes");
        this.initClickHandlers();
    },

    initClickHandlers: function() {
        this.usersList.getEl().on("click", function(event, target) {
            var username = target.innerHTML;
            var li = Ext.get(target).up("li");

            // remove "selected" class from all other items and add it
            // to the current item unless it was already selected
            // before, in which case all items become unselected.
            var wasSelected = li.hasCls("selected");
            this.usersList.getEl().select("li").removeCls("selected");
            if (!wasSelected) {
                li.addCls("selected");
            }

            /**
             * @event select
             * Fired when user is selected from users list.
             * @param {String} username  The name of the user
             * or undefined when all users were deselected.
             */
            this.fireEvent("select", wasSelected ? undefined : username);
        }, this, {preventDefault: true, delegate: "a"});
    },

    fetchUsers: function(sortBy) {
@@ -84,7 +109,7 @@ Ext.define('Docs.view.comments.TopUsers', {
                    '<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>',
                    '<a href="#" class="username <tpl if="moderator">moderator</tpl>">{username}</a>',
                '</li>',
            '</tpl>',
            '</ul>'
Loading