Commit 7d4748b5 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Create list of topics.

For start show the list in place of users list.
parent 57fccd22
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -114,6 +114,13 @@ app.get('/auth/:sdk/:version/users', function(req, res) {
    });
});

// Returns the most commented targets.
app.get('/auth/:sdk/:version/targets', function(req, res) {
    new Request(req).getTopTargets(function(users) {
        res.json(users);
    });
});

// Returns number of comments for each class/member,
// and when user is logged in, all his subscriptions.
app.get('/auth/:sdk/:version/comments_meta', function(req, res) {
+21 −0
Original line number Diff line number Diff line
@@ -395,6 +395,27 @@ Comments.prototype = {
        this.db.query(sql, [this.domain], callback);
    },

    /**
     * Retrieves targets ordered by number of comments.
     * @param {Function} callback Called when done.
     * @param {String} callback.err Error message when query failed.
     * @param {Object} callback.targets The top targets.
     */
    getTopTargets: function(callback) {
        var sql = [
            "SELECT",
                "type,",
                "cls,",
                "member,",
                "COUNT(*) AS score",
            "FROM ", this.view,
            "WHERE domain = ?",
            "GROUP BY target_id",
            "ORDER BY score DESC"
        ];
        this.db.query(sql, [this.domain], callback);
    },

    // Helper that converts all `vote_dir` and `read` fields into
    // appropriate type. For some reason the vote_dir field is a
    // string by default, but we don't want that.  The `read` field is
+9 −0
Original line number Diff line number Diff line
@@ -62,6 +62,15 @@ Request.prototype = {
        });
    },

    /**
     * Retrieves most commented targets.
     */
    getTopTargets: function(callback) {
        this.db.comments().getTopTargets(function(err, targets) {
            callback(targets);
        });
    },

    /**
     * Provides the comments_meta request data.
     */
+14 −0
Original line number Diff line number Diff line
@@ -249,6 +249,20 @@ describe("Comments", function() {
        });
    });

    it("#getTopTargets gives all targets that have received posts in this domain", function(done) {
        comments.getTopTargets(function(err, targets) {
            expect(targets.length).toEqual(11);
            done();
        });
    });

    it("#getTopTargets sorts targets by number of comments", function(done) {
        comments.getTopTargets(function(err, targets) {
            expect(targets[0].score).toBeGreaterThan(targets[1].score);
            done();
        });
    });

    it("#add adds a new comment and returns its ID which we can then use to retrieve the comment", function(done) {
        var com = {
            user_id: 1,
+3 −2
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@ Ext.define('Docs.view.comments.Index', {
    mixins: ['Docs.view.Scrolling'],
    requires: [
        'Docs.view.comments.List',
        'Docs.view.comments.Users'
        'Docs.view.comments.Users',
        'Docs.view.comments.Targets'
    ],

    cls: 'comment-index',
@@ -21,7 +22,7 @@ Ext.define('Docs.view.comments.Index', {
        },
        {
            region: "east",
            xtype: "commentsusers",
            xtype: "commentstargets",
            width: 300,
            margin: '0 0 0 20'
        }
Loading