Highlighting the row, which is in the URL

Review Request #5706 — Created April 12, 2014 and submitted

Information

Review Board
master
843fcf7...

Reviewers

Highlighting the row, which is in the URL. This is the part 2 of my project. The goal is to highlight the row, which is in the URL (example:
localhost:8080/r/1/diff/#file2,1072) based on the file and the line number.

Testing done on my development server locally, works fine there


Description From Last Updated

It would be nice to combine this a bit with the selector passed into diffReviewableView. How about this in the …

daviddavid

This could also be defined in the initial variable definition instead of as a separate statement.

daviddavid

Spacing is a bit weird here. Add a space between if and (, and remove one of the two after …

daviddavid

Please add spaces around the + characters.

daviddavid

Put the })); on the next line.

daviddavid

You should probably merge the code above with this--we don't want to add a second anchor if one already exists, …

daviddavid

You use this hex color in two places--mind defining a variable for it in defs.less? Also, add a space after …

daviddavid

This should use a variable for the color, and include a space after the :

daviddavid

This should use a variable for the color, and include a space after the :

daviddavid

This should use a variable for the color, and include a space after the :

daviddavid

This is closer, but still doesn't do quite the right thing for the case of comment anchors which are added …

daviddavid

There are a ton of typos in this comment.

daviddavid

This change exposed an existing bug in the code. If the URL contains any hash, we want to strip it …

daviddavid

If this._startAtAnchorName is null, this line will fail (and break the diff viewer). Can you change this line to just …

daviddavid
AU
AU
AU
david
  1. 
      
  2. Show all issues

    It would be nice to combine this a bit with the selector passed into diffReviewableView. How about this in the variable definitions:

    var elementName = 'file' + diffReviewable.get('fileDiffID'),
        diffReviewableView = new RB.DiffReviewableView({
            el: $('#' + elementName'),
            model: diffReviewable
        }),
        ...
    
  3. Show all issues

    This could also be defined in the initial variable definition instead of as a separate statement.

  4. Show all issues

    Spacing is a bit weird here. Add a space between if and (, and remove one of the two after &&.

  5. Show all issues

    Please add spaces around the + characters.

  6. Show all issues

    Put the })); on the next line.

  7. reviewboard/static/rb/js/pages/views/diffViewerPageView.js (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
    Show all issues

    You should probably merge the code above with this--we don't want to add a second anchor if one already exists, and it would be nice to keep these things next to each other.

  8. 
      
AU
AU
david
  1. 
      
  2. Show all issues

    You use this hex color in two places--mind defining a variable for it in defs.less?

    Also, add a space after the :

  3. Show all issues

    This should use a variable for the color, and include a space after the :

  4. Show all issues

    This should use a variable for the color, and include a space after the :

  5. Show all issues

    This should use a variable for the color, and include a space after the :

  6. reviewboard/static/rb/js/pages/views/diffViewerPageView.js (Diff revision 3)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    This is closer, but still doesn't do quite the right thing for the case of comment anchors which are added by the template. I think probably what you need is something more like the following. Note that I haven't tested it, it's just a proposal for how to structure this code.

    if (this._startAtAnchorName) {
        $anchor = $('a[name]"' + this._startAtAnchorName + '"]');
    
        /*
         * Some anchors are added by the template (such as those at
         * comment locations), but not all are. If the anchor isn't found,
         * but the URL hash is indicating that we want to start at a
         * location within this file, add the anchor.
         * /
        if ($anchor.length === 0 &&
            urlSplit.length === 2 &&
            elementName === urlSplit[0]) {
            $anchor = $(this.anchorTemplate({
                anchorName: this._startAtAnchorName
            });
    
            diffReviewableView.$el
                .find("tr[line='" + urlSplit[1] + "'])
                    .addClass('highlight-anchor')
                    .append($anchor);
        }
    
        if ($anchor.length !== 0) {
            this.selectAnchor($anchor);
            this._startAtAnchorName = null;
        }
    }
    
    1. I added this as it is and it worked fine on my development environment.

  7. reviewboard/static/rb/js/pages/views/diffViewerPageView.js (Diff revision 3)
     
     
     
     
     
     
     
    Show all issues

    There are a ton of typos in this comment.

    1. Is the commenting you suggested above comprehensive, so I don't need to add anything? Your comment's were way better than mine. :D

  8. 
      
AU
david
  1. Just a couple small changes left!

  2. Show all issues

    This change exposed an existing bug in the code. If the URL contains any hash, we want to strip it out here (otherwise if you copy a URL from a page which was navigated to you might end up with something like "diff/1/file1672,3#file1672,4" which doesn't work. Can you change this to just be if (window.location.hash) ?

  3. Show all issues

    If this._startAtAnchorName is null, this line will fail (and break the diff viewer). Can you change this line to just define the variable, and then assign it within the if (this._startAtAnchorName) block?

  4. 
      
AU
david
  1. Ship It!

  2. 
      
AU
Review request changed
Status:
Completed
Change Summary:
Pushed to master (04fce8b)