Commit b96520a4 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Filtering of recent comments list by target.

parent 7d4748b5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -100,7 +100,8 @@ app.get('/auth/:sdk/:version/comments_recent', function(req, res) {
        orderBy: req.query.sortByScore ? "vote" : "created_at",
        hideCurrentUser: req.query.hideCurrentUser,
        hideRead: req.query.hideRead,
        username: req.query.username
        username: req.query.username,
        targetId: req.query.targetId
    };
    new Request(req).getRecentComments(query, function(comments) {
        res.json(comments);
+6 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ Comments.prototype = {
     * @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 {Number} [opts.targetId=undefined] The ID of the target to show.
     *
     * @param {Function} callback Called with the result.
     * @param {Error} callback.err The error object.
@@ -140,6 +141,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 {Number} [opts.targetId=undefined] The ID of the target to show.
     *
     * @param {Function} callback Called with the result.
     * @param {Error} callback.err The error object.
@@ -169,6 +171,9 @@ Comments.prototype = {
        if (opts.username) {
            where.push(this.db.format("username = ?", [opts.username]));
        }
        if (opts.targetId) {
            where.push(this.db.format("target_id = ?", [opts.targetId]));
        }
        return where.join(" AND ");
    },

@@ -404,6 +409,7 @@ Comments.prototype = {
    getTopTargets: function(callback) {
        var sql = [
            "SELECT",
                "target_id AS id,",
                "type,",
                "cls,",
                "member,",
+14 −0
Original line number Diff line number Diff line
@@ -170,6 +170,13 @@ describe("Comments", function() {
        });
    });

    it("#findRecent with targetId:1 includes only comments for that target", function(done) {
        comments.findRecent({targetId: 1}, function(err, rows) {
            expect(rows.every(function(r){return r.target_id === 1;})).toEqual(true);
            done();
        });
    });

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

    it("#count with targetId:1 includes only comments of that target", function(done) {
        comments.count({targetId: 1}, 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];
+9 −1
Original line number Diff line number Diff line
@@ -155,6 +155,13 @@ Ext.define('Docs.controller.Comments', {
                }
            },

            'commentstargets': {
                select: function(target) {
                    this.recentCommentsSettings.targetId = target && target.get("id");
                    this.fetchRecentComments();
                }
            },

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

        this.getCommentsList().setMasked(true);
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ Ext.define('Docs.view.comments.Targets', {
                cls: "iScroll targets-list",
                autoScroll: true,
                store: Ext.create('Ext.data.Store', {
                    fields: ["type", "cls", "member", "score"]
                    fields: ["id", "type", "cls", "member", "score"]
                }),
                allowDeselect: true,
                tpl: [