Commit 05f30593 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Update class doc comment counts when comment added/removed.

parent 0bf58980
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ Ext.define('Docs.Application', {
                'Videos',
                'Tabs',
                'Comments',
                'CommentCounts',
                'Tests'
            ],
            launch: this.launch
+14 −7
Original line number Diff line number Diff line
@@ -16,15 +16,22 @@ Ext.define('Docs.CommentCounts', {
    },

    /**
     * Returns comments count for a specific item.
     * @param {String} type
     * @param {String} cls
     * @param {String} member
     * Returns comments count for a specific target.
     * @param {String[]} target
     * @return {Number}
     */
    get: function(type, cls, member) {
        var key = [type||"", cls||"", member||""].join("__");
        return this.counts[key];
    get: function(target) {
        return this.counts[target.join("__")] || 0;
    },

    /**
     * Changes comment count of a target by the given amount.
     * @param {String[]} target The target which count to change.
     * @param {Number} amount Usually +1 or -1.
     * @return {Number} The resulting total amount of comments.
     */
    change: function(target, amount) {
        return this.counts[target.join("__")] = this.get(target) + amount;
    },

    /**
+18 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
 * Provides a way to perform queries to the comments backend.
 */
Ext.define('Docs.Comments', {
    extend: 'Ext.util.Observable',
    singleton: true,
    requires: [
        "Docs.Auth",
@@ -96,8 +97,22 @@ Ext.define('Docs.Comments', {
    /**
     * @inheritdoc Docs.CommentCounts#get
     */
    getCount: function(type, cls, member) {
        return this.counts.get(type, cls, member);
    getCount: function(target) {
        return this.counts.get(target);
    },

    /**
     * @inheritdoc Docs.CommentCounts#change
     */
    changeCount: function(target, amount) {
        var count = this.counts.change(target, amount);
        /**
         * @event countChange
         * Fired when comment count of a target changes.
         * @param {String[]} target
         * @param {Number} count
         */
        this.fireEvent("countChange", target, count);
    },

    /**
@@ -153,6 +168,7 @@ Ext.define('Docs.Comments', {
            callback: function(options, success, response) {
                var data = Ext.JSON.decode(response.responseText);
                if (success && data.success) {
                    this.changeCount(target, +1);
                    callback && callback.call(scope, data.comment);
                }
            },
+26 −0
Original line number Diff line number Diff line
/**
 * Retrieving and posting Comments
 */
Ext.define('Docs.controller.CommentCounts', {
    extend: 'Ext.app.Controller',

    requires: [
        "Docs.Comments"
    ],

    refs: [
        {
            ref: "classOverview",
            selector: "classoverview"
        }
    ],

    init: function() {
        Docs.Comments.on("countChange", this.updateCounts, this);
    },

    updateCounts: function(target, count) {
        this.getClassOverview().updateCommentCounts();
    }

});
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ Ext.define('Docs.model.Comment', {
            success: function() {
                this.set("deleted", deleted);
                this.commit();
                Docs.Comments.changeCount(this.get("target"), deleted ? -1 : +1);
            },
            scope: this
        });
Loading