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

Merge branch 'recent-comments-improvements'

parents f268e260 9a351c5b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -198,6 +198,10 @@ app.get('/auth/:sdk/:version/comments_recent', util.getCommentReads, function(re
        filter._id = { $nin: req.commentMeta.reads };
    }

    if (req.query.hideCurrentUser) {
        filter.userId = { $ne: req.session.user.userid };
    }

    Comment.find(filter).sort("createdAt", -1).run(function(err, comments) {
        var total_rows = comments.length;

+5 −0
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@ Ext.define("Docs.Settings", {
            "inherited": true,
            "accessor": true
        },
        comments: {
            hideRead: false,
            hideCurrentUser: false,
            sortByScore: false
        },
        showPrivateClasses: false,
        classTreeLogic: "PackageLogic"
    },
+16 −10
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ Ext.define('Docs.controller.Comments', {

    requires: [
        "Docs.view.auth.LoginHelper",
        "Docs.Settings",
        "Docs.Syntax",
        "Docs.Tip"
    ],
@@ -120,9 +121,7 @@ Ext.define('Docs.controller.Comments', {
                        [ '.readComment',          'click', this.readComment],
                        [ '.fetchMoreComments',    'click', this.fetchMoreComments],
                        [ '.voteCommentUp',        'click', this.voteUp],
                        [ '.voteCommentDown',      'click', this.voteDown],
                        [ '#hideRead',            'change', function() { this.fetchRecentComments(); }],
                        [ '#sortByScore',         'change', function() { this.fetchRecentComments(); }]
                        [ '.voteCommentDown',      'click', this.voteDown]
                    ], function(delegate) {
                        cmp.el.addListener(delegate[1], delegate[2], this, {
                            preventDefault: true,
@@ -136,6 +135,12 @@ Ext.define('Docs.controller.Comments', {
                }
            },

            'commentindex': {
                settingChange: function() {
                    this.fetchRecentComments();
                }
            },

            'classoverview toolbar': {
                commentcountclick: function(cmp) {
                    var commentsDiv = Ext.get(Ext.query('.comments-section .comments-div')[0]);
@@ -274,23 +279,24 @@ Ext.define('Docs.controller.Comments', {
     * Fetches the most recent comments
     */
    fetchRecentComments: function(offset) {
        var settings = Docs.Settings.get('comments');
        var params = {
            offset: offset || 0,
            limit: 100
            limit: 100,
            hideRead: settings.hideRead ? 1 : undefined,
            hideCurrentUser: settings.hideCurrentUser ? 1 : undefined,
            sortByScore: settings.sortByScore ? 1 : undefined
        };

        if (this.isChecked('hideRead')) {
            params.hideRead = 1;
        }
        if (this.isChecked('sortByScore')) {
            params.sortByScore = 1;
        }
        this.getIndex().setMasked(true);

        this.request("jsonp", {
            url: '/comments_recent',
            method: 'GET',
            params: params,
            success: function(response) {
                this.getIndex().setMasked(false);

                this.renderComments(response, 'recentcomments', {
                    hideCommentForm: true,
                    append: !!offset,
+73 −7
Original line number Diff line number Diff line
@@ -5,28 +5,94 @@ Ext.define('Docs.view.comments.Index', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.commentindex',
    mixins: ['Docs.view.Scrolling'],
    requires: ['Docs.Settings'],

    cls: 'comment-index iScroll',
    cls: 'comment-index',
    margin: '10 0 0 0',
    autoScroll: true,
    layout: 'fit',

    items: [
    dockedItems: [
        {
            xtype: 'component',
            dock: 'top',
            html: [
                '<h1>Recent Comments</h1>'
            ].join(" ")
        },
        {
            xtype: 'container',
            dock: 'left',
            width: 200,
            html: [
                '<h1>Recent Comments</h1>',
                '<ul id="comment-index-controls">',
                    '<li><label><input type="checkbox" name="hideRead" id="hideRead" /> Hide read</label></li>',
                    '<li><label><input type="checkbox" name="hideCurrentUser" id="hideCurrentUser" /> Hide current User</label></li>',
                    '<li><label><input type="checkbox" name="sortByScore" id="sortByScore" /> Sort by score</label></li>',
                '</ul>'
            ].join(" ")
        },
        }
    ],

    items: [
        {
            cls: 'iScroll',
            id: 'comment-index-container',
            autoScroll: true,
            items: [
                {
                    xtype: 'container',
                    id: 'recentcomments'
                }
            ]
        }
    ],

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

        this.setMasked(true);
    },

    /**
     * Masks or unmasks the container
     * @param {Boolean} masked True to show mask.
     */
    setMasked: function(masked) {
        var container = Ext.get('comment-index-container');
        if (container) {
            container[masked ? "mask" : "unmask"]();
        }
    },

    // Initializes all checkboxes from settings.
    // Bind event handlers to fire changeSetting event when checked/unchecked.
    initCheckboxes: function() {
        var settings = Docs.Settings.get("comments");
        Ext.Array.forEach(['hideRead', 'hideCurrentUser', 'sortByScore'], function(id) {
            var cb = Ext.get(id);
            if (cb) {
                cb.dom.checked = settings[id];
                cb.on("change", function() {
                    this.saveSetting(id, cb.dom.checked);
                    /**
                     * @event settingChange
                     * Fired when one of the comments settings checkboxes is checked/unchecked.
                     * @param {String} name The name of the setting
                     * @param {Boolean} enabled True if setting is turned on, false when off.
                     */
                    this.fireEvent("settingChange", id, cb.dom.checked);
                }, this);
            }
        }, this);
    },

    saveSetting: function(name, enabled) {
        var settings = Docs.Settings.get('comments');
        settings[name] = enabled;
        Docs.Settings.set('comments', settings);
    },

    /**
     * Returns tab config for comments page.
     * @return {Object}
+4 −1
Original line number Diff line number Diff line
@@ -300,7 +300,10 @@
    font-weight: bold; } }

#comment-index-controls {
  position: absolute;
  padding-top: 1em;
  li {
    list-style-type: none; } }

#comment-index-container .x-mask {
  opacity: 0.9;
  background: #fff url(../images/ajax-loader.gif) no-repeat center; }