Commit 39b6e678 authored by Paco Guzman's avatar Paco Guzman

Simplify HAML code using unless condition and nesting

Extract diff line data attributes to helper methods
parent fa981c97
...@@ -24,7 +24,6 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -24,7 +24,6 @@ class Projects::CompareController < Projects::ApplicationController
@diff_refs = [@base_commit, @commit] @diff_refs = [@base_commit, @commit]
@diff_notes_disabled = true @diff_notes_disabled = true
@grouped_diff_notes = {} @grouped_diff_notes = {}
@comments_target = {}
end end
end end
......
...@@ -138,7 +138,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -138,7 +138,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@base_commit = @merge_request.diff_base_commit @base_commit = @merge_request.diff_base_commit
@diffs = @merge_request.compare.diffs(diff_options) if @merge_request.compare @diffs = @merge_request.compare.diffs(diff_options) if @merge_request.compare
@diff_notes_disabled = true @diff_notes_disabled = true
@comments_target = {}
@pipeline = @merge_request.pipeline @pipeline = @merge_request.pipeline
@statuses = @pipeline.statuses if @pipeline @statuses = @pipeline.statuses if @pipeline
......
...@@ -24,6 +24,27 @@ module NotesHelper ...@@ -24,6 +24,27 @@ module NotesHelper
}.to_json }.to_json
end end
def note_text_file_data
return {} unless defined?(@comments_target) && @comments_target.any?
@comments_target.slice(:noteable_id, :noteable_type, :commit_id).merge(note_type: LegacyDiffNote.name)
end
def note_line_parallel_data(line_code, line_type)
data = {
line_code: line_code,
line_type: line_type,
}
unless @diff_notes_disabled
data.merge!(
discussion_id: discussion_id(line_code)
)
end
data
end
def discussion_id(line_code) def discussion_id(line_code)
LegacyDiffNote.build_discussion_id( LegacyDiffNote.build_discussion_id(
@comments_target[:noteable_type], @comments_target[:noteable_type],
......
...@@ -30,7 +30,6 @@ module Emails ...@@ -30,7 +30,6 @@ module Emails
@target_url = @message.target_url @target_url = @message.target_url
@project = Project.find(project_id) @project = Project.find(project_id)
@diff_notes_disabled = true @diff_notes_disabled = true
@comments_target = {}
add_project_headers add_project_headers
headers['X-GitLab-Author'] = @message.author_username headers['X-GitLab-Author'] = @message.author_username
......
- type = line.type - type = line.type
- line_data = @comments_target.any? ? { data: { discussion_id: discussion_id(line_code) } } : {} - line_data = @diff_notes_disabled ? {} : { data: { discussion_id: discussion_id(line_code) } }
%tr.line_holder{ line_data, id: line_code, class: type } %tr.line_holder{ line_data, id: line_code, class: type }
- case type - case type
- when 'match' - when 'match'
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
- if defined?(plain) && plain - if defined?(plain) && plain
= link_text = link_text
- else - else
%a{href: "##{line_code}", data: { linenumber: link_text }}= " " %a{href: "##{line_code}", data: { linenumber: link_text }}
%td.new_line.diff-line-num{ class: type, data: { linenumber: line.new_pos } } %td.new_line.diff-line-num{ class: type, data: { linenumber: line.new_pos } }
- link_text = type == "old" ? " " : line.new_pos - link_text = type == "old" ? " " : line.new_pos
- if defined?(plain) && plain - if defined?(plain) && plain
= link_text = link_text
- else - else
%a{href: "##{line_code}", data: { linenumber: link_text }}= "" %a{href: "##{line_code}", data: { linenumber: link_text }}
%td.line_content{ class: ['noteable_line', type], data: { line_code: line_code, line_type: type } }= diff_line_content(line.text, type) %td.line_content{ class: ['noteable_line', type], data: { line_code: line_code, line_type: type } }= diff_line_content(line.text, type)
/ Side-by-side diff view / Side-by-side diff view
- text_file_data = @comments_target.any? ? { data: { noteable_id: @comments_target[:noteable_id], noteable_type: @comments_target[:noteable_type], commit_id: @comments_target[:commit_id], note_type: LegacyDiffNote.name } } : {} %div.text-file.diff-wrap-lines.code.file-content.js-syntax-highlight{ data: note_text_file_data }
%div.text-file.diff-wrap-lines.code.file-content.js-syntax-highlight{ text_file_data }
%table %table
- diff_file.parallel_diff_lines.each do |line| - diff_file.parallel_diff_lines.each do |line|
- left = line[:left] - left = line[:left]
...@@ -14,9 +13,9 @@ ...@@ -14,9 +13,9 @@
%td.new_line.diff-line-num.empty-cell %td.new_line.diff-line-num.empty-cell
%td.line_content.parallel.match= left[:text] %td.line_content.parallel.match= left[:text]
- else - else
%td.old_line.diff-line-num{id: left[:line_code], class: "#{left[:type]} #{'empty-cell' if !left[:number]}", data: { linenumber: left[:number] }} %td.old_line.diff-line-num{id: left[:line_code], class: "#{left[:type]} #{'empty-cell' unless left[:number]}", data: { linenumber: left[:number] }}
%a{href: "##{left[:line_code]}" }= raw(left[:number]) %a{href: "##{left[:line_code]}" }= raw(left[:number])
%td.line_content{class: "parallel noteable_line #{left[:type]} #{'empty-cell' if left[:text].empty?}", data: { discussion_id: discussion_id(left[:line_code]), line_type: left[:type], line_code: left[:line_code] }}= diff_line_content(left[:text]) %td.line_content{class: "parallel noteable_line #{left[:type]} #{'empty-cell' if left[:text].empty?}", data: note_line_parallel_data(left[:line_code], left[:type]) }= diff_line_content(left[:text])
- if right[:type] == 'new' - if right[:type] == 'new'
- new_line_class = 'new' - new_line_class = 'new'
...@@ -25,9 +24,9 @@ ...@@ -25,9 +24,9 @@
- new_line_class = nil - new_line_class = nil
- new_line_code = left[:line_code] - new_line_code = left[:line_code]
%td.new_line.diff-line-num{id: new_line_code, class: "#{new_line_class} #{'empty-cell' if !right[:number]}", data: { linenumber: right[:number] } } %td.new_line.diff-line-num{id: new_line_code, class: "#{new_line_class} #{'empty-cell' unless right[:number]}", data: { linenumber: right[:number] } }
%a{href: "##{new_line_code}" }= raw(right[:number]) %a{href: "##{new_line_code}" }= raw(right[:number])
%td.line_content.parallel{class: "noteable_line #{new_line_class} #{'empty-cell' if right[:text].empty?}", data: { discussion_id: discussion_id(new_line_code), line_type: new_line_class, line_code: new_line_code }}= diff_line_content(right[:text]) %td.line_content.parallel{class: "noteable_line #{new_line_class} #{'empty-cell' if right[:text].empty?}", data: note_line_parallel_data(new_line_code, new_line_class) }= diff_line_content(right[:text])
- unless @diff_notes_disabled - unless @diff_notes_disabled
- notes_left, notes_right = organize_comments(left, right) - notes_left, notes_right = organize_comments(left, right)
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
.suppressed-container .suppressed-container
%a.show-suppressed-diff.js-show-suppressed-diff Changes suppressed. Click to show. %a.show-suppressed-diff.js-show-suppressed-diff Changes suppressed. Click to show.
- text_file_data = @comments_target.any? ? { data: { noteable_id: @comments_target[:noteable_id], noteable_type: @comments_target[:noteable_type], commit_id: @comments_target[:commit_id], note_type: LegacyDiffNote.name } } : {} %table.text-file.code.js-syntax-highlight{ data: note_text_file_data, class: too_big ? 'hide' : '' }
%table.text-file.code.js-syntax-highlight{ text_file_data, class: too_big ? 'hide' : '' }
- last_line = 0 - last_line = 0
- diff_file.highlighted_diff_lines.each_with_index do |line, index| - diff_file.highlighted_diff_lines.each_with_index do |line, index|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment