Commit f7e7dc7ebbdac2a45d528d1f9c19055febd0bede
1 parent
73af33e4
Exists in
spb-stable
and in
3 other branches
Make note anchors actually work
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
9 changed files
with
59 additions
and
66 deletions
Show diff stats
app/assets/javascripts/notes.js
@@ -13,9 +13,6 @@ var NoteList = { | @@ -13,9 +13,6 @@ var NoteList = { | ||
13 | 13 | ||
14 | NoteList.setupMainTargetNoteForm(); | 14 | NoteList.setupMainTargetNoteForm(); |
15 | 15 | ||
16 | - // get initial set of notes | ||
17 | - NoteList.getContent(); | ||
18 | - | ||
19 | // Unbind events to prevent firing twice | 16 | // Unbind events to prevent firing twice |
20 | $(document).off("click", ".js-add-diff-note-button"); | 17 | $(document).off("click", ".js-add-diff-note-button"); |
21 | $(document).off("click", ".js-discussion-reply-button"); | 18 | $(document).off("click", ".js-discussion-reply-button"); |
app/controllers/projects/commit_controller.rb
@@ -24,7 +24,8 @@ class Projects::CommitController < Projects::ApplicationController | @@ -24,7 +24,8 @@ class Projects::CommitController < Projects::ApplicationController | ||
24 | @line_notes = result[:line_notes] | 24 | @line_notes = result[:line_notes] |
25 | @branches = result[:branches] | 25 | @branches = result[:branches] |
26 | @notes_count = result[:notes_count] | 26 | @notes_count = result[:notes_count] |
27 | - @target_type = :commit | 27 | + @target_type = "Commit" |
28 | + @notes = project.notes.for_commit_id(@commit.id).not_inline.fresh | ||
28 | @target_id = @commit.id | 29 | @target_id = @commit.id |
29 | 30 | ||
30 | @comments_allowed = @reply_allowed = true | 31 | @comments_allowed = @reply_allowed = true |
app/controllers/projects/issues_controller.rb
@@ -49,7 +49,8 @@ class Projects::IssuesController < Projects::ApplicationController | @@ -49,7 +49,8 @@ class Projects::IssuesController < Projects::ApplicationController | ||
49 | 49 | ||
50 | def show | 50 | def show |
51 | @note = @project.notes.new(noteable: @issue) | 51 | @note = @project.notes.new(noteable: @issue) |
52 | - @target_type = :issue | 52 | + @notes = @issue.notes.inc_author.fresh |
53 | + @target_type = 'Issue' | ||
53 | @target_id = @issue.id | 54 | @target_id = @issue.id |
54 | 55 | ||
55 | respond_with(@issue) | 56 | respond_with(@issue) |
app/controllers/projects/merge_requests_controller.rb
@@ -198,6 +198,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController | @@ -198,6 +198,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController | ||
198 | def define_show_vars | 198 | def define_show_vars |
199 | # Build a note object for comment form | 199 | # Build a note object for comment form |
200 | @note = @project.notes.new(noteable: @merge_request) | 200 | @note = @project.notes.new(noteable: @merge_request) |
201 | + @notes = @merge_request.mr_and_commit_notes.inc_author.fresh | ||
202 | + @discussions = Note.discussions_from_notes(@notes) | ||
203 | + @target_type = 'MergeRequest' | ||
204 | + @target_id = @merge_request.id | ||
201 | 205 | ||
202 | # Get commits from repository | 206 | # Get commits from repository |
203 | # or from cache if already merged | 207 | # or from cache if already merged |
@@ -205,9 +209,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController | @@ -205,9 +209,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController | ||
205 | 209 | ||
206 | @allowed_to_merge = allowed_to_merge? | 210 | @allowed_to_merge = allowed_to_merge? |
207 | @show_merge_controls = @merge_request.opened? && @commits.any? && @allowed_to_merge | 211 | @show_merge_controls = @merge_request.opened? && @commits.any? && @allowed_to_merge |
208 | - | ||
209 | - @target_type = :merge_request | ||
210 | - @target_id = @merge_request.id | ||
211 | end | 212 | end |
212 | 213 | ||
213 | def allowed_to_merge? | 214 | def allowed_to_merge? |
app/controllers/projects/notes_controller.rb
@@ -11,7 +11,7 @@ class Projects::NotesController < Projects::ApplicationController | @@ -11,7 +11,7 @@ class Projects::NotesController < Projects::ApplicationController | ||
11 | @target_id = params[:target_id] | 11 | @target_id = params[:target_id] |
12 | 12 | ||
13 | if params[:target_type] == "merge_request" | 13 | if params[:target_type] == "merge_request" |
14 | - @discussions = discussions_from_notes | 14 | + @discussions = Note.discussions_from_notes(@notes) |
15 | end | 15 | end |
16 | 16 | ||
17 | respond_to do |format| | 17 | respond_to do |format| |
@@ -76,36 +76,4 @@ class Projects::NotesController < Projects::ApplicationController | @@ -76,36 +76,4 @@ class Projects::NotesController < Projects::ApplicationController | ||
76 | def preview | 76 | def preview |
77 | render text: view_context.markdown(params[:note]) | 77 | render text: view_context.markdown(params[:note]) |
78 | end | 78 | end |
79 | - | ||
80 | - protected | ||
81 | - | ||
82 | - def discussion_notes_for(note) | ||
83 | - @notes.select do |other_note| | ||
84 | - note.discussion_id == other_note.discussion_id | ||
85 | - end | ||
86 | - end | ||
87 | - | ||
88 | - def discussions_from_notes | ||
89 | - discussion_ids = [] | ||
90 | - discussions = [] | ||
91 | - | ||
92 | - @notes.each do |note| | ||
93 | - next if discussion_ids.include?(note.discussion_id) | ||
94 | - | ||
95 | - # don't group notes for the main target | ||
96 | - if note_for_main_target?(note) | ||
97 | - discussions << [note] | ||
98 | - else | ||
99 | - discussions << discussion_notes_for(note) | ||
100 | - discussion_ids << note.discussion_id | ||
101 | - end | ||
102 | - end | ||
103 | - | ||
104 | - discussions | ||
105 | - end | ||
106 | - | ||
107 | - # Helps to distinguish e.g. commit notes in mr notes list | ||
108 | - def note_for_main_target?(note) | ||
109 | - (@target_type.camelize == note.noteable_type && !note.for_diff_line?) | ||
110 | - end | ||
111 | end | 79 | end |
app/controllers/projects/snippets_controller.rb
@@ -48,7 +48,8 @@ class Projects::SnippetsController < Projects::ApplicationController | @@ -48,7 +48,8 @@ class Projects::SnippetsController < Projects::ApplicationController | ||
48 | 48 | ||
49 | def show | 49 | def show |
50 | @note = @project.notes.new(noteable: @snippet) | 50 | @note = @project.notes.new(noteable: @snippet) |
51 | - @target_type = :snippet | 51 | + @notes = @snippet.notes.fresh |
52 | + @target_type = 'Snippet' | ||
52 | @target_id = @snippet.id | 53 | @target_id = @snippet.id |
53 | end | 54 | end |
54 | 55 |
app/models/note.rb
@@ -56,29 +56,52 @@ class Note < ActiveRecord::Base | @@ -56,29 +56,52 @@ class Note < ActiveRecord::Base | ||
56 | serialize :st_diff | 56 | serialize :st_diff |
57 | before_create :set_diff, if: ->(n) { n.line_code.present? } | 57 | before_create :set_diff, if: ->(n) { n.line_code.present? } |
58 | 58 | ||
59 | - def self.create_status_change_note(noteable, project, author, status, source) | ||
60 | - body = "_Status changed to #{status}#{' by ' + source.gfm_reference if source}_" | ||
61 | - | ||
62 | - create({ | ||
63 | - noteable: noteable, | ||
64 | - project: project, | ||
65 | - author: author, | ||
66 | - note: body, | ||
67 | - system: true | ||
68 | - }, without_protection: true) | ||
69 | - end | 59 | + class << self |
60 | + def create_status_change_note(noteable, project, author, status, source) | ||
61 | + body = "_Status changed to #{status}#{' by ' + source.gfm_reference if source}_" | ||
62 | + | ||
63 | + create({ | ||
64 | + noteable: noteable, | ||
65 | + project: project, | ||
66 | + author: author, | ||
67 | + note: body, | ||
68 | + system: true | ||
69 | + }, without_protection: true) | ||
70 | + end | ||
71 | + | ||
72 | + # +noteable+ was referenced from +mentioner+, by including GFM in either +mentioner+'s description or an associated Note. | ||
73 | + # Create a system Note associated with +noteable+ with a GFM back-reference to +mentioner+. | ||
74 | + def create_cross_reference_note(noteable, mentioner, author, project) | ||
75 | + create({ | ||
76 | + noteable: noteable, | ||
77 | + commit_id: (noteable.sha if noteable.respond_to? :sha), | ||
78 | + project: project, | ||
79 | + author: author, | ||
80 | + note: "_mentioned in #{mentioner.gfm_reference}_", | ||
81 | + system: true | ||
82 | + }, without_protection: true) | ||
83 | + end | ||
70 | 84 | ||
71 | - # +noteable+ was referenced from +mentioner+, by including GFM in either +mentioner+'s description or an associated Note. | ||
72 | - # Create a system Note associated with +noteable+ with a GFM back-reference to +mentioner+. | ||
73 | - def self.create_cross_reference_note(noteable, mentioner, author, project) | ||
74 | - create({ | ||
75 | - noteable: noteable, | ||
76 | - commit_id: (noteable.sha if noteable.respond_to? :sha), | ||
77 | - project: project, | ||
78 | - author: author, | ||
79 | - note: "_mentioned in #{mentioner.gfm_reference}_", | ||
80 | - system: true | ||
81 | - }, without_protection: true) | 85 | + def discussions_from_notes(notes) |
86 | + discussion_ids = [] | ||
87 | + discussions = [] | ||
88 | + | ||
89 | + notes.each do |note| | ||
90 | + next if discussion_ids.include?(note.discussion_id) | ||
91 | + | ||
92 | + # don't group notes for the main target | ||
93 | + if !note.for_diff_line? && note.noteable_type == "MergeRequest" | ||
94 | + discussions << [note] | ||
95 | + else | ||
96 | + discussions << notes.select do |other_note| | ||
97 | + note.discussion_id == other_note.discussion_id | ||
98 | + end | ||
99 | + discussion_ids << note.discussion_id | ||
100 | + end | ||
101 | + end | ||
102 | + | ||
103 | + discussions | ||
104 | + end | ||
82 | end | 105 | end |
83 | 106 | ||
84 | # Determine whether or not a cross-reference note already exists. | 107 | # Determine whether or not a cross-reference note already exists. |
@@ -89,7 +112,7 @@ class Note < ActiveRecord::Base | @@ -89,7 +112,7 @@ class Note < ActiveRecord::Base | ||
89 | def commit_author | 112 | def commit_author |
90 | @commit_author ||= | 113 | @commit_author ||= |
91 | project.users.find_by_email(noteable.author_email) || | 114 | project.users.find_by_email(noteable.author_email) || |
92 | - project.users.find_by_name(noteable.author_name) | 115 | + project.users.find_by_name(noteable.author_name) |
93 | rescue | 116 | rescue |
94 | nil | 117 | nil |
95 | end | 118 | end |
app/views/projects/notes/_notes.html.haml
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | - if note_for_main_target?(note) | 4 | - if note_for_main_target?(note) |
5 | = render discussion_notes | 5 | = render discussion_notes |
6 | - else | 6 | - else |
7 | - = render 'discussion', discussion_notes: discussion_notes | 7 | + = render 'projects/notes/discussion', discussion_notes: discussion_notes |
8 | - else | 8 | - else |
9 | - @notes.each do |note| | 9 | - @notes.each do |note| |
10 | - next unless note.author | 10 | - next unless note.author |