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:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-07 00:15:54 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-06-07 00:15:54 +0400
commit2aef3b00cf2ee06dc4128a1a54483cccc1fd48f9 (patch)
treed29ced54655bab917d504396e2c68d52710efd29 /app
parentbc6a17a6828f2695a7ad0f64671ac1b6845c111d (diff)
Refactor link to new diff note rendering
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r--app/helpers/notes_helper.rb19
-rw-r--r--app/models/note.rb14
-rw-r--r--app/views/projects/commits/_text_file.html.haml2
3 files changed, 29 insertions, 6 deletions
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb
index 7ae104b8fd1..9ed38ba84b2 100644
--- a/app/helpers/notes_helper.rb
+++ b/app/helpers/notes_helper.rb
@@ -42,4 +42,23 @@ module NotesHelper
project_id: noteable.project.id,
}.to_json
end
+
+ def link_to_new_diff_note(line_code)
+ discussion_id = Note.build_discussion_id(
+ @comments_target[:noteable_type],
+ @comments_target[:noteable_id] || @comments_target[:commit_id],
+ line_code
+ )
+
+ data = {
+ noteable_type: @comments_target[:noteable_type],
+ noteable_id: @comments_target[:noteable_id],
+ commit_id: @comments_target[:commit_id],
+ line_code: line_code,
+ discussion_id: discussion_id
+ }
+
+ link_to "", "javascript:;", class: "add-diff-note js-add-diff-note-button",
+ data: data, title: "Add a comment to this line"
+ end
end
diff --git a/app/models/note.rb b/app/models/note.rb
index cee10ec90d2..278c957af0e 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -122,11 +122,15 @@ class Note < ActiveRecord::Base
discussions
end
- end
- # Determine whether or not a cross-reference note already exists.
- def self.cross_reference_exists?(noteable, mentioner)
- where(noteable_id: noteable.id, system: true, note: "_mentioned in #{mentioner.gfm_reference}_").any?
+ def build_discussion_id(type, id, line_code)
+ [:discussion, type.try(:underscore), id, line_code].join("-").to_sym
+ end
+
+ # Determine whether or not a cross-reference note already exists.
+ def cross_reference_exists?(noteable, mentioner)
+ where(noteable_id: noteable.id, system: true, note: "_mentioned in #{mentioner.gfm_reference}_").any?
+ end
end
def commit_author
@@ -194,7 +198,7 @@ class Note < ActiveRecord::Base
end
def discussion_id
- @discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id || commit_id, line_code].join("-").to_sym
+ @discussion_id ||= Note.build_discussion_id(noteable_type, noteable_id || commit_id, line_code)
end
# Returns true if this is a downvote note,
diff --git a/app/views/projects/commits/_text_file.html.haml b/app/views/projects/commits/_text_file.html.haml
index ba83d2e5a0f..74a68b1bf82 100644
--- a/app/views/projects/commits/_text_file.html.haml
+++ b/app/views/projects/commits/_text_file.html.haml
@@ -13,7 +13,7 @@
%td.old_line
= link_to raw(type == "new" ? "&nbsp;" : line_old), "##{line_code}", id: line_code
- if @comments_allowed
- = render "projects/notes/diff_note_link", line_code: line_code
+ = link_to_new_diff_note(line_code)
%td.new_line= link_to raw(type == "old" ? "&nbsp;" : line_new) , "##{line_code}", id: line_code
%td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line)