BigW Consortium Gitlab

_parallel_view.html.haml 1.88 KB
Newer Older
1
/ Side-by-side diff view
2 3
- old_lines, new_lines = parallel_diff_lines(project, @commit, diff, file)
- num_lines = old_lines.length
4 5

%div.text-file-parallel
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  %div.diff-side.diff-side-left
    %table
      - old_lines.each do |line|

        %tr.line_holder.parallel
          - if line.type == :file_created
            %td.line_content.parallel= "File was created"
          - elsif line.type == :deleted
            %td.line_content{class: "parallel noteable_line old #{line.code}", "line_code" => line.code }= line.content
          - else line.type == :no_change
            %td.line_content.parallel= line.content

  %div.diff-middle
    %table
      - num_lines.times do |index|
        %tr
          - if old_lines[index].type == :deleted
            %td.old_line.old= old_lines[index].num
          - else
            %td.old_line= old_lines[index].num

          %td.diff_line=""
28

29 30 31 32
          - if new_lines[index].type == :added
            %td.new_line.new= new_lines[index].num
          - else
            %td.new_line= new_lines[index].num
33

34 35 36
  %div.diff-side.diff-side-right
    %table
      - new_lines.each do |line|
37

38 39 40 41 42 43 44
        %tr.line_holder.parallel
          - if line.type == :file_deleted
            %td.line_content.parallel= "File was deleted"
          - elsif line.type == :added
            %td.line_content{class: "parallel noteable_line new #{line.code}", "line_code" => line.code }= line.content
          - else line.type == :no_change
            %td.line_content.parallel= line.content
45

46 47 48 49 50
:javascript
  $('.diff-side-right').on('scroll', function(){
    $('.diff-side-left, .diff-middle').scrollTop($(this).scrollTop());
    $('.diff-side-left').scrollLeft($(this).scrollLeft());
  });
51

52 53 54 55
  $('.diff-side-left').on('scroll', function(){
    $('.diff-side-right, .diff-middle').scrollTop($(this).scrollTop()); // might never be relevant
    $('.diff-side-right').scrollLeft($(this).scrollLeft());
  });