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:
authorDouwe Maan <douwe@selenight.nl>2017-03-31 03:38:21 +0300
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-05 19:44:14 +0300
commit2058e71e63c9ac471137f831b4d04b6626968532 (patch)
tree5c06529ab83a209f8ad7b203d1f131a97041b0bf /app/models/concerns/discussion_on_diff.rb
parent874413cf701870a0fc1051f7c0a5fc4b4f884657 (diff)
Extract commonalities between DiffDiscussion and LegacyDiffDiscussion
Diffstat (limited to 'app/models/concerns/discussion_on_diff.rb')
-rw-r--r--app/models/concerns/discussion_on_diff.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/models/concerns/discussion_on_diff.rb b/app/models/concerns/discussion_on_diff.rb
new file mode 100644
index 00000000000..28abed967f0
--- /dev/null
+++ b/app/models/concerns/discussion_on_diff.rb
@@ -0,0 +1,56 @@
+module DiscussionOnDiff
+ extend ActiveSupport::Concern
+
+ included do
+ NUMBER_OF_TRUNCATED_DIFF_LINES = 16
+
+ memoized_values << :active
+
+ delegate :line_code,
+ :original_line_code,
+ :diff_file,
+ :diff_line,
+ :for_line?,
+ :active?,
+
+ to: :first_note
+
+ delegate :file_path,
+ :blob,
+ :highlighted_diff_lines,
+ :diff_lines,
+
+ to: :diff_file,
+ allow_nil: true
+ end
+
+ def diff_discussion?
+ true
+ end
+
+ def active?
+ return @active if @active.present?
+
+ @active = first_note.active?
+ end
+
+ # Returns an array of at most 16 highlighted lines above a diff note
+ def truncated_diff_lines(highlight: true)
+ lines = highlight ? highlighted_diff_lines : diff_lines
+ prev_lines = []
+
+ lines.each do |line|
+ if line.meta?
+ prev_lines.clear
+ else
+ prev_lines << line
+
+ break if for_line?(line)
+
+ prev_lines.shift if prev_lines.length >= NUMBER_OF_TRUNCATED_DIFF_LINES
+ end
+ end
+
+ prev_lines
+ end
+end