-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathrevision_component.rb
127 lines (109 loc) · 3.75 KB
/
revision_component.rb
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# frozen_string_literal: true
# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2023 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++
require "sanitize"
module WorkPackages
module ActivitiesTab
module Journals
class RevisionComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
def initialize(changeset:, filter:)
super
@changeset = changeset
@filter = filter
end
def render_committer_name(committer)
render(Primer::Beta::Text.new(font_weight: :bold, mr: 1)) do
remove_email_addresses(committer)
end
end
def remove_email_addresses(committer)
return "" if committer.blank?
ERB::Util.html_escape(
Sanitize.fragment(
committer.gsub(%r{<[^>]+@[^>]+>}, ""),
Sanitize::Config::RESTRICTED
).strip
)
end
private
attr_reader :changeset, :filter
def render?
filter != :only_comments
end
def user_name
if changeset.user
changeset.user.name
else
# Extract name from committer string (format: "name <email>")
changeset.committer.split("<").first.strip
end
end
def revision_url
repository = changeset.repository
project = repository.project
show_revision_project_repository_path(project_id: project.id, rev: changeset.revision)
end
def short_revision
changeset.revision[0..7]
end
def copy_url_action_item(menu)
menu.with_item(label: t("button_copy_link_to_clipboard"),
tag: :button,
content_arguments: {
data: {
action: "click->work-packages--activities-tab--item#copyActivityUrlToClipboard"
}
}) do |item|
item.with_leading_visual_icon(icon: :copy)
end
end
def render_user_name
if changeset.user
render_user_link(changeset.user)
else
render_committer_name(changeset.committer)
end
end
def render_user_link(user)
render(Primer::Beta::Link.new(
href: user_url(user),
target: "_blank",
scheme: :primary,
underline: false,
font_weight: :bold
)) do
changeset.user.name
end
end
end
end
end
end