Commit 7606c2c6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Update class index comment counts.

Just rebuild the entire total-comments-per-class cache.
We could do it in a smarter way, but as it only needs to be
done when posting/deleting comments, it happens rarely enough.
And the performance is actually just good-enough; no noticable lag.
parent 2e55ec44
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ Ext.define('Docs.CommentCounts', {
     * @return {Number} The resulting total amount of comments.
     */
    change: function(target, amount) {
        // reset the totals cache
        delete this.totals;

        return this.counts[target.join("__")] = this.get(target) + amount;
    },

+7 −0
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@ Ext.define('Docs.controller.CommentCounts', {
            ref: "class",
            selector: "classoverview"
        },
        {
            ref: "classIndex",
            selector: "#classindex"
        },
        {
            ref: 'guide',
            selector: '#guide'
@@ -37,8 +41,11 @@ Ext.define('Docs.controller.CommentCounts', {

    updateCounts: function(target, count) {
        this.getClass().updateCommentCounts();
        this.getClassIndex().updateCommentCounts();

        this.getGuide().updateCommentCounts();
        this.getGuideIndex().updateCommentCounts();

        this.getVideo().updateCommentCounts();
        this.getVideoIndex().updateCommentCounts();
    }
+16 −0
Original line number Diff line number Diff line
@@ -36,6 +36,10 @@ Ext.define('Docs.view.cls.Index', {
            return;
        }

        this.initComments();
    },

    initComments: function() {
        this.getEl().select("a.docClass").each(function(a) {
            var className = a.getHTML();
            var count = Docs.Comments.getClassTotalCount(className);
@@ -45,6 +49,18 @@ Ext.define('Docs.view.cls.Index', {
        }, this);
    },

    /**
     * Updates all comment counters.
     */
    updateCommentCounts: function() {
        if (!this.getEl()) {
            return;
        }

        this.getEl().select(".comment-counter-small").remove();
        this.initComments();
    },

    /**
     * Returns tab config for classes page if at least one class.
     * @return {Object}