Commit 1912ff25 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Implement filtering comments by tags.

For now the comment counts aren't shown in tags menu, but otherwise
it's working.
parent 08879b26
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -114,7 +114,8 @@ app.get('/auth/:sdk/:version/comments_recent', function(req, res) {
        hideCurrentUser: req.query.hideCurrentUser,
        hideRead: req.query.hideRead,
        username: req.query.username,
        targetId: req.query.targetId
        targetId: req.query.targetId,
        tagname: req.query.tagname
    };
    new Request(req).getRecentComments(query, function(comments) {
        res.json(comments);
+6 −0
Original line number Diff line number Diff line
var regexpQuote = require("regexp-quote");
var Targets = require("./targets");
var Formatter = require("./formatter");
var Tags = require("./tags");
@@ -118,6 +119,7 @@ Comments.prototype = {
     * @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 {Number} [opts.tagname=undefined] A tagname the comment is tagged with.
     *
     * @param {Function} callback Called with the result.
     * @param {Error} callback.err The error object.
@@ -176,6 +178,10 @@ Comments.prototype = {
        if (opts.targetId) {
            where.push(this.db.format("target_id = ?", [opts.targetId]));
        }
        if (opts.tagname) {
            var t = regexpQuote(opts.tagname);
            where.push(this.db.format("tags REGEXP ?", ['(^|\t)'+t+'(\t|$)']));
        }
        return where.join(" AND ");
    },

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

    it("#findRecent with tagname:feature includes only comments with that tag", function(done) {
        comments.findRecent({tagname: 'feature'}, function(err, rows) {
            expect(rows.length).toEqual(2);
            expect(rows.every(function(r){return /\bfeature\b/.test(r.tags);})).toEqual(true);
            done();
        });
    });

    it("#count gets total number of comments in current domain", function(done) {
        comments.count({}, function(err, cnt) {
            expect(cnt).toEqual(24);
+9 −1
Original line number Diff line number Diff line
@@ -59,6 +59,13 @@ Ext.define('Docs.controller.Comments', {
                    this.recentCommentsSettings.targetId = target && target.get("id");
                    this.fetchRecentComments();
                }
            },

            'commentsTags': {
                select: function(tag) {
                    this.recentCommentsSettings.tagname = tag && tag.get("tagname");
                    this.fetchRecentComments();
                }
            }
        });
    },
@@ -82,7 +89,8 @@ Ext.define('Docs.controller.Comments', {
            hideRead: settings.hideRead ? 1 : undefined,
            sortByScore: this.recentCommentsSettings.sortByScore ? 1 : undefined,
            username: this.recentCommentsSettings.username,
            targetId: this.recentCommentsSettings.targetId
            targetId: this.recentCommentsSettings.targetId,
            tagname: this.recentCommentsSettings.tagname
        };

        this.getCommentsFullList().setMasked(true);
+17 −16
Original line number Diff line number Diff line
/**
 * Container for recent comments and top users.
 * Menu for selecting between Users / Targets / Tags.
 */
Ext.define('Docs.view.comments.HeaderMenu', {
    extend: 'Ext.container.Container',
    alias: 'widget.commentsHeaderMenu',
    componentCls: "comments-header-menu",
    html: '<h1><a href="#" class="users selected">Users</a> <a href="#" class="targets">Topics</a></h1>',
    html: [
        '<h1>',
        '  <a href="#" class="users selected">Users</a>',
        '  <a href="#" class="targets">Topics</a>',
        '  <a href="#" class="tags">Tags</a>',
        '</h1>'
    ].join(""),

    /**
     * @event select
     * Fired when item in header menu selected.
     * @param {String} name Either "users" or "targets".
     * @param {String} type Either "users", "targets" or "tags".
     */

    afterRender: function() {
        this.callParent(arguments);

        var users = this.getEl().down("a.users");
        var targets = this.getEl().down("a.targets");
        Ext.Array.forEach(["users", "targets", "tags"], function(type) {
            var link = this.getEl().down("a."+type);

        users.on("click", function(event, target) {
            users.addCls("selected");
            targets.removeCls("selected");
            this.fireEvent("select", "users");
        }, this, {preventDefault: true});

        targets.on("click", function(event, target) {
            targets.addCls("selected");
            users.removeCls("selected");
            this.fireEvent("select", "targets");
            link.on("click", function(event, target) {
                this.getEl().select("a", true).removeCls("selected");
                link.addCls("selected");
                this.fireEvent("select", type);
            }, this, {preventDefault: true});
        }, this);
    }
});
Loading