diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-15 07:19:50 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-15 07:19:50 +0000 |
commit | 79190fe06be1671eed82c0b463c27c35224fa0d3 (patch) | |
tree | ce32cfd7a37fe08bcaa3bbde64e5858b7a2e8fbc /app | |
parent | e19c1f71d3a6d6b5be638c4f1fb5c9d2401e04be (diff) | |
parent | 9b59570c8ee9bfa39c64531ea4cc12b46ff99f9e (diff) | |
download | gitlab-ce-79190fe06be1671eed82c0b463c27c35224fa0d3.tar.gz |
Merge branch 'implement_comments_on_parallel_diff' into 'master'
Implement comments on parallel diff
Fixes #1565
See merge request !1090
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/stylesheets/sections/notes.scss | 3 | ||||
-rw-r--r-- | app/helpers/diff_helper.rb | 36 | ||||
-rw-r--r-- | app/views/projects/diffs/_parallel_view.html.haml | 30 | ||||
-rw-r--r-- | app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml | 11 |
4 files changed, 58 insertions, 22 deletions
diff --git a/app/assets/stylesheets/sections/notes.scss b/app/assets/stylesheets/sections/notes.scss index 4e13e30bac8..8df25f53762 100644 --- a/app/assets/stylesheets/sections/notes.scss +++ b/app/assets/stylesheets/sections/notes.scss @@ -90,6 +90,9 @@ ul.notes { border-width: 1px 0; padding-top: 0; vertical-align: top; + &.parallel{ + border-width: 1px; + } } } } diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index afe7447d4e2..cb50d89cba8 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -36,7 +36,10 @@ module DiffHelper # Building array of lines # - # [left_type, left_line_number, left_line_content, line_code, right_line_type, right_line_number, right_line_content] + # [ + # left_type, left_line_number, left_line_content, left_line_code, + # right_line_type, right_line_number, right_line_content, right_line_code + # ] # diff_file.diff_lines.each do |line| @@ -49,26 +52,25 @@ module DiffHelper next_line = diff_file.next_line(line.index) if next_line + next_line_code = generate_line_code(diff_file.file_path, next_line) next_type = next_line.type next_line = next_line.text end - line = [type, line_old, full_line, line_code, next_type, line_new] if type == 'match' || type.nil? # line in the right panel is the same as in the left one - line = [type, line_old, full_line, line_code, type, line_new, full_line] + line = [type, line_old, full_line, line_code, type, line_new, full_line, line_code] lines.push(line) elsif type == 'old' if next_type == 'new' # Left side has text removed, right side has text added - line.push(next_line) + line = [type, line_old, full_line, line_code, next_type, line_new, next_line, next_line_code] lines.push(line) skip_next = true elsif next_type == 'old' || next_type.nil? # Left side has text removed, right side doesn't have any change - line.pop # remove the newline - line.push(nil) # no line number on the right panel - line.push(" ") # empty line on the right panel + # No next line code, no new line number, no new line text + line = [type, line_old, full_line, line_code, next_type, nil, " ", nil] lines.push(line) end elsif type == 'new' @@ -78,7 +80,7 @@ module DiffHelper next else # Change is only on the right side, left side has no change - line = [nil, nil, " ", line_code, type, line_new, full_line] + line = [nil, nil, " ", line_code, type, line_new, full_line, line_code] lines.push(line) end end @@ -97,4 +99,22 @@ module DiffHelper line end end + + def line_comments + @line_comments ||= @line_notes.group_by(&:line_code) + end + + def organize_comments(type_left, type_right, line_code_left, line_code_right) + comments_left = comments_right = nil + + unless type_left.nil? && type_right == 'new' + comments_left = line_comments[line_code_left] + end + + unless type_left.nil? && type_right.nil? + comments_right = line_comments[line_code_right] + end + + [comments_left, comments_right] + end end diff --git a/app/views/projects/diffs/_parallel_view.html.haml b/app/views/projects/diffs/_parallel_view.html.haml index 3ec769e0b83..75f3a80f0d7 100644 --- a/app/views/projects/diffs/_parallel_view.html.haml +++ b/app/views/projects/diffs/_parallel_view.html.haml @@ -5,22 +5,36 @@ - type_left = line[0] - line_number_left = line[1] - line_content_left = line[2] - - line_code = line[3] + - line_code_left = line[3] - type_right = line[4] - line_number_right = line[5] - line_content_right = line[6] + - line_code_right = line[7] - %tr.line_holder.parallel{id: line_code} + %tr.line_holder.parallel - if type_left == 'match' = render "projects/diffs/match_line_parallel", { line: line_content_left, line_old: line_number_left, line_new: line_number_right } - elsif type_left == 'old' || type_left.nil? - %td.old_line{class: "#{type_left}"} - = link_to raw(line_number_left), "##{line_code}", id: line_code - %td.line_content{class: "parallel noteable_line #{type_left} #{line_code}", "line_code" => line_code }= raw line_content_left - %td.new_line{ class: "#{type_right == 'new' ? 'new' : nil}", data: { linenumber: line_number_right }} - = link_to raw(line_number_right), "##{line_code}", id: line_code - %td.line_content.parallel{class: "noteable_line #{type_right == 'new' ? 'new' : nil} #{line_code}", "line_code" => line_code}= raw line_content_right + %td.old_line{id: line_code_left, class: "#{type_left}"} + = link_to raw(line_number_left), "##{line_code_left}", id: line_code_left + %td.line_content{class: "parallel noteable_line #{type_left} #{line_code_left}", "line_code" => line_code_left }= raw line_content_left + + - if type_right == 'new' + - new_line_class = 'new' + - new_line_code = line_code_right + - else + - new_line_class = nil + - new_line_code = line_code_left + + %td.new_line{id: new_line_code, class: "#{new_line_class}", data: { linenumber: line_number_right }} + = link_to raw(line_number_right), "##{new_line_code}", id: new_line_code + %td.line_content.parallel{class: "noteable_line #{new_line_class} #{new_line_code}", "line_code" => new_line_code}= raw line_content_right + + - if @reply_allowed + - comments_left, comments_right = organize_comments(type_left, type_right, line_code_left, line_code_right) + - if comments_left.present? || comments_right.present? + = render "projects/notes/diff_notes_with_reply_parallel", notes1: comments_left, notes2: comments_right - if diff_file.diff.diff.blank? && diff_file.mode_changed? .file-mode-changed diff --git a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml index 8adf903a9a1..506d1fff008 100644 --- a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml +++ b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml @@ -1,14 +1,13 @@ -- note1 = notes1.first # example note -- note2 = notes2.first # example note --# Check if line want not changed since comment was left -/- if !defined?(line) || line == note.diff_line +- note1 = notes1.present? ? notes1.first : nil +- note2 = notes2.present? ? notes2.first : nil + %tr.notes_holder - if note1 %td.notes_line %span.btn.disabled %i.icon-comment = notes1.count - %td.notes_content + %td.notes_content.parallel %ul.notes{ rel: note1.discussion_id } = render notes1 @@ -23,7 +22,7 @@ %span.btn.disabled %i.icon-comment = notes2.count - %td.notes_content + %td.notes_content.parallel %ul.notes{ rel: note2.discussion_id } = render notes2 |