decidim-comments 0.23.1 → 0.24.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
- data/app/assets/javascripts/decidim/comments/comments.component.js.es6 +292 -0
- data/app/assets/javascripts/decidim/comments/comments.component.test.js +581 -0
- data/app/assets/javascripts/decidim/comments/comments.js.erb +1 -1
- data/app/cells/decidim/comments/comment/actions.erb +7 -0
- data/app/cells/decidim/comments/comment/alignment_badge.erb +4 -0
- data/app/cells/decidim/comments/comment/author.erb +1 -0
- data/app/cells/decidim/comments/comment/show.erb +40 -0
- data/app/cells/decidim/comments/comment/utilities.erb +13 -0
- data/app/cells/decidim/comments/comment/votes.erb +25 -0
- data/app/cells/decidim/comments/comment_card_cell.rb +22 -0
- data/app/cells/decidim/comments/comment_cell.rb +142 -8
- data/app/cells/decidim/comments/comment_form/comment_as.erb +10 -0
- data/app/cells/decidim/comments/comment_form/show.erb +24 -0
- data/app/cells/decidim/comments/comment_form_cell.rb +94 -0
- data/app/cells/decidim/comments/comment_m/top.erb +1 -1
- data/app/cells/decidim/comments/comment_thread/show.erb +6 -0
- data/app/cells/decidim/comments/comment_thread/title.erb +3 -0
- data/app/cells/decidim/comments/comment_thread_cell.rb +30 -0
- data/app/cells/decidim/comments/comments/add_comment.erb +30 -0
- data/app/cells/decidim/comments/comments/blocked_comments_warning.erb +3 -0
- data/app/cells/decidim/comments/comments/order_control.erb +37 -0
- data/app/cells/decidim/comments/comments/show.erb +32 -0
- data/app/cells/decidim/comments/comments/single_comment_warning.erb +9 -0
- data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +3 -0
- data/app/cells/decidim/comments/comments_cell.rb +134 -0
- data/app/commands/decidim/comments/vote_comment.rb +34 -10
- data/app/controllers/decidim/comments/application_controller.rb +16 -0
- data/app/controllers/decidim/comments/comments_controller.rb +122 -0
- data/app/controllers/decidim/comments/votes_controller.rb +41 -0
- data/app/events/decidim/comments/comment_created_event.rb +1 -1
- data/app/events/decidim/comments/comment_downvoted_event.rb +8 -0
- data/app/events/decidim/comments/comment_event.rb +0 -15
- data/app/events/decidim/comments/comment_upvoted_event.rb +8 -0
- data/app/events/decidim/comments/comment_voted_event.rb +26 -0
- data/app/forms/decidim/comments/comment_form.rb +6 -2
- data/app/models/decidim/comments/comment.rb +33 -11
- data/app/models/decidim/comments/seed.rb +1 -1
- data/app/permissions/decidim/comments/permissions.rb +59 -0
- data/app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb +2 -2
- data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +5 -6
- data/app/queries/decidim/comments/sorted_comments.rb +18 -14
- data/app/views/decidim/comments/comments/_comment.html.erb +5 -0
- data/app/views/decidim/comments/comments/_comments.html.erb +1 -0
- data/app/views/decidim/comments/comments/create.js.erb +16 -0
- data/app/views/decidim/comments/comments/error.js.erb +1 -0
- data/app/views/decidim/comments/comments/index.js.erb +24 -0
- data/app/views/decidim/comments/comments/reload.js.erb +21 -0
- data/app/views/decidim/comments/votes/create.js.erb +23 -0
- data/app/views/decidim/comments/votes/error.js.erb +1 -0
- data/config/locales/ar.yml +0 -2
- data/config/locales/ca.yml +17 -2
- data/config/locales/cs.yml +20 -3
- data/config/locales/de.yml +46 -30
- data/config/locales/el.yml +0 -2
- data/config/locales/en.yml +17 -2
- data/config/locales/es-MX.yml +17 -2
- data/config/locales/es-PY.yml +17 -2
- data/config/locales/es.yml +17 -2
- data/config/locales/eu.yml +0 -2
- data/config/locales/fi-plain.yml +17 -2
- data/config/locales/fi.yml +17 -2
- data/config/locales/fr-CA.yml +17 -2
- data/config/locales/fr.yml +17 -2
- data/config/locales/gl.yml +20 -2
- data/config/locales/hu.yml +0 -2
- data/config/locales/id-ID.yml +0 -2
- data/config/locales/is-IS.yml +0 -1
- data/config/locales/it.yml +5 -2
- data/config/locales/ja.yml +14 -10
- data/config/locales/lv.yml +0 -2
- data/config/locales/nl.yml +7 -9
- data/config/locales/no.yml +0 -2
- data/config/locales/pl.yml +22 -4
- data/config/locales/pt-BR.yml +0 -2
- data/config/locales/pt.yml +0 -2
- data/config/locales/ro-RO.yml +0 -2
- data/config/locales/ru.yml +0 -2
- data/config/locales/si-LK.yml +1 -0
- data/config/locales/sk.yml +0 -2
- data/config/locales/sv.yml +7 -2
- data/config/locales/sw-KE.yml +1 -0
- data/config/locales/tr-TR.yml +60 -35
- data/config/locales/uk.yml +0 -1
- data/config/locales/zh-CN.yml +0 -2
- data/lib/decidim/api/add_comment_type.rb +13 -0
- data/lib/decidim/api/comment_mutation_type.rb +22 -0
- data/lib/decidim/api/comment_type.rb +89 -0
- data/lib/decidim/api/commentable_interface.rb +50 -0
- data/lib/decidim/api/commentable_mutation_type.rb +30 -0
- data/{app/types/decidim/comments → lib/decidim/api}/commentable_type.rb +2 -5
- data/lib/decidim/comments.rb +1 -3
- data/lib/decidim/comments/api.rb +12 -0
- data/lib/decidim/comments/comments_helper.rb +10 -52
- data/lib/decidim/comments/engine.rb +9 -7
- data/lib/decidim/comments/mutation_extensions.rb +22 -22
- data/lib/decidim/comments/query_extensions.rb +12 -14
- data/lib/decidim/comments/test.rb +1 -0
- data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +65 -0
- data/lib/decidim/comments/version.rb +1 -1
- metadata +72 -69
- data/app/assets/javascripts/decidim/comments/bundle.js +0 -268
- data/app/frontend/application/apollo_client.ts +0 -12
- data/app/frontend/application/application.component.test.tsx +0 -23
- data/app/frontend/application/application.component.tsx +0 -35
- data/app/frontend/application/icon.component.test.tsx +0 -38
- data/app/frontend/application/icon.component.tsx +0 -46
- data/app/frontend/comments/add_comment_form.component.test.tsx +0 -265
- data/app/frontend/comments/add_comment_form.component.tsx +0 -482
- data/app/frontend/comments/comment.component.test.tsx +0 -490
- data/app/frontend/comments/comment.component.tsx +0 -677
- data/app/frontend/comments/comment_order_selector.component.test.tsx +0 -29
- data/app/frontend/comments/comment_order_selector.component.tsx +0 -106
- data/app/frontend/comments/comment_thread.component.test.tsx +0 -82
- data/app/frontend/comments/comment_thread.component.tsx +0 -81
- data/app/frontend/comments/comments.component.test.tsx +0 -150
- data/app/frontend/comments/comments.component.tsx +0 -289
- data/app/frontend/comments/down_vote_button.component.test.tsx +0 -59
- data/app/frontend/comments/down_vote_button.component.tsx +0 -133
- data/app/frontend/comments/up_vote_button.component.test.tsx +0 -59
- data/app/frontend/comments/up_vote_button.component.tsx +0 -133
- data/app/frontend/comments/vote_button.component.tsx +0 -50
- data/app/frontend/comments/vote_button_component.test.tsx +0 -64
- data/app/frontend/entry.ts +0 -38
- data/app/frontend/entry_test.ts +0 -6
- data/app/frontend/fragments/add_comment_form_commentable.fragment.graphql +0 -4
- data/app/frontend/fragments/add_comment_form_session.fragment.graphql +0 -6
- data/app/frontend/fragments/comment.fragment.graphql +0 -14
- data/app/frontend/fragments/comment_data.fragment.graphql +0 -27
- data/app/frontend/fragments/comment_thread.fragment.graphql +0 -6
- data/app/frontend/fragments/down_vote_button.fragment.graphql +0 -6
- data/app/frontend/fragments/up_vote_button.fragment.graphql +0 -6
- data/app/frontend/mutations/add_comment.mutation.graphql +0 -9
- data/app/frontend/mutations/down_vote.mutation.graphql +0 -9
- data/app/frontend/mutations/up_vote.mutation.graphql +0 -9
- data/app/frontend/queries/comments.query.graphql +0 -26
- data/app/frontend/support/asset_url.ts +0 -11
- data/app/frontend/support/generate_comments_data.ts +0 -49
- data/app/frontend/support/generate_user_data.ts +0 -14
- data/app/frontend/support/generate_user_group_data.ts +0 -14
- data/app/frontend/support/graphql_transformer.js +0 -32
- data/app/frontend/support/load_translations.ts +0 -48
- data/app/frontend/support/require_all.ts +0 -10
- data/app/frontend/support/resolve_graphql_query.ts +0 -37
- data/app/frontend/support/schema.ts +0 -2026
- data/app/types/decidim/comments/commentable_interface.rb +0 -61
- data/app/types/decidim/comments/commentable_mutation_type.rb +0 -33
- data/lib/decidim/comments/api/add_comment_type.rb +0 -13
- data/lib/decidim/comments/api/comment_mutation_type.rb +0 -20
- data/lib/decidim/comments/api/comment_type.rb +0 -89
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<div class="comment__actions">
|
|
2
|
+
<% if can_reply? %>
|
|
3
|
+
<button class="comment__reply muted-link" aria-controls="<%= reply_id %>" data-toggle="<%= reply_id %>">
|
|
4
|
+
<%= icon "pencil", class: "icon--small", role: "none presentation" %> <%= t("decidim.components.comment.reply") %>
|
|
5
|
+
</button>
|
|
6
|
+
<% end %>
|
|
7
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%== cell("decidim/author", author_presenter).profile %>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<%= content_tag :div, id: "comment_#{model.id}", class: comment_classes, data: { comment_id: model.id } do %>
|
|
2
|
+
<div class="comment__header">
|
|
3
|
+
<div class="author-data">
|
|
4
|
+
<div class="author-data__main">
|
|
5
|
+
<%= render :author %>
|
|
6
|
+
<span>
|
|
7
|
+
<%= time_tag created_at, l(created_at, format: :decidim_short) %>
|
|
8
|
+
</span>
|
|
9
|
+
</div>
|
|
10
|
+
<div class="author-data__extra">
|
|
11
|
+
<%= render :utilities %>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
<div class="comment__content">
|
|
16
|
+
<%= alignment_badge %>
|
|
17
|
+
<%= comment_body %>
|
|
18
|
+
</div>
|
|
19
|
+
<div class="comment__footer">
|
|
20
|
+
<%= render :actions %>
|
|
21
|
+
<%= votes %>
|
|
22
|
+
</div>
|
|
23
|
+
<div id="comment-<%= model.id %>-replies">
|
|
24
|
+
<% if has_replies? %>
|
|
25
|
+
<% replies.each do |reply| %>
|
|
26
|
+
<%= cell("decidim/comments/comment", reply, root_depth: root_depth, order: order) %>
|
|
27
|
+
<% end %>
|
|
28
|
+
<% end %>
|
|
29
|
+
</div>
|
|
30
|
+
<% if can_reply? %>
|
|
31
|
+
<div class="comment__additionalreply<%= " hide" unless has_replies? %>">
|
|
32
|
+
<button class="comment__reply muted-link" aria-controls="<%= reply_id %>" data-toggle="<%= reply_id %>">
|
|
33
|
+
<%= icon "pencil", class: "icon--small", role: "none presentation" %> <%= t("decidim.components.comment.reply") %>
|
|
34
|
+
</button>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="add-comment hide" id="<%= reply_id %>" data-toggler=".hide">
|
|
37
|
+
<%== cell("decidim/comments/comment_form", model, root_depth: root_depth, order: order) %>
|
|
38
|
+
</div>
|
|
39
|
+
<% end %>
|
|
40
|
+
<% end %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<button type="button" class="link-alt" data-open="<%= current_user.present? ? "flagModalComment#{model.id}" : "loginModal" %>" title="<%= t("decidim.components.comment.report.title") %>" aria-controls="<%= current_user.present? ? "flagModalComment#{model.id}" : "loginModal" %>" aria-haspopup="true" tabindex="0">
|
|
2
|
+
<%= icon "flag", aria_hidden: true, class: "icon--small", role: "none presentation", "aria-hidden": true %>
|
|
3
|
+
<span class="show-for-sr"><%= t("decidim.components.comment.report.title") %></span>
|
|
4
|
+
</button>
|
|
5
|
+
|
|
6
|
+
<%= link_to "#{commentable_path("commentId" => model.id)}#comment_#{model.id}", title: t("decidim.components.comment.single_comment_link_title") do %>
|
|
7
|
+
<span class="show-for-sr"><%= t("decidim.components.comment.single_comment_link_title") %></span>
|
|
8
|
+
<%= icon "link-intact", class: "icon--small", role: "none presentation" %>
|
|
9
|
+
<% end %>
|
|
10
|
+
|
|
11
|
+
<% if current_user.present? %>
|
|
12
|
+
<%= cell("decidim/flag_modal", model, modal_id: "flagModalComment#{model.id}") %>
|
|
13
|
+
<% end %>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<div class="comment__votes">
|
|
2
|
+
<% if user_signed_in? %>
|
|
3
|
+
<%= button_to decidim_comments.comment_votes_path(model, weight: 1), remote: true, disabled: voted_down?, class: votes_up_classes, title: t("decidim.components.up_vote_button.text") do %>
|
|
4
|
+
<span class="show-for-sr"><%= t("decidim.components.up_vote_button.text") %></span>
|
|
5
|
+
<%= icon "chevron-top", class: "icon--small", role: "none presentation" %>
|
|
6
|
+
<span class="comment__votes--count"><%= up_votes_count %></span>
|
|
7
|
+
<% end %>
|
|
8
|
+
<%= button_to decidim_comments.comment_votes_path(model, weight: -1), remote: true, disabled: voted_up?, class: votes_down_classes, title: t("decidim.components.down_vote_button.text") do %>
|
|
9
|
+
<span class="show-for-sr"><%= t("decidim.components.down_vote_button.text") %></span>
|
|
10
|
+
<%= icon "chevron-bottom", class: "icon--small", role: "none presentation" %>
|
|
11
|
+
<span class="comment__votes--count"><%= down_votes_count %></span>
|
|
12
|
+
<% end %>
|
|
13
|
+
<% else %>
|
|
14
|
+
<button class="<%= votes_up_classes %> " title="<%= t("decidim.components.up_vote_button.text") %>" data-open="loginModal">
|
|
15
|
+
<span class="show-for-sr"><%= t("decidim.components.up_vote_button.text") %></span>
|
|
16
|
+
<%= icon "chevron-top", class: "icon--small", role: "none presentation" %>
|
|
17
|
+
<span class="comment__votes--count"><%= up_votes_count %></span>
|
|
18
|
+
</button>
|
|
19
|
+
<button class="<%= votes_down_classes %> " title="<%= t("decidim.components.down_vote_button.text") %>" data-open="loginModal">
|
|
20
|
+
<span class="show-for-sr"><%= t("decidim.components.down_vote_button.text") %></span>
|
|
21
|
+
<%= icon "chevron-bottom", class: "icon--small", role: "none presentation" %>
|
|
22
|
+
<span class="comment__votes--count"><%= down_votes_count %></span>
|
|
23
|
+
</button>
|
|
24
|
+
<% end %>
|
|
25
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Comments
|
|
5
|
+
# This cell renders the comment card for an instance of a Comment
|
|
6
|
+
# the default size is the Medium Card (:m)
|
|
7
|
+
class CommentCardCell < Decidim::ViewModel
|
|
8
|
+
include CommentCellsHelper
|
|
9
|
+
include Cell::ViewModel::Partial
|
|
10
|
+
|
|
11
|
+
def show
|
|
12
|
+
cell card_size, model, options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def card_size
|
|
18
|
+
"decidim/comments/comment_m"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -2,20 +2,154 @@
|
|
|
2
2
|
|
|
3
3
|
module Decidim
|
|
4
4
|
module Comments
|
|
5
|
-
#
|
|
6
|
-
# the default size is the Medium Card (:m)
|
|
5
|
+
# A cell to display a single comment.
|
|
7
6
|
class CommentCell < Decidim::ViewModel
|
|
8
|
-
include
|
|
9
|
-
include
|
|
7
|
+
include ActionView::Helpers::DateHelper
|
|
8
|
+
include Decidim::IconHelper
|
|
9
|
+
include Decidim::ResourceHelper
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
delegate :current_user, :user_signed_in?, to: :controller
|
|
12
|
+
|
|
13
|
+
property :root_commentable
|
|
14
|
+
property :created_at
|
|
15
|
+
property :alignment
|
|
16
|
+
property :translated_body
|
|
17
|
+
property :comment_threads
|
|
18
|
+
property :accepts_new_comments?
|
|
19
|
+
|
|
20
|
+
def alignment_badge
|
|
21
|
+
return unless [-1, 1].include?(alignment)
|
|
22
|
+
|
|
23
|
+
render :alignment_badge
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def votes
|
|
27
|
+
return unless root_commentable.comments_have_votes?
|
|
28
|
+
|
|
29
|
+
render :votes
|
|
13
30
|
end
|
|
14
31
|
|
|
15
32
|
private
|
|
16
33
|
|
|
17
|
-
def
|
|
18
|
-
|
|
34
|
+
def decidim_comments
|
|
35
|
+
Decidim::Comments::Engine.routes.url_helpers
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def comment_body
|
|
39
|
+
Decidim::ContentProcessor.render(translated_body)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def replies
|
|
43
|
+
SortedComments.for(model, order_by: order)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def order
|
|
47
|
+
options[:order] || "older"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def reply_id
|
|
51
|
+
"comment#{model.id}-reply"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def can_reply?
|
|
55
|
+
user_signed_in? && accepts_new_comments? &&
|
|
56
|
+
root_commentable.user_allowed_to_comment?(current_user)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def author_presenter
|
|
60
|
+
if model.author.respond_to?(:official?) && model.author.official?
|
|
61
|
+
Decidim::Core::OfficialAuthorPresenter.new
|
|
62
|
+
elsif model.user_group
|
|
63
|
+
model.user_group.presenter
|
|
64
|
+
else
|
|
65
|
+
model.author.presenter
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def comment_classes
|
|
70
|
+
classes = ["comment"]
|
|
71
|
+
if nested?
|
|
72
|
+
classes << "comment--nested"
|
|
73
|
+
classes << "comment--nested--alt" if nested_level_even?
|
|
74
|
+
end
|
|
75
|
+
classes.join(" ")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def alignment_badge_classes
|
|
79
|
+
classes = %w(label alignment)
|
|
80
|
+
case alignment
|
|
81
|
+
when 1
|
|
82
|
+
classes << "success"
|
|
83
|
+
when -1
|
|
84
|
+
classes << "alert"
|
|
85
|
+
end
|
|
86
|
+
classes.join(" ")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def alignment_badge_label
|
|
90
|
+
if alignment == 1
|
|
91
|
+
I18n.t("decidim.components.comment.alignment.in_favor")
|
|
92
|
+
else
|
|
93
|
+
I18n.t("decidim.components.comment.alignment.against")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def votes_up_classes
|
|
98
|
+
classes = ["comment__votes--up"]
|
|
99
|
+
classes << "is-vote-selected" if voted_up?
|
|
100
|
+
classes << "is-vote-notselected" if voted_down?
|
|
101
|
+
classes.join(" ")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def votes_down_classes
|
|
105
|
+
classes = ["comment__votes--down"]
|
|
106
|
+
classes << "is-vote-selected" if voted_down?
|
|
107
|
+
classes << "is-vote-notselected" if voted_up?
|
|
108
|
+
classes.join(" ")
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def commentable_path(params = {})
|
|
112
|
+
if root_commentable.is_a?(Decidim::Budgets::Project)
|
|
113
|
+
resource_locator([root_commentable.budget, root_commentable]).path(params)
|
|
114
|
+
else
|
|
115
|
+
resource_locator(root_commentable).path(params)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def up_votes_count
|
|
120
|
+
model.up_votes.count
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def down_votes_count
|
|
124
|
+
model.down_votes.count
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def root_depth
|
|
128
|
+
options[:root_depth] || 0
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def depth
|
|
132
|
+
model.depth - root_depth
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def voted_up?
|
|
136
|
+
model.up_voted_by?(current_user)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def voted_down?
|
|
140
|
+
model.down_voted_by?(current_user)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def nested?
|
|
144
|
+
depth.positive?
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def nested_level_even?
|
|
148
|
+
depth.even?
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def has_replies?
|
|
152
|
+
model.comment_threads.any?
|
|
19
153
|
end
|
|
20
154
|
end
|
|
21
155
|
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<div class="field">
|
|
2
|
+
<label for="<%= comment_as_id %>">
|
|
3
|
+
<%= t("decidim.components.add_comment_form.form.user_group_id.label") %>
|
|
4
|
+
</label>
|
|
5
|
+
<select id="<%= comment_as_id %>" name="comment[user_group_id]">
|
|
6
|
+
<% comment_as_options.each do |option| %>
|
|
7
|
+
<option value="<%= option[1] %>"><%= option[0] %></option>
|
|
8
|
+
<% end %>
|
|
9
|
+
</select>
|
|
10
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%= form_for(form_object, url: decidim_comments.comments_path(order: order), method: :post, remote: true, html: { id: form_id }) do |form| %>
|
|
2
|
+
<%= form.hidden_field :commentable_gid, id: nil %>
|
|
3
|
+
<%= form.hidden_field :alignment, id: nil, class: "alignment-input" %>
|
|
4
|
+
<%= comment_as_for(form) %>
|
|
5
|
+
<div class="field">
|
|
6
|
+
<label class="show-for-sr" for="<%= add_comment_id %>">
|
|
7
|
+
<%= t("decidim.components.add_comment_form.form.body.label") %>
|
|
8
|
+
</label>
|
|
9
|
+
<div class="hashtags__container">
|
|
10
|
+
<%= form.text_area(
|
|
11
|
+
:body,
|
|
12
|
+
id: add_comment_id,
|
|
13
|
+
rows: 4,
|
|
14
|
+
maxlength: comments_max_length,
|
|
15
|
+
required: true,
|
|
16
|
+
placeholder: t("decidim.components.add_comment_form.form.body.placeholder"),
|
|
17
|
+
label: false,
|
|
18
|
+
data: { remaining_characters: "##{add_comment_id}-remaining-characters" }
|
|
19
|
+
) %>
|
|
20
|
+
</div>
|
|
21
|
+
<button type="submit" class="button button--sc" disabled="disabled"><%= t("decidim.components.add_comment_form.form.submit") %></button>
|
|
22
|
+
<span id="<%= add_comment_id %>-remaining-characters" class="remaining-character-count"></span>
|
|
23
|
+
</div>
|
|
24
|
+
<% end %>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Comments
|
|
5
|
+
# A cell to display a form for adding a new comment.
|
|
6
|
+
class CommentFormCell < Decidim::ViewModel
|
|
7
|
+
delegate :current_user, :user_signed_in?, to: :controller
|
|
8
|
+
|
|
9
|
+
def comment_as_for(form)
|
|
10
|
+
return if verified_user_groups.blank?
|
|
11
|
+
|
|
12
|
+
# Note that the form.select does not seem to work correctly in the cell
|
|
13
|
+
# context. The Rails form builder tries to call @template.select which
|
|
14
|
+
# is not available for the cell objects.
|
|
15
|
+
render view: :comment_as, locals: { form: form }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def decidim_comments
|
|
21
|
+
Decidim::Comments::Engine.routes.url_helpers
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def order
|
|
25
|
+
options[:order] || "older"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def commentable_type
|
|
29
|
+
model.commentable_type
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def form_id
|
|
33
|
+
"new_comment_for_#{commentable_type.demodulize}_#{model.id}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def add_comment_id
|
|
37
|
+
"add-comment-#{commentable_type.demodulize}-#{model.id}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def comment_as_id
|
|
41
|
+
"add-comment-#{commentable_type.demodulize}-#{model.id}-user-group-id"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def root_depth
|
|
45
|
+
options[:root_depth] || 0
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def form_object
|
|
49
|
+
Decidim::Comments::CommentForm.new(
|
|
50
|
+
commentable_gid: model.to_signed_global_id.to_s,
|
|
51
|
+
alignment: 0
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def verified_user_groups
|
|
56
|
+
return [] unless current_user
|
|
57
|
+
|
|
58
|
+
@verified_user_groups ||= Decidim::UserGroups::ManageableUserGroups.for(current_user).verified
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def comment_as_options
|
|
62
|
+
[[current_user.name, ""]] + verified_user_groups.map do |group|
|
|
63
|
+
[group.name, group.id]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def comments_max_length
|
|
68
|
+
return 1000 unless model.respond_to?(:component)
|
|
69
|
+
return component_comments_max_length if component_comments_max_length
|
|
70
|
+
return organization_comments_max_length if organization_comments_max_length
|
|
71
|
+
|
|
72
|
+
1000
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def component_comments_max_length
|
|
76
|
+
return unless model.component&.settings.respond_to?(:comments_max_length)
|
|
77
|
+
|
|
78
|
+
model.component.settings.comments_max_length if model.component.settings.comments_max_length.positive?
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def organization_comments_max_length
|
|
82
|
+
return unless organization
|
|
83
|
+
|
|
84
|
+
organization.comments_max_length if organization.comments_max_length.positive?
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def organization
|
|
88
|
+
return model.organization if model.respond_to?(:organization)
|
|
89
|
+
|
|
90
|
+
model.component.organization if model.component.organization.comments_max_length.positive?
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div class="card__top">
|
|
2
2
|
<% if render_space? %>
|
|
3
3
|
<div class="card__content text-small">
|
|
4
|
-
<span class="muted"><%= searchable_resource_human_name(model.root_commentable.class) %>:</span> <%= link_to root_commentable_title, resource_link_path, class: "card__link text-ellipsis" %>
|
|
4
|
+
<span class="muted"><%= searchable_resource_human_name(model.root_commentable.class, count: 1) %>:</span> <%= link_to root_commentable_title, resource_link_path, class: "card__link text-ellipsis" %>
|
|
5
5
|
</div>
|
|
6
6
|
<% end %>
|
|
7
7
|
</div>
|