1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# frozen_string_literal: true
module Diffs
class OverflowWarningComponent < BaseComponent
def initialize(diffs:, diff_files:, project:, commit: nil, merge_request: nil)
@diffs = diffs
@diff_files = diff_files
@project = project
@commit = commit
@merge_request = merge_request
end
def message
html_escape(message_text) % {
display_size: @diff_files.size,
real_size: @diffs.real_size,
strong_open: '<strong>'.html_safe,
strong_close: '</strong>'.html_safe
}
end
def diff_link
text = _("Plain diff")
if commit?
link_to text, project_commit_path(@project, @commit, format: :diff), class: button_classes
elsif merge_request?
link_to text, merge_request_path(@merge_request, format: :diff), class: button_classes
end
end
def patch_link
text = _("Email patch")
if commit?
link_to text, project_commit_path(@project, @commit, format: :patch), class: button_classes
elsif merge_request?
link_to text, merge_request_path(@merge_request, format: :patch), class: button_classes
end
end
private
def commit?
current_controller?(:commit) &&
@commit.present?
end
def merge_request?
current_controller?("projects/merge_requests/diffs") &&
@merge_request.present? &&
@merge_request.persisted?
end
def message_text
_(
"For a faster browsing experience, only %{strong_open}%{display_size} of %{real_size}%{strong_close} " \
"files are shown. Download one of the files below to see all changes."
)
end
def button_classes
"btn gl-alert-action btn-default gl-button btn-default-secondary"
end
end
end
|