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
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/projects/commit_controller.rb4
-rw-r--r--app/controllers/projects/compare_controller.rb2
-rw-r--r--app/controllers/projects/merge_requests_controller.rb8
-rw-r--r--app/controllers/projects/notes_controller.rb65
4 files changed, 43 insertions, 36 deletions
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index 727e84b40a1..7ae034f9398 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -115,11 +115,11 @@ class Projects::CommitController < Projects::ApplicationController
end
def define_note_vars
- @grouped_diff_notes = commit.notes.grouped_diff_notes
+ @grouped_diff_discussions = commit.notes.grouped_diff_discussions
@notes = commit.notes.non_diff_notes.fresh
Banzai::NoteRenderer.render(
- @grouped_diff_notes.values.flatten + @notes,
+ @grouped_diff_discussions.values.flat_map(&:notes) + @notes,
@project,
current_user,
)
diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb
index 10749d0fef8..8c004724f02 100644
--- a/app/controllers/projects/compare_controller.rb
+++ b/app/controllers/projects/compare_controller.rb
@@ -54,7 +54,7 @@ class Projects::CompareController < Projects::ApplicationController
)
@diff_notes_disabled = true
- @grouped_diff_notes = {}
+ @grouped_diff_discussions = {}
end
end
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 7beeb7d97d0..594a61464b9 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -97,7 +97,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
else
build_merge_request
@diff_notes_disabled = true
- @grouped_diff_notes = {}
+ @grouped_diff_discussions = {}
end
define_commit_vars
@@ -378,7 +378,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
# This is not executed lazily
@notes = Banzai::NoteRenderer.render(
- @discussions.flatten,
+ @discussions.flat_map(&:notes),
@project,
current_user,
@path,
@@ -404,10 +404,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
}
@use_legacy_diff_notes = !@merge_request.support_new_diff_notes?
- @grouped_diff_notes = @merge_request.notes.grouped_diff_notes
+ @grouped_diff_discussions = @merge_request.notes.grouped_diff_discussions
Banzai::NoteRenderer.render(
- @grouped_diff_notes.values.flatten,
+ @grouped_diff_discussions.values.flat_map(&:notes),
@project,
current_user,
@path,
diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb
index 3eacdbbd067..766b7e9cf22 100644
--- a/app/controllers/projects/notes_controller.rb
+++ b/app/controllers/projects/notes_controller.rb
@@ -73,7 +73,7 @@ class Projects::NotesController < Projects::ApplicationController
end
alias_method :awardable, :note
- def note_to_html(note)
+ def note_html(note)
render_to_string(
"projects/notes/_note",
layout: false,
@@ -82,20 +82,20 @@ class Projects::NotesController < Projects::ApplicationController
)
end
- def note_to_discussion_html(note)
- return unless note.diff_note?
+ def diff_discussion_html(discussion)
+ return unless discussion.diff_discussion?
if params[:view] == 'parallel'
- template = "projects/notes/_diff_notes_with_reply_parallel"
+ template = "discussions/_parallel_diff_discussion"
locals =
if params[:line_type] == 'old'
- { notes_left: [note], notes_right: [] }
+ { discussion_left: discussion, discussion_right: nil }
else
- { notes_left: [], notes_right: [note] }
+ { discussion_left: nil, discussion_right: discussion }
end
else
- template = "projects/notes/_diff_notes_with_reply"
- locals = { notes: [note] }
+ template = "discussions/_diff_discussion"
+ locals = { discussion: discussion }
end
render_to_string(
@@ -106,14 +106,14 @@ class Projects::NotesController < Projects::ApplicationController
)
end
- def note_to_discussion_with_diff_html(note)
- return unless note.diff_note?
+ def discussion_html(discussion)
+ return unless discussion.diff_discussion?
render_to_string(
- "projects/notes/_discussion",
+ "discussions/_discussion",
layout: false,
formats: [:html],
- locals: { discussion_notes: [note] }
+ locals: { discussion: discussion }
)
end
@@ -132,26 +132,33 @@ class Projects::NotesController < Projects::ApplicationController
valid: true,
id: note.id,
discussion_id: note.discussion_id,
- html: note_to_html(note),
+ html: note_html(note),
award: false,
- note: note.note,
- discussion_html: note_to_discussion_html(note),
- discussion_with_diff_html: note_to_discussion_with_diff_html(note)
+ note: note.note
}
- # The discussion_id is used to add the comment to the correct discussion
- # element on the merge request page. Among other things, the discussion_id
- # contains the sha of head commit of the merge request.
- # When new commits are pushed into the merge request after the initial
- # load of the merge request page, the discussion elements will still have
- # the old discussion_ids, with the old head commit sha. The new comment,
- # however, will have the new discussion_id with the new commit sha.
- # To ensure that these new comments will still end up in the correct
- # discussion element, we also send the original discussion_id, with the
- # old commit sha, along, and fall back on this value when no discussion
- # element with the new discussion_id could be found.
- if note.new_diff_note? && note.position != note.original_position
- attrs[:original_discussion_id] = note.original_discussion_id
+ if note.diff_note?
+ discussion = Discussion.new([note])
+
+ attrs.merge!(
+ diff_discussion_html: diff_discussion_html(discussion),
+ discussion_html: discussion_html(discussion)
+ )
+
+ # The discussion_id is used to add the comment to the correct discussion
+ # element on the merge request page. Among other things, the discussion_id
+ # contains the sha of head commit of the merge request.
+ # When new commits are pushed into the merge request after the initial
+ # load of the merge request page, the discussion elements will still have
+ # the old discussion_ids, with the old head commit sha. The new comment,
+ # however, will have the new discussion_id with the new commit sha.
+ # To ensure that these new comments will still end up in the correct
+ # discussion element, we also send the original discussion_id, with the
+ # old commit sha, along, and fall back on this value when no discussion
+ # element with the new discussion_id could be found.
+ if note.new_diff_note? && note.position != note.original_position
+ attrs[:original_discussion_id] = note.original_discussion_id
+ end
end
attrs