Commit 76336231 authored by Nick Poulden's avatar Nick Poulden
Browse files

MORE comments

parent 01994761
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -45,8 +45,8 @@ Ext.define('Docs.Application', {
            Docs.initEventTracking();
        }

        // setInterval(function(){
        //     Ext.DomQuery.select('link')[4].href = "resources/css/viewport.css?" + Math.ceil(Math.random() * 100000000)
        // }, 1000);
        setInterval(function(){
            Ext.DomQuery.select('link')[4].href = "resources/css/viewport.css?" + Math.ceil(Math.random() * 100000000)
        }, 1000);
    }
});
+11 −9
Original line number Diff line number Diff line
@@ -25,7 +25,13 @@ Ext.define('Docs.controller.Auth', {
             * @event loggedOut
             * Fired after user logs out
             */
            "loggedOut"
            "loggedOut",

            /**
             * @event available
             * Fired if the authorisation is available
             */
            "available"
        );

        if (Ext.isIE) {
@@ -70,17 +76,13 @@ Ext.define('Docs.controller.Auth', {
            method: 'GET',
            cors: true,
            callback: function(options, success, response) {

                if (success) {
                if (response && response.responseText) {
                    this.currentUser = JSON.parse(response.responseText);
                    }

                    this.fireEvent('available');
                    if (this.currentUser) {
                        this.loggedIn();
                    } else {
                        this.setSid(null);
                        this.getAuth().showLoggedOut();
                        this.loggedOut();
                    }
                }
            },
+32 −20
Original line number Diff line number Diff line
@@ -42,32 +42,36 @@ Ext.define('Docs.controller.Comments', {
        );

        this.getController('Auth').on({
            available: function() {
                this.enableComments();
            },
            loggedIn:  function() {
                Docs.view.Comments.renderNewCommentForms();
            },
            loggedOut: function() {
                Docs.view.Comments.renderNewCommentForms()
            }
                Docs.view.Comments.renderNewCommentForms();
            },
            scope: this
        });

        this.getController('Classes').on({
            showClass: function(cls, opts) {
                if (opts.reRendered) {
                    Docs.view.Comments.renderClassCommentContainers(this.currentCls);
                }
                    this.renderClassCommentContainers(cls);
                }
            },
            scope: this
        });

        this.control({
            'viewport': {
                afterrender: function(cmp) {
                    // Map user interactions to methods
                    // Map comment interactions to methods
                    Ext.Array.each([
                        [ '.toggleComments',       'click', this.toggleComments],
                        [ '.toggleMemberComments', 'click', this.showMemberComments],
                        [ '.toggleNewComment',     'click', this.toggleNewComment],
                        [ '.toggleCommentGuide',   'click', this.toggleCommentGuide],
                        // [ '.toggleCodeEditor',     'click', this.toggleCodeEditor],
                        [ '.postComment',          'click', this.postComment],
                        [ '.updateComment',        'click', this.updateComment],
                        [ '.deleteComment',        'click', this.promptDeleteComment],
@@ -97,6 +101,14 @@ Ext.define('Docs.controller.Comments', {
        });
    },

    enableComments: function() {
        if (!this.commentsEnabled) {
            // alert(this.getController('Classes').currentCls)
            this.commentsEnabled = true;
            // Docs.view.Comments.renderClassCommentContainers(this.getController('Classes').currentCls);
        }
    },

    loadIndex: function() {
        this.fireEvent('loadIndex');
        Ext.getCmp('treecontainer').hide();
@@ -158,7 +170,7 @@ Ext.define('Docs.controller.Comments', {
                comment: comment
            },
            callback: function(options, success, response) {
                if (success) {
                if (response && response.responseText) {
                    var data = Ext.JSON.decode(response.responseText);
                    this.fireEvent('add', id);
                    textarea.editor.setValue('');
@@ -261,7 +273,7 @@ Ext.define('Docs.controller.Comments', {
                    }), true);

                    var textarea = editForm.down('textarea').dom;
                    this.makeCodeMirror(textarea);
                    Docs.view.Comments.makeCodeMirror(textarea);
                }
            },
            scope: this
@@ -404,6 +416,11 @@ Ext.define('Docs.controller.Comments', {
        this.getOverview().scrollToEl(commentsDiv, -20);
    },

    renderClassCommentContainers: function() {
        var cls = this.getController('Classes').currentCls;
        Docs.view.Comments.renderClassCommentContainers(cls);
    },

    renderComments: function(rows, id, opts) {

        opts = opts || {};
@@ -421,26 +438,21 @@ Ext.define('Docs.controller.Comments', {
        } else if (!comments.hasCls('hideCommentForm')) {

            var commentWrap = comments.down('.new-comment-wrap');

            if (this.loggedIn()) {
                var wrap = Docs.view.Comments.loggedInCommentTpl.overwrite(commentWrap, this.getController('Auth').currentUser, true),
                    textarea = wrap.down('textarea').dom;
                var wrap = Docs.view.Comments.loggedInCommentTpl.overwrite(commentWrap, this.getController('Auth').currentUser, true);

                this.makeCodeMirror(textarea);
                if (wrap) {
                    var textareaEl = wrap.down('textarea');
                    if (textareaEl) {
                        Docs.view.Comments.makeCodeMirror(textareaEl.dom);
                    }
                }
            } else {
                Docs.view.Comments.loggedOutCommentTpl.overwrite(commentWrap, {});
            }
        }
    },

    makeCodeMirror: function(textarea) {
        textarea.editor = CodeMirror.fromTextArea(textarea, {
            enterMode: "keep",
            mode: 'markdown',
            indentUnit: 4
        });
    },

    toggleNewComment: function(cmp, el) {
        if (!this.loggedIn()) {
            return;
+90 −75
Original line number Diff line number Diff line
@@ -34,78 +34,46 @@ Ext.define('Docs.controller.CommentsMeta', {
            'afterLoad'
        );

        this.getController('Auth').on({
            available: function() {
                this.fetchCommentMeta();
            },
            scope: this
        });

        this.getController('Comments').on({
            add: function(id) {
                this.updateMeta(Docs.commentMeta.idMap[id], 1);
                var clsId = Docs.commentMeta.idMap[id];
                Docs.view.Comments.updateClassCommentMeta(clsId[1]);
                this.updateClassCommentMeta(id, 1);
            },
            remove: function(id) {
                this.updateMeta(Docs.commentMeta.idMap[id], -1);
                var clsId = Docs.commentMeta.idMap[id];
                Docs.view.Comments.updateClassCommentMeta(clsId[1]);
                this.updateClassCommentMeta(id, -1);
            },
            scope: this
        });

        this.getController('Classes').on({
            showIndex: function() {
                if (this.metaLoaded) {
                    Docs.view.Comments.updateClassIndex();
                } else {
                    this.addListener('afterLoad', function() {
                        Docs.view.Comments.updateClassIndex();
                    }, this, {
                        single: true
                    });
                }
                this.updateClassIndex();
            },
            showClass: function(cls, opts) {
                if (opts.reRendered) {
                    if (this.metaLoaded) {
                        Docs.view.Comments.updateClassCommentMeta(cls);
                    } else {
                        this.addListener('afterLoad', function() {
                            Docs.view.Comments.updateClassCommentMeta(cls);
                        }, this, {
                            single: true
                        });
                    }
                    this.createCommentIdMap(this.getController('Classes').currentCls);
                    this.renderClassCommentMeta(cls);
                }
            },
            scope: this
        });

        // this.getController('Welcome').on({
        //     loadIndex: function() {
        //         if (!this.hasFetchedCommentLeaders) {
        //             this.fetchCommentLeaders();
        //             this.hasFetchedCommentLeaders = true;
        //         }
        //     },
        //     scope: this
        // });

        this.control({
            'hovermenu': {
                refresh : function(cmp) {
                    if (this.metaLoaded) {
                        Docs.view.Comments.renderHoverMenuMeta(cmp.el);
                    } else {
                        this.addListener('afterLoad', function() {
                            Docs.view.Comments.renderHoverMenuMeta(cmp.el);
                        }, this, {
                            single: true
                        });
                    }
                }
                refresh : this.refreshHoverMenu
            }
        });

        this.fetchCommentMeta();
    },

    /**
     * Fetch all comment meta data and populate a local store
     */
    fetchCommentMeta: function() {
        Ext.data.JsonP.request({
            url: Docs.baseUrl + '/' + Docs.commentsDb + '/_design/Comments/_view/by_target',
@@ -122,39 +90,40 @@ Ext.define('Docs.controller.CommentsMeta', {

                this.metaLoaded = true;
                this.fireEvent('afterLoad');
                Docs.view.Comments.updateClassIndex();
                this.updateClassIndex();
            },
            scope: this
        });
    },

    updateVoteMeta: function() {

        var id = Docs.App.getController('Classes').currentCls.name,
            startkey = Ext.JSON.encode(['class',id]),
            endkey = Ext.JSON.encode(['class',id,{}]),
            currentUser = this.getController('Auth').currentUser;

        if (!id) return;

        Ext.data.JsonP.request({
            url: Docs.baseUrl + '/' + Docs.commentsDb + '/_design/Comments/_list/with_vote/by_target',
            method: 'GET',
            params: {
                reduce: false,
                startkey: startkey,
                endkey: endkey,
                user: currentUser && currentUser.userName,
                votes: true
            },
            success: function(response) {
                console.log(response.rows)
            },
            scope: this
        });
    },
    // updateVoteMeta: function() {
    //
    //     var id = Docs.App.getController('Classes').currentCls.name,
    //         startkey = Ext.JSON.encode(['class',id]),
    //         endkey = Ext.JSON.encode(['class',id,{}]),
    //         currentUser = this.getController('Auth').currentUser;
    //
    //     if (!id) return;
    //
    //     Ext.data.JsonP.request({
    //         url: Docs.baseUrl + '/' + Docs.commentsDb + '/_design/Comments/_list/with_vote/by_target',
    //         method: 'GET',
    //         params: {
    //             reduce: false,
    //             startkey: startkey,
    //             endkey: endkey,
    //             user: currentUser && currentUser.userName,
    //             votes: true
    //         },
    //         success: function(response) {
    //             console.log(response.rows)
    //         },
    //         scope: this
    //     });
    // },

    fetchCommentLeaders: function() {

        Ext.data.JsonP.request({
            url: Docs.baseUrl + '/' + Docs.commentsDb + '/_design/Comments/_view/by_author',
            method: 'GET',
@@ -181,6 +150,15 @@ Ext.define('Docs.controller.CommentsMeta', {
        });
    },

    /**
     * Called when a comment is added or removed. Updates the meta table, then refreshes the view
     */
    updateClassCommentMeta: function(id, delta) {
        var clsId = Docs.commentMeta.idMap[id];
        this.updateMeta(clsId, delta);
        Docs.view.Comments.updateClassCommentMeta(clsId[1]);
    },

    /**
     * Update comment count info
     * @param key Path to class / property
@@ -196,7 +174,7 @@ Ext.define('Docs.controller.CommentsMeta', {
    },

    /**
     * Creates a mapping between comment element IDs and CouchDB view keys
     * Creates a mapping between comment element IDs and DB view keys.
     */
    createCommentIdMap: function(cls) {
        var key, commentId, member
@@ -212,6 +190,43 @@ Ext.define('Docs.controller.CommentsMeta', {
                }, this);
            }
        }
    },

    refreshHoverMenu: function(cmp) {
        if (this.metaLoaded) {
            Docs.view.Comments.renderHoverMenuMeta(cmp.el);
        } else {
            this.addListener('afterLoad', function() {
                Docs.view.Comments.renderHoverMenuMeta(cmp.el);
            }, this, {
                single: true
            });
        }
    },

    updateClassIndex: function() {
        if (this.getController('Comments').commentsEnabled) {
            if (this.metaLoaded) {
                Docs.view.Comments.updateClassIndex();
            } else {
                this.addListener('afterLoad', function() {
                    Docs.view.Comments.updateClassIndex();
                }, this, {
                    single: true
                });
            }
        }
    },

    renderClassCommentMeta: function(cls) {
        if (this.metaLoaded) {
            Docs.view.Comments.updateClassCommentMeta(cls);
        } else {
            this.addListener('afterLoad', function() {
                Docs.view.Comments.updateClassCommentMeta(cls);
            }, this, {
                single: true
            });
        }
    }
});
 No newline at end of file
+22 −3
Original line number Diff line number Diff line
@@ -62,7 +62,11 @@ Ext.define('Docs.view.Comments', {

        var commentTplMethods = {
            date: function(date) {
                return Ext.Date.format(new Date(date), 'm/d/y');
                try {
                    return Ext.Date.format(new Date(date), 'jS M \'y');
                } catch(e) {
                    return '';
                }
            },
            isMod: function() {
                return Docs.App.getController('Auth').currentUser.mod;
@@ -152,7 +156,7 @@ Ext.define('Docs.view.Comments', {

        this.loggedInCommentTpl = Ext.create('Ext.XTemplate',
            '<div class="new-comment{[values.hide ? "" : " open"]}">',
                '<a href="#" class="toggleNewComment"><span></span>Post a comment</a>',
                // '<a href="#" class="name toggleComments"><span></span>Viewing 8 comments</a>',
                '<form class="newCommentForm">',
                    '<span class="action">',
                        'Action: ',
@@ -162,6 +166,7 @@ Ext.define('Docs.view.Comments', {
                            '<option value="problem">Report a problem</option>',
                            '<option value="problem">Request a feature</option>',
                        '</select>',
                        ' on Ext.Base',
                    '</span>',
                    // '<a href="#" class="toggleCodeEditor" title="Toggle code editor">Code editor</a>',
                    '<textarea></textarea>',
@@ -337,13 +342,27 @@ Ext.define('Docs.view.Comments', {

            if (hideCommentForm) {
            } else if (Docs.App.getController('Auth').isLoggedIn()) {
                this.loggedInCommentTpl.overwrite(newComment, currentUser);

                // currentUser.

                var wrap = this.loggedInCommentTpl.overwrite(newComment, currentUser, true),
                    textarea = wrap.down('textarea').dom;

                this.makeCodeMirror(textarea);
            } else {
                this.loggedOutCommentTpl.overwrite(newComment, {});
            }
        }, this);
    },

    makeCodeMirror: function(textarea) {
        textarea.editor = CodeMirror.fromTextArea(textarea, {
            enterMode: "keep",
            mode: 'markdown',
            indentUnit: 4
        });
    },

    showMember: function(cls, member) {

        var memberEl = Ext.get(member).down('.long'),
Loading