Add toggle for inline comment visibility (bug 1115707) r?smacleod draft
authorbyron jones <glob@mozilla.com>
Fri, 02 Sep 2016 14:45:10 +0800
changeset 176 ecefa6ac2100bcd663965830597220225e3b5ac0
parent 175 bf7e26563eac2f5563dd24700429aa1d42059410
child 177 9f344050a3d17bd992ee2ae2e9e22676b43a86f0
child 178 d0a40c3a1a82d6df2dae8426485e5c5919eaad62
child 194 f2370c6d5958d1288fe377c99536f7f0b2c9ec8b
push idunknown
push userunknown
push dateunknown
reviewerssmacleod
bugs1115707
Add toggle for inline comment visibility (bug 1115707) r?smacleod Adds a button for toggling inline comments on diff view. Toggle state is stored in a cookie. Currently when comments are hidden they are completely hidden (as opposed to toggling between inline and bubbles). MozReview-Commit-ID: CRqBiGxs15y
reviewboard/reviewboard/static/rb/css/pages/diffviewer_mozreview.less
reviewboard/reviewboard/static/rb/js/models/userSessionModel_mozreview.js
reviewboard/reviewboard/static/rb/js/pages/views/diffViewerPageView_mozreview.js
reviewboard/reviewboard/templates/diffviewer/view_diff_mozreview.html
--- a/reviewboard/reviewboard/static/rb/css/pages/diffviewer_mozreview.less
+++ b/reviewboard/reviewboard/static/rb/css/pages/diffviewer_mozreview.less
@@ -928,9 +928,15 @@
       tr.selected-draft * { background: @diff-insert-selected-color; }
     }
     &.replace {
       tr.selected-draft * { background: @diff-replace-selected-color; }
     }
   }
 }
 
+#diffs.hide-ic {
+  .inlineCommentRow {
+    display: none;
+  }
+}
+
 // vim: set et ts=2 sw=2:
--- a/reviewboard/reviewboard/static/rb/js/models/userSessionModel_mozreview.js
+++ b/reviewboard/reviewboard/static/rb/js/models/userSessionModel_mozreview.js
@@ -114,16 +114,17 @@ StoredItems = RB.BaseResource.extend({
  * There should only ever be one instance of a UserSession. It should always
  * be created through UserSession.create, and retrieved through
  * UserSession.instance.
  */
 RB.UserSession = Backbone.Model.extend({
     defaults: {
         authenticated: false,
         diffsShowExtraWhitespace: false,
+        diffsHideInlineComments: false,
         fullName: null,
         loginURL: null,
         username: null,
         userPageURL: null,
         sessionURL: null,
         timezoneOffset: '0',
         watchedReviewGroupsURL: null,
         watchedReviewRequestsURL: null,
@@ -158,16 +159,24 @@ RB.UserSession = Backbone.Model.extend({
 
         this._bindCookie({
             attr: 'diffsShowExtraWhitespace',
             cookieName: 'show_ew',
             deserialize: function(value) {
                 return value !== 'false';
             }
         });
+
+        this._bindCookie({
+            attr: 'diffsHideInlineComments',
+            cookieName: 'hide_ic',
+            deserialize: function(value) {
+                return value === 'true';
+            }
+        });
     },
 
     /*
      * Toggles a boolean attribute.
      *
      * The attribute will be the inverse of the prior value.
      */
     toggleAttr: function(attr) {
--- a/reviewboard/reviewboard/static/rb/js/pages/views/diffViewerPageView_mozreview.js
+++ b/reviewboard/reviewboard/static/rb/js/pages/views/diffViewerPageView_mozreview.js
@@ -22,17 +22,18 @@ RB.DiffViewerPageView = RB.ReviewablePag
         '[x': '_selectPreviousComment',
         ']c': '_selectNextComment',
         '\x0d': '_recenterSelected',
         'rR': '_createComment'
     },
 
     events: _.extend({
         'click .toggle-whitespace-only-chunks': '_toggleWhitespaceOnlyChunks',
-        'click .toggle-show-whitespace': '_toggleShowExtraWhitespace'
+        'click .toggle-show-whitespace': '_toggleShowExtraWhitespace',
+        'click .toggle-inline-comments': '_toggleInlineComments'
     }, RB.ReviewablePageView.prototype.events),
 
     /*
      * Initializes the diff viewer page.
      */
     initialize: function() {
         var revisionInfo = this.model.get('revision'),
             curRevision = revisionInfo.get('revision'),
@@ -205,16 +206,25 @@ RB.DiffViewerPageView = RB.ReviewablePag
             model: this.model.get('pagination')
         });
         this._paginationView2.render();
         this.listenTo(this._paginationView2, 'pageSelected',
                       _.partial(this._onPageSelected, true));
 
         $diffs.bindClass(RB.UserSession.instance,
                          'diffsShowExtraWhitespace', 'ewhl');
+        if (RB.UserSession.instance.get('diffsShowExtraWhitespace')) {
+            this._$controls.find('.ew').toggle();
+        }
+
+        $diffs.bindClass(RB.UserSession.instance,
+                         'diffsHideInlineComments', 'hide-ic');
+        if (RB.UserSession.instance.get('diffsHideInlineComments')) {
+            this._$controls.find('.ic').toggle();
+        }
 
         this._setFiles();
 
         this._chunkHighlighter = new RB.ChunkHighlighterView();
         this._chunkHighlighter.render().$el.prependTo($diffs);
 
         $('#diff-details').removeClass('loading');
 
@@ -632,16 +642,29 @@ RB.DiffViewerPageView = RB.ReviewablePag
     _toggleShowExtraWhitespace: function() {
         this._$controls.find('.ew').toggle();
         RB.UserSession.instance.toggleAttr('diffsShowExtraWhitespace');
 
         return false;
     },
 
     /*
+     * Toggles the display of inline comments.
+     *
+     * A cookie will be set to the newy setting, so that
+     * the new option will be the default when viewing diffs.
+     */
+    _toggleInlineComments: function() {
+        this._$controls.find('.ic').toggle();
+        RB.UserSession.instance.toggleAttr('diffsHideInlineComments');
+
+        return false;
+    },
+
+    /*
      * Callback for when a new revision is selected.
      *
      * This supports both single revisions and interdiffs. If `base` is 0, a
      * single revision is selected. If not, the interdiff between `base` and
      * `tip` will be shown.
      *
      * This will always implicitly navigate to page 1 of any paginated diffs.
      */
--- a/reviewboard/reviewboard/templates/diffviewer/view_diff_mozreview.html
+++ b/reviewboard/reviewboard/templates/diffviewer/view_diff_mozreview.html
@@ -83,16 +83,20 @@
  <li><a href=".?collapse=1"><span class="fa fa-minus"></span> {% trans "Collapse changes" %}</a></li>
 {%    endif %}
 {%    if siteconfig_settings.diffviewer_show_trailing_whitespace %}
  <li class="ew" style="display:none;"><a href="#" class="toggle-show-whitespace"><span class="fa fa-minus"></span> {% trans "Hide extra whitespace" %}</a></li>
  <li class="ew"><a href="#" class="toggle-show-whitespace"><span class="fa fa-plus"></span> {% trans "Show extra whitespace" %}</a></li>
 {%    endif %}
  <li class="ws"><a href="#" class="toggle-whitespace-only-chunks"><span class="fa fa-minus"></span> {% trans "Hide whitespace changes" %}</a></li>
  <li  class="ws" style="display:none;"><a href="#" class="toggle-whitespace-only-chunks"><span class="fa fa-plus"></span> {% trans "Show whitespace changes" %}</a></li>
+{%    if siteconfig_settings.diffviewer_show_comments_inline %}
+ <li class="ic"><a href="#" class="toggle-inline-comments"><span class="fa fa-minus"></span> {% trans "Hide comments" %}</a></li>
+ <li  class="ic" style="display:none;"><a href="#" class="toggle-inline-comments"><span class="fa fa-plus"></span> {% trans "Show comments" %}</a></li>
+{%    endif %}
 </ul>
 
 <div id="diffs"></div>
 <div id="pagination2"></div>
 
 {%  endif %}{# !error #}
 {% endblock content %}