Commit 2aef3b00cf2ee06dc4128a1a54483cccc1fd48f9
1 parent
bc6a17a6
Exists in
spb-stable
and in
2 other branches
Refactor link to new diff note rendering
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
3 changed files
with
29 additions
and
6 deletions
Show diff stats
app/helpers/notes_helper.rb
| ... | ... | @@ -42,4 +42,23 @@ module NotesHelper |
| 42 | 42 | project_id: noteable.project.id, |
| 43 | 43 | }.to_json |
| 44 | 44 | end |
| 45 | + | |
| 46 | + def link_to_new_diff_note(line_code) | |
| 47 | + discussion_id = Note.build_discussion_id( | |
| 48 | + @comments_target[:noteable_type], | |
| 49 | + @comments_target[:noteable_id] || @comments_target[:commit_id], | |
| 50 | + line_code | |
| 51 | + ) | |
| 52 | + | |
| 53 | + data = { | |
| 54 | + noteable_type: @comments_target[:noteable_type], | |
| 55 | + noteable_id: @comments_target[:noteable_id], | |
| 56 | + commit_id: @comments_target[:commit_id], | |
| 57 | + line_code: line_code, | |
| 58 | + discussion_id: discussion_id | |
| 59 | + } | |
| 60 | + | |
| 61 | + link_to "", "javascript:;", class: "add-diff-note js-add-diff-note-button", | |
| 62 | + data: data, title: "Add a comment to this line" | |
| 63 | + end | |
| 45 | 64 | end | ... | ... |
app/models/note.rb
| ... | ... | @@ -122,11 +122,15 @@ class Note < ActiveRecord::Base |
| 122 | 122 | |
| 123 | 123 | discussions |
| 124 | 124 | end |
| 125 | - end | |
| 126 | 125 | |
| 127 | - # Determine whether or not a cross-reference note already exists. | |
| 128 | - def self.cross_reference_exists?(noteable, mentioner) | |
| 129 | - where(noteable_id: noteable.id, system: true, note: "_mentioned in #{mentioner.gfm_reference}_").any? | |
| 126 | + def build_discussion_id(type, id, line_code) | |
| 127 | + [:discussion, type.try(:underscore), id, line_code].join("-").to_sym | |
| 128 | + end | |
| 129 | + | |
| 130 | + # Determine whether or not a cross-reference note already exists. | |
| 131 | + def cross_reference_exists?(noteable, mentioner) | |
| 132 | + where(noteable_id: noteable.id, system: true, note: "_mentioned in #{mentioner.gfm_reference}_").any? | |
| 133 | + end | |
| 130 | 134 | end |
| 131 | 135 | |
| 132 | 136 | def commit_author |
| ... | ... | @@ -194,7 +198,7 @@ class Note < ActiveRecord::Base |
| 194 | 198 | end |
| 195 | 199 | |
| 196 | 200 | def discussion_id |
| 197 | - @discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id || commit_id, line_code].join("-").to_sym | |
| 201 | + @discussion_id ||= Note.build_discussion_id(noteable_type, noteable_id || commit_id, line_code) | |
| 198 | 202 | end |
| 199 | 203 | |
| 200 | 204 | # Returns true if this is a downvote note, | ... | ... |
app/views/projects/commits/_text_file.html.haml
| ... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 | %td.old_line |
| 14 | 14 | = link_to raw(type == "new" ? " " : line_old), "##{line_code}", id: line_code |
| 15 | 15 | - if @comments_allowed |
| 16 | - = render "projects/notes/diff_note_link", line_code: line_code | |
| 16 | + = link_to_new_diff_note(line_code) | |
| 17 | 17 | %td.new_line= link_to raw(type == "old" ? " " : line_new) , "##{line_code}", id: line_code |
| 18 | 18 | %td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line) |
| 19 | 19 | ... | ... |