Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-07-06 07:59:18 +0300
committerPaco Guzman <pacoguzmanp@gmail.com>2016-07-06 10:02:53 +0300
commit39b6e678da8c431020370dfc26c761255bc3ddf8 (patch)
tree3d5034b2fdba1cb41576b213d3832cadf77a3d19 /app
parentfa981c9794de7a76bf225dc243e20d2799b55e53 (diff)
Simplify HAML code using unless condition and nesting
Extract diff line data attributes to helper methods
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/compare_controller.rb1
-rw-r--r--app/controllers/projects/merge_requests_controller.rb1
-rw-r--r--app/helpers/notes_helper.rb21
-rw-r--r--app/mailers/emails/projects.rb1
-rw-r--r--app/views/projects/diffs/_line.html.haml6
-rw-r--r--app/views/projects/diffs/_parallel_view.html.haml11
-rw-r--r--app/views/projects/diffs/_text_file.html.haml3
7 files changed, 30 insertions, 14 deletions
diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb
index 57725944d68..af0b69a2442 100644
--- a/app/controllers/projects/compare_controller.rb
+++ b/app/controllers/projects/compare_controller.rb
@@ -24,7 +24,6 @@ class Projects::CompareController < Projects::ApplicationController
@diff_refs = [@base_commit, @commit]
@diff_notes_disabled = true
@grouped_diff_notes = {}
- @comments_target = {}
end
end
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 99630bc1099..dd86b940a08 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -138,7 +138,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@base_commit = @merge_request.diff_base_commit
@diffs = @merge_request.compare.diffs(diff_options) if @merge_request.compare
@diff_notes_disabled = true
- @comments_target = {}
@pipeline = @merge_request.pipeline
@statuses = @pipeline.statuses if @pipeline
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb
index 42419aa908e..e1c8152885a 100644
--- a/app/helpers/notes_helper.rb
+++ b/app/helpers/notes_helper.rb
@@ -24,6 +24,27 @@ module NotesHelper
}.to_json
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)
LegacyDiffNote.build_discussion_id(
@comments_target[:noteable_type],
diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb
index 1a6900b3293..e0af7081411 100644
--- a/app/mailers/emails/projects.rb
+++ b/app/mailers/emails/projects.rb
@@ -30,7 +30,6 @@ module Emails
@target_url = @message.target_url
@project = Project.find(project_id)
@diff_notes_disabled = true
- @comments_target = {}
add_project_headers
headers['X-GitLab-Author'] = @message.author_username
diff --git a/app/views/projects/diffs/_line.html.haml b/app/views/projects/diffs/_line.html.haml
index da1c81bfc15..1953720b79e 100644
--- a/app/views/projects/diffs/_line.html.haml
+++ b/app/views/projects/diffs/_line.html.haml
@@ -1,5 +1,5 @@
- 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 }
- case type
- when 'match'
@@ -15,11 +15,11 @@
- if defined?(plain) && plain
= link_text
- 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 } }
- link_text = type == "old" ? " " : line.new_pos
- if defined?(plain) && plain
= link_text
- 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)
diff --git a/app/views/projects/diffs/_parallel_view.html.haml b/app/views/projects/diffs/_parallel_view.html.haml
index e205686ceea..a234f778190 100644
--- a/app/views/projects/diffs/_parallel_view.html.haml
+++ b/app/views/projects/diffs/_parallel_view.html.haml
@@ -1,6 +1,5 @@
/ 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{ text_file_data }
+%div.text-file.diff-wrap-lines.code.file-content.js-syntax-highlight{ data: note_text_file_data }
%table
- diff_file.parallel_diff_lines.each do |line|
- left = line[:left]
@@ -14,9 +13,9 @@
%td.new_line.diff-line-num.empty-cell
%td.line_content.parallel.match= left[:text]
- 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])
- %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'
- new_line_class = 'new'
@@ -25,9 +24,9 @@
- new_line_class = nil
- 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])
- %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
- notes_left, notes_right = organize_comments(left, right)
diff --git a/app/views/projects/diffs/_text_file.html.haml b/app/views/projects/diffs/_text_file.html.haml
index a1c3bf74b0a..3a3aff4d054 100644
--- a/app/views/projects/diffs/_text_file.html.haml
+++ b/app/views/projects/diffs/_text_file.html.haml
@@ -3,8 +3,7 @@
.suppressed-container
%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{ text_file_data, class: too_big ? 'hide' : '' }
+%table.text-file.code.js-syntax-highlight{ data: note_text_file_data, class: too_big ? 'hide' : '' }
- last_line = 0
- diff_file.highlighted_diff_lines.each_with_index do |line, index|