-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathitem_component.rb
168 lines (146 loc) · 6.08 KB
/
item_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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.
#++
module WorkPackages
module ActivitiesTab
module Journals
class ItemComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
include WorkPackages::ActivitiesTab::SharedHelpers
include WorkPackages::ActivitiesTab::StimulusControllers
def initialize(journal:, filter:, grouped_emoji_reactions:, state: :show)
super
@journal = journal
@filter = filter
@grouped_emoji_reactions = grouped_emoji_reactions
@state = state
end
private
attr_reader :journal, :state, :filter, :grouped_emoji_reactions
def wrapper_uniq_by
journal.id
end
def wrapper_data_attributes
{
controller: "work-packages--activities-tab--item",
"application-target": "dynamic",
"work-packages--activities-tab--item-activity-url-value": activity_url(journal)
}
end
def container_classes
[].tap do |classes|
if journal.restricted?
classes << "work-packages-activities-tab-journals-item-component--container__restricted-comment"
end
end
end
def comment_header_classes
[].tap do |classes|
if journal.restricted?
classes << "work-packages-activities-tab-journals-item-component--header__restricted-comment"
end
end
end
def comment_body_classes
["work-packages-activities-tab-journals-item-component--journal-notes-body"].tap do |classes|
if journal.restricted?
classes << "work-packages-activities-tab-journals-item-component--journal-notes-body__restricted-comment"
end
end
end
def show_comment_container?
(journal.notes.present? || noop?) && filter != :only_changes
end
def noop?
journal.noop?
end
def updated?
return false if journal.initial?
journal.updated_at - journal.created_at > 5.seconds
end
def has_unread_notifications?
journal.has_unread_notifications_for_user?(User.current)
end
def notification_on_details?
has_unread_notifications? && journal.notes.blank?
end
def allowed_to_edit?
journal.editable_by?(User.current)
end
def allowed_to_quote?
User.current.allowed_in_project?(:add_work_package_notes, journal.journable.project)
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 edit_action_item(menu)
menu.with_item(label: t("js.label_edit_comment"),
href: edit_work_package_activity_path(journal.journable, journal, filter:),
content_arguments: {
data: { turbo_stream: true, test_selector: "op-wp-journal-#{journal.id}-edit" }
}) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
end
def quote_action_item(menu)
menu.with_item(label: t("js.label_quote_comment"),
tag: :button,
content_arguments: {
data: quote_action_data_attributes
}) do |item|
item.with_leading_visual_icon(icon: :quote)
end
end
def quote_action_data_attributes # rubocop:disable Metrics/AbcSize
{
controller: quote_comments_stimulus_controller,
"application-target": "dynamic",
action: "click->#{quote_comments_stimulus_controller}#quote:prevent",
quote_comments_stimulus_controller("-content-param") => journal.notes,
quote_comments_stimulus_controller("-user-id-param") => journal.user_id,
quote_comments_stimulus_controller("-user-name-param") => journal.user.name,
quote_comments_stimulus_controller("-is-restricted-param") => journal.restricted?,
quote_comments_stimulus_controller("-text-wrote-param") => I18n.t(:text_wrote),
quote_comments_stimulus_controller("-#{index_stimulus_controller}-outlet") => items_index_selector,
quote_comments_stimulus_controller("-#{restricted_comment_stimulus_controller}-outlet") => add_comment_selector,
test_selector: "op-wp-journal-#{journal.id}-quote"
}
end
end
end
end
end