decidim-comments 0.27.5 → 0.28.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/comments/comment/actions.erb +13 -7
  3. data/app/cells/decidim/comments/comment/alignment_badge.erb +1 -4
  4. data/app/cells/decidim/comments/comment/deletion_data.erb +9 -1
  5. data/app/cells/decidim/comments/comment/moderation_data.erb +1 -1
  6. data/app/cells/decidim/comments/comment/replies.erb +3 -0
  7. data/app/cells/decidim/comments/comment/show.erb +72 -35
  8. data/app/cells/decidim/comments/comment/votes.erb +14 -14
  9. data/app/cells/decidim/comments/comment_activity_cell.rb +11 -7
  10. data/app/cells/decidim/comments/comment_card_cell.rb +2 -2
  11. data/app/cells/decidim/comments/comment_cell.rb +5 -15
  12. data/app/cells/decidim/comments/comment_form/comment_as.erb +3 -3
  13. data/app/cells/decidim/comments/comment_form/opinion.erb +18 -0
  14. data/app/cells/decidim/comments/comment_form/show.erb +33 -16
  15. data/app/cells/decidim/comments/comment_form_cell.rb +9 -1
  16. data/app/cells/decidim/comments/comment_metadata_cell.rb +27 -0
  17. data/app/cells/decidim/comments/comment_s_cell.rb +27 -0
  18. data/app/cells/decidim/comments/comment_thread/show.erb +2 -5
  19. data/app/cells/decidim/comments/comment_thread_cell.rb +0 -6
  20. data/app/cells/decidim/comments/comments/add_comment.erb +1 -20
  21. data/app/cells/decidim/comments/comments/blocked_comments_warning.erb +1 -3
  22. data/app/cells/decidim/comments/comments/comments_loading.erb +1 -3
  23. data/app/cells/decidim/comments/comments/order_control.erb +11 -35
  24. data/app/cells/decidim/comments/comments/show.erb +8 -9
  25. data/app/cells/decidim/comments/comments/single_comment_warning.erb +6 -9
  26. data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +9 -6
  27. data/app/cells/decidim/comments/comments_cell.rb +1 -1
  28. data/app/cells/decidim/comments/edit_comment_modal_form/show.erb +20 -15
  29. data/app/commands/decidim/comments/create_comment.rb +17 -5
  30. data/app/commands/decidim/comments/delete_comment.rb +1 -1
  31. data/app/commands/decidim/comments/update_comment.rb +14 -2
  32. data/app/commands/decidim/comments/vote_comment.rb +1 -1
  33. data/app/controllers/decidim/comments/comments_controller.rb +14 -9
  34. data/app/controllers/decidim/comments/votes_controller.rb +1 -1
  35. data/app/events/decidim/comments/comment_by_followed_user_event.rb +1 -1
  36. data/app/events/decidim/comments/comment_by_followed_user_group_event.rb +1 -1
  37. data/app/events/decidim/comments/comment_event.rb +2 -3
  38. data/app/events/decidim/comments/reply_created_event.rb +1 -1
  39. data/app/events/decidim/comments/user_group_mentioned_event.rb +1 -1
  40. data/app/events/decidim/comments/user_mentioned_event.rb +1 -1
  41. data/app/helpers/decidim/comments/comment_cells_helper.rb +1 -1
  42. data/app/jobs/decidim/comments/hide_all_created_by_author_job.rb +13 -0
  43. data/app/models/decidim/comments/comment.rb +7 -4
  44. data/app/models/decidim/comments/seed.rb +30 -14
  45. data/app/packs/entrypoints/decidim_comments.js +5 -0
  46. data/app/packs/src/decidim/comments/comments.component.js +27 -36
  47. data/app/packs/src/decidim/comments/comments.component.test.js +218 -240
  48. data/app/packs/src/decidim/comments/comments.component_for_testing.js +1 -1
  49. data/app/packs/src/decidim/comments/comments.js +20 -1
  50. data/app/packs/stylesheets/comments.scss +327 -0
  51. data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +1 -1
  52. data/app/queries/decidim/comments/sorted_comments.rb +10 -10
  53. data/app/services/decidim/comments/comment_creation.rb +1 -1
  54. data/app/services/decidim/comments/new_comment_notification_creator.rb +8 -8
  55. data/app/views/decidim/comments/admin/shared/_availability_fields.html.erb +4 -9
  56. data/app/views/decidim/comments/comments/_comment.html.erb +1 -1
  57. data/app/views/decidim/comments/comments/_comments.html.erb +1 -1
  58. data/app/views/decidim/comments/comments/_delete.html.erb +2 -4
  59. data/app/views/decidim/comments/comments/_moderated.html.erb +2 -4
  60. data/app/views/decidim/comments/comments/create.js.erb +5 -3
  61. data/app/views/decidim/comments/comments/delete.js.erb +4 -1
  62. data/app/views/decidim/comments/comments/index.js.erb +8 -1
  63. data/app/views/decidim/comments/comments/reload.js.erb +1 -2
  64. data/app/views/decidim/comments/comments/update.js.erb +5 -4
  65. data/app/views/decidim/comments/votes/create.js.erb +5 -5
  66. data/config/assets.rb +3 -0
  67. data/config/locales/ar.yml +0 -16
  68. data/config/locales/ca.yml +8 -10
  69. data/config/locales/cs.yml +8 -10
  70. data/config/locales/de.yml +7 -9
  71. data/config/locales/el.yml +3 -11
  72. data/config/locales/en.yml +10 -12
  73. data/config/locales/es-MX.yml +10 -12
  74. data/config/locales/es-PY.yml +10 -12
  75. data/config/locales/es.yml +9 -11
  76. data/config/locales/eu.yml +6 -8
  77. data/config/locales/fi-plain.yml +7 -9
  78. data/config/locales/fi.yml +7 -9
  79. data/config/locales/fr-CA.yml +9 -11
  80. data/config/locales/fr.yml +9 -11
  81. data/config/locales/ga-IE.yml +0 -4
  82. data/config/locales/gl.yml +0 -16
  83. data/config/locales/hu.yml +5 -11
  84. data/config/locales/id-ID.yml +0 -11
  85. data/config/locales/is-IS.yml +0 -8
  86. data/config/locales/it.yml +0 -16
  87. data/config/locales/ja.yml +6 -8
  88. data/config/locales/lb.yml +0 -16
  89. data/config/locales/lt.yml +7 -10
  90. data/config/locales/lv.yml +0 -11
  91. data/config/locales/nl.yml +0 -16
  92. data/config/locales/no.yml +0 -16
  93. data/config/locales/pl.yml +7 -10
  94. data/config/locales/pt-BR.yml +0 -18
  95. data/config/locales/pt.yml +0 -16
  96. data/config/locales/ro-RO.yml +2 -10
  97. data/config/locales/ru.yml +0 -11
  98. data/config/locales/sk.yml +0 -11
  99. data/config/locales/sv.yml +2 -16
  100. data/config/locales/tr-TR.yml +1 -13
  101. data/config/locales/uk.yml +0 -8
  102. data/config/locales/zh-CN.yml +0 -13
  103. data/config/locales/zh-TW.yml +1 -9
  104. data/lib/decidim/api/commentable_interface.rb +1 -1
  105. data/lib/decidim/comments/comment_serializer.rb +1 -1
  106. data/lib/decidim/comments/comment_vote_serializer.rb +1 -1
  107. data/lib/decidim/comments/commentable.rb +1 -1
  108. data/lib/decidim/comments/comments_helper.rb +6 -3
  109. data/lib/decidim/comments/engine.rb +31 -1
  110. data/lib/decidim/comments/export.rb +1 -1
  111. data/lib/decidim/comments/test/factories.rb +2 -2
  112. data/lib/decidim/comments/test/shared_examples/comment_event.rb +3 -3
  113. data/lib/decidim/comments/test/shared_examples/comment_voted_event.rb +3 -3
  114. data/lib/decidim/comments/test/shared_examples/create_comment_context.rb +5 -5
  115. data/lib/decidim/comments/test/shared_examples/has_comments_availability_attributes.rb +2 -2
  116. data/lib/decidim/comments/test/shared_examples/translatable_comment.rb +3 -3
  117. data/lib/decidim/comments/version.rb +1 -1
  118. metadata +26 -21
  119. data/app/cells/decidim/comments/comment/author.erb +0 -1
  120. data/app/cells/decidim/comments/comment/utilities.erb +0 -41
  121. data/app/cells/decidim/comments/comment_m/footer.erb +0 -5
  122. data/app/cells/decidim/comments/comment_m/top.erb +0 -7
  123. data/app/cells/decidim/comments/comment_m_cell.rb +0 -29
  124. data/app/cells/decidim/comments/comment_thread/title.erb +0 -3
  125. data/config/environment.rb +0 -3
@@ -1,16 +1,17 @@
1
1
  <%= content_tag :div, id: node_id, data: { decidim_comments: comments_data } do %>
2
- <div class="columns large-9 comments-container" id="comments">
2
+ <div id="comments">
3
3
  <div class="comments">
4
- <div class="row collapse order-by">
5
- <h3 class="order-by__text section-heading">
4
+ <div class="comments__header">
5
+ <h2 class="h4">
6
6
  <% if single_comment? %>
7
7
  <%= t("decidim.components.comments.comment_details_title") %>
8
8
  <% else %>
9
- <span class="comments-count">
9
+ <%= icon "chat-1-line", class: "fill-tertiary w-6 h-6 inline-block align-middle" %>
10
+ <span class="comments-count inline-block align-middle">
10
11
  <%= t("decidim.components.comments.title", count: comments_count) %>
11
12
  </span>
12
13
  <% end %>
13
- </h3>
14
+ </h2>
14
15
  <%= render :order_control %>
15
16
  </div>
16
17
  <%= single_comment_warning %>
@@ -18,14 +19,12 @@
18
19
  <div class="comment-threads">
19
20
  <%= comments_loading %>
20
21
  <% comments.each do |comment| %>
21
- <%= cell("decidim/comments/comment_thread", comment, order: order) %>
22
+ <%= cell("decidim/comments/comment_thread", comment, order:) %>
22
23
  <% end %>
23
24
  </div>
24
25
  <%= add_comment %>
25
26
  <%= user_comments_blocked_warning %>
26
27
  </div>
27
- <div class="callout primary loading-comments hide">
28
- <p><%= t("decidim.components.comments.loading") %></p>
29
- </div>
28
+ <%= cell("decidim/announcement", t("decidim.components.comments.loading"), callout_class: "primary loading-comments hidden") %>
30
29
  </div>
31
30
  <% end %>
@@ -1,9 +1,6 @@
1
- <div class="callout secondary">
2
- <h5><%= t("decidim.components.comments.single_comment_warning_title") %></h5>
3
- <p>
4
- <%== t(
5
- "decidim.components.comments.single_comment_warning",
6
- url: "#{commentable_path}##{node_id}"
7
- ) %>
8
- </p>
9
- </div>
1
+ <%= cell("decidim/announcement", {
2
+ title: t("decidim.components.comments.single_comment_warning_title"),
3
+ body: t("decidim.components.comments.single_comment_warning", url: "#{commentable_path}##{node_id}")
4
+ },
5
+ callout_class: "secondary"
6
+ ) %>
@@ -1,7 +1,10 @@
1
- <div class="callout warning">
2
- <% if comment_permissions? %>
3
- <p><%= blocked_comments_for_unauthorized_user_warning_link %></p>
4
- <% else %>
5
- <p><%= t("decidim.components.comments.blocked_comments_for_user_warning") %></p>
6
- <% end %>
1
+ <%# We cannot use the AnnouncementCell directly here as the link is escaped and it would not work %>
2
+ <div class="flash warning" data-announcement="">
3
+ <span class="flash__message">
4
+ <% if comment_permissions? %>
5
+ <p><%= blocked_comments_for_unauthorized_user_warning_link %></p>
6
+ <% else %>
7
+ <p><%= t("decidim.components.comments.blocked_comments_for_user_warning") %></p>
8
+ <% end %>
9
+ </span>
7
10
  </div>
@@ -99,7 +99,7 @@ module Decidim
99
99
  commentableGid: model.to_signed_global_id.to_s,
100
100
  commentsUrl: decidim_comments.comments_path,
101
101
  rootDepth: root_depth,
102
- order: order
102
+ order:
103
103
  }
104
104
  end
105
105
 
@@ -1,16 +1,15 @@
1
- <div class="reveal edit-comment-modal" id="<%= "editCommentModal#{model.id}" %>" data-reveal role="dialog" aria-modal="true" aria-labelledby="<%= "editCommentModal#{model.id}" %>-label">
2
- <div class="reveal__header">
3
- <h3 id="<%= "editCommentModal#{model.id}" %>-label" class="reveal__title"><%= t("decidim.components.edit_comment_modal_form.title") %></h3>
4
- <button class="close-button" data-close aria-label="<%= t("decidim.components.edit_comment_modal_form.close") %>" type="button">
5
- <span aria-hidden="true">&times;</span>
6
- </button>
7
- </div>
8
- <%= form_for(form_object, url: decidim_comments.comment_path(comment), method: :put, remote: true, html: { id: form_id }) do |form| %>
9
- <div class="field">
10
- <label class="show-for-sr" for="<%= form_id %>">
11
- <%= t("decidim.components.edit_comment_modal_form.form.body.label") %>
12
- </label>
13
- <div class="hashtags__container">
1
+ <%= decidim_modal id: "editCommentModal#{model.id}" do %>
2
+ <%= form_for(form_object, url: decidim_comments.comment_path(comment), method: :put, remote: true, html: { id: nil }) do |form| %>
3
+ <div data-dialog-container>
4
+ <%= icon "edit-line" %>
5
+ <h2 class="h2" id="dialog-title-budget-confirm" data-dialog-title>
6
+ <%= t("decidim.components.edit_comment_modal_form.title") %>
7
+ </h2>
8
+
9
+ <div class="form__wrapper gap-2">
10
+ <label class="text-gray-2" for="<%= form_id %>">
11
+ <%= t("decidim.components.edit_comment_modal_form.form.body.label") %>
12
+ </label>
14
13
  <%= form.text_area(
15
14
  :body,
16
15
  id: form_id,
@@ -19,11 +18,17 @@
19
18
  required: true,
20
19
  placeholder: t("decidim.components.edit_comment_modal_form.form.body.placeholder"),
21
20
  label: false,
21
+ class: "w-full rounded border min-h-[160px] border-text-gray-2",
22
22
  data: { remaining_characters: "##{form_id}-remaining-characters", input_emoji: true }
23
23
  ) %>
24
24
  </div>
25
- <button type="submit" data-close class="button button--sc"><%= t("decidim.components.edit_comment_modal_form.form.submit") %></button>
25
+ </div>
26
+ <div data-dialog-actions>
27
+ <button type="submit" data-dialog-close="editCommentModal<%= model.id %>" class="button button__sm md:button__lg button__secondary">
28
+ <%= t("decidim.components.edit_comment_modal_form.form.submit") %>
29
+ </button>
30
+
26
31
  <span id="<%= form_id %>-remaining-characters" class="remaining-character-count"></span>
27
32
  </div>
28
33
  <% end %>
29
- </div>
34
+ <% end %>
@@ -15,26 +15,38 @@ module Decidim
15
15
  # Executes the command. Broadcasts these events:
16
16
  #
17
17
  # - :ok when everything is valid.
18
- # - :invalid if the form wasn't valid and we couldn't proceed.
18
+ # - :invalid if the form was not valid and we could not proceed.
19
19
  #
20
20
  # Returns nothing.
21
21
  def call
22
22
  return broadcast(:invalid) if form.invalid?
23
23
 
24
- create_comment
24
+ with_events do
25
+ create_comment
26
+ end
25
27
 
26
28
  broadcast(:ok, comment)
27
29
  end
28
30
 
29
31
  private
30
32
 
31
- attr_reader :form, :comment
33
+ attr_reader :form, :comment, :author
34
+
35
+ def event_arguments
36
+ {
37
+ resource: comment,
38
+ extra: {
39
+ event_author: form.current_user,
40
+ locale:
41
+ }
42
+ }
43
+ end
32
44
 
33
45
  def create_comment
34
46
  parsed = Decidim::ContentProcessor.parse(form.body, current_organization: form.current_organization)
35
47
 
36
48
  params = {
37
- author: @author,
49
+ author:,
38
50
  commentable: form.commentable,
39
51
  root_commentable: root_commentable(form.commentable),
40
52
  body: { I18n.locale => parsed.rewrite },
@@ -45,7 +57,7 @@ module Decidim
45
57
 
46
58
  @comment = Decidim.traceability.create!(
47
59
  Comment,
48
- @author,
60
+ author,
49
61
  params,
50
62
  visibility: "public-only"
51
63
  )
@@ -16,7 +16,7 @@ module Decidim
16
16
  # Executes the command. Broadcasts these events:
17
17
  #
18
18
  # - :ok when everything is valid.
19
- # - :invalid if comment isn't authored by current_user.
19
+ # - :invalid if comment is not authored by current_user.
20
20
  #
21
21
  # Returns nothing.
22
22
  def call
@@ -18,13 +18,15 @@ module Decidim
18
18
  # Executes the command. Broadcasts these events:
19
19
  #
20
20
  # - :ok when everything is valid.
21
- # - :invalid if the form wasn't valid and we couldn't proceed.
21
+ # - :invalid if the form was not valid and we could not proceed.
22
22
  #
23
23
  # Returns nothing.
24
24
  def call
25
25
  return broadcast(:invalid) if form.invalid? || !comment.authored_by?(current_user)
26
26
 
27
- update_comment
27
+ with_events do
28
+ update_comment
29
+ end
28
30
 
29
31
  broadcast(:ok)
30
32
  end
@@ -33,6 +35,16 @@ module Decidim
33
35
 
34
36
  attr_reader :form, :comment, :current_user
35
37
 
38
+ def event_arguments
39
+ {
40
+ resource: comment,
41
+ extra: {
42
+ event_author: form.current_user,
43
+ locale:
44
+ }
45
+ }
46
+ end
47
+
36
48
  def update_comment
37
49
  parsed = Decidim::ContentProcessor.parse(form.body, current_organization: form.current_organization)
38
50
 
@@ -19,7 +19,7 @@ module Decidim
19
19
  # Executes the command. Broadcasts these events:
20
20
  #
21
21
  # - :ok when everything is valid.
22
- # - :invalid if the vote wasn't create
22
+ # - :invalid if the vote was not create
23
23
  #
24
24
  # Returns nothing.
25
25
  def call
@@ -16,7 +16,7 @@ module Decidim
16
16
  helper_method :root_depth, :commentable, :order, :reply?, :reload?, :root_comment
17
17
 
18
18
  def index
19
- enforce_permission_to :read, :comment, commentable: commentable
19
+ enforce_permission_to(:read, :comment, commentable:)
20
20
 
21
21
  @comments = SortedComments.for(
22
22
  commentable,
@@ -47,12 +47,13 @@ module Decidim
47
47
 
48
48
  def update
49
49
  set_comment
50
- enforce_permission_to :update, :comment, comment: comment
50
+ set_commentable
51
+ enforce_permission_to(:update, :comment, comment:)
51
52
 
52
53
  form = Decidim::Comments::CommentForm.from_params(
53
54
  params.merge(commentable: comment.commentable)
54
55
  ).with_context(
55
- current_organization: current_organization
56
+ current_organization:
56
57
  )
57
58
 
58
59
  Decidim::Comments::UpdateComment.call(comment, current_user, form) do
@@ -71,13 +72,13 @@ module Decidim
71
72
  end
72
73
 
73
74
  def create
74
- enforce_permission_to :create, :comment, commentable: commentable
75
+ enforce_permission_to(:create, :comment, commentable:)
75
76
 
76
77
  form = Decidim::Comments::CommentForm.from_params(
77
- params.merge(commentable: commentable)
78
+ params.merge(commentable:)
78
79
  ).with_context(
79
- current_organization: current_organization,
80
- current_component: current_component
80
+ current_organization:,
81
+ current_component:
81
82
  )
82
83
  Decidim::Comments::CreateComment.call(form, current_user) do
83
84
  on(:ok) do |comment|
@@ -106,7 +107,7 @@ module Decidim
106
107
  set_comment
107
108
  @commentable = @comment.commentable
108
109
 
109
- enforce_permission_to :destroy, :comment, comment: comment
110
+ enforce_permission_to(:destroy, :comment, comment:)
110
111
 
111
112
  Decidim::Comments::DeleteComment.call(comment, current_user) do
112
113
  on(:ok) do
@@ -129,7 +130,11 @@ module Decidim
129
130
  attr_reader :commentable, :comment
130
131
 
131
132
  def set_commentable
132
- @commentable = GlobalID::Locator.locate_signed(commentable_gid)
133
+ @commentable ||= if commentable_gid
134
+ GlobalID::Locator.locate_signed(commentable_gid)
135
+ elsif comment
136
+ comment.root_commentable
137
+ end
133
138
  end
134
139
 
135
140
  def set_comment
@@ -13,7 +13,7 @@ module Decidim
13
13
  def create
14
14
  raise ActionController::RoutingError, "Not Found" unless comment
15
15
 
16
- enforce_permission_to :vote, :comment, comment: comment
16
+ enforce_permission_to(:vote, :comment, comment:)
17
17
 
18
18
  Decidim::Comments::VoteComment.call(comment, current_user, weight: params[:weight].to_i) do
19
19
  on(:ok) do
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -11,8 +11,7 @@ module Decidim
11
11
 
12
12
  included do
13
13
  def resource_text(override_translation = nil)
14
- translated_body = translated_attribute(comment.body, comment.organization, override_translation)
15
- Decidim::ContentProcessor.render(sanitize_content(render_markdown(translated_body)), "div")
14
+ comment.formatted_body(override_translation)
16
15
  end
17
16
 
18
17
  def author
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -1,4 +1,4 @@
1
- # frozen-string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
4
  module Comments
@@ -26,7 +26,7 @@ module Decidim
26
26
  end
27
27
 
28
28
  def url_params
29
- { commentId: comment.id }
29
+ { commentId: comment.id, anchor: "comment_#{comment.id}" }
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ class HideAllCreatedByAuthorJob < ::Decidim::HideAllCreatedByAuthorJob
6
+ protected
7
+
8
+ def base_query
9
+ Decidim::Comments::Comment.not_hidden.where(author:)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -179,12 +179,15 @@ module Decidim
179
179
  root_commentable.can_participate?(user)
180
180
  end
181
181
 
182
- def formatted_body
183
- Decidim::ContentProcessor.render(sanitize_content_for_comment(render_markdown(translated_body)), "div")
182
+ # The override_translation argument has been added to be able to use this
183
+ # method from comment event in the resource_text method which requires
184
+ # the use of this argument in translated_attribute of body
185
+ def formatted_body(override_translation = nil)
186
+ Decidim::ContentProcessor.render(sanitize_content_for_comment(render_markdown(translated_body(override_translation))), "div")
184
187
  end
185
188
 
186
- def translated_body
187
- translated_attribute(body, organization)
189
+ def translated_body(override_translation = nil)
190
+ translated_attribute(body, organization, override_translation)
188
191
  end
189
192
 
190
193
  def delete!
@@ -6,28 +6,44 @@ module Decidim
6
6
  # to Seed those models in order to be able to use them in the development
7
7
  # app.
8
8
  class Seed
9
- # Public: adds a random amount of comments for a given resource.
10
- #
11
- # resource - the resource to add the coments to.
12
- #
13
- # Returns nothing.
14
- def self.comments_for(resource)
15
- return unless resource.accepts_new_comments?
9
+ class << self
10
+ # Adds a random amount of comments for a given resource.
11
+ #
12
+ # @param resource [Object] - the Decidim resource to add the coments to.
13
+ # examples: Decidim::Proposals::CollaborativeDraft, Decidim::Proposals::Proposal,
14
+ #
15
+ # @return nil
16
+ def comments_for(resource)
17
+ return unless resource.accepts_new_comments?
16
18
 
17
- Decidim::Comments::Comment.reset_column_information
19
+ Decidim::Comments::Comment.reset_column_information
18
20
 
19
- organization = resource.organization
21
+ rand(0..6).times do
22
+ comment = create_comment(resource)
23
+ create_comment(comment, resource) if [true, false].sample
24
+ end
25
+ end
26
+
27
+ private
20
28
 
21
- 2.times do
22
- author = Decidim::User.where(organization: organization).all.sample
29
+ # Creates a comment for a given resource.
30
+ #
31
+ # @private
32
+ #
33
+ # @param resource [Object] - the Decidim resource to add the comments to.
34
+ # @param root_commentable - the root commentable resource. It is optional, used for making nested comments.
35
+ #
36
+ # @return [Decidim::Comments::Comment]
37
+ def create_comment(resource, root_commentable = nil)
38
+ author = Decidim::User.where(organization: resource.organization).all.sample
23
39
  user_group = [true, false].sample ? Decidim::UserGroups::ManageableUserGroups.for(author).verified.sample : nil
24
40
 
25
41
  params = {
26
42
  commentable: resource,
27
- root_commentable: resource,
43
+ root_commentable: root_commentable || resource,
28
44
  body: { en: ::Faker::Lorem.sentence(word_count: 50) },
29
- author: author,
30
- user_group: user_group
45
+ author:,
46
+ user_group:
31
47
  }
32
48
 
33
49
  Decidim.traceability.create!(
@@ -0,0 +1,5 @@
1
+ // CSS
2
+ import "stylesheets/comments.scss"
3
+
4
+ // Javacript
5
+ import "src/decidim/comments/comments"
@@ -1,7 +1,6 @@
1
1
  /* eslint id-length: ["error", { "exceptions": ["$"] }] */
2
2
  /* eslint max-lines: ["error", {"max": 350, "skipBlankLines": true}] */
3
3
 
4
-
5
4
  /**
6
5
  * A plain Javascript component that handles the comments.
7
6
  *
@@ -12,11 +11,7 @@
12
11
  // This is necessary for testing purposes
13
12
  const $ = window.$;
14
13
 
15
- import Rails from "@rails/ujs";
16
-
17
- import { createCharacterCounter } from "src/decidim/input_character_counter"
18
- import ExternalLink from "src/decidim/external_link"
19
- import updateExternalDomainLinks from "src/decidim/external_domain_warning"
14
+ import changeReportFormBehavior from "src/decidim/change_report_form_behavior"
20
15
 
21
16
  export default class CommentsComponent {
22
17
  constructor($element, config) {
@@ -48,8 +43,6 @@ export default class CommentsComponent {
48
43
  $(".add-comment textarea", this.$element).prop("disabled", false);
49
44
  });
50
45
  }
51
-
52
- $(".order-by__dropdown .is-submenu-item a", this.$element).on("click.decidim-comments", () => this._onInitOrder());
53
46
  }
54
47
  }
55
48
 
@@ -63,9 +56,8 @@ export default class CommentsComponent {
63
56
  this.mounted = false;
64
57
  this._stopPolling();
65
58
 
66
- $(".add-comment .opinion-toggle .button", this.$element).off("click.decidim-comments");
59
+ $(".add-comment .opinion-toggle button", this.$element).off("click.decidim-comments");
67
60
  $(".add-comment textarea", this.$element).off("input.decidim-comments");
68
- $(".order-by__dropdown .is-submenu-item a", this.$element).off("click.decidim-comments");
69
61
  $(".add-comment form", this.$element).off("submit.decidim-comments");
70
62
  $(".add-comment textarea", this.$element).each((_i, el) => el.removeEventListener("emoji.added", this._onTextInput));
71
63
  }
@@ -102,7 +94,7 @@ export default class CommentsComponent {
102
94
  const $comment = $(replyHtml);
103
95
  const $replies = $(`#comment-${commentId}-replies`);
104
96
  this._addComment($replies, $comment);
105
- $replies.siblings(".comment__additionalreply").removeClass("hide");
97
+ $replies.addClass("comment-reply");
106
98
  this._finalizeCommentCreation($parent, fromCurrentUser);
107
99
  }
108
100
 
@@ -125,7 +117,7 @@ export default class CommentsComponent {
125
117
  $(".add-comment", $parent).each((_i, el) => {
126
118
  const $add = $(el);
127
119
  const $form = $("form", $add);
128
- const $opinionButtons = $(".opinion-toggle .button", $add);
120
+ const $opinionButtons = $(".opinion-toggle button", $add);
129
121
  const $text = $("textarea", $form);
130
122
 
131
123
  $opinionButtons.on("click.decidim-comments", this._onToggleOpinion);
@@ -140,6 +132,8 @@ export default class CommentsComponent {
140
132
  this._stopPolling();
141
133
  });
142
134
 
135
+ document.querySelectorAll(".new_report").forEach((container) => changeReportFormBehavior(container))
136
+
143
137
  if ($text.length && $text.get(0) !== null) {
144
138
  // Attach event to the DOM node, instead of the jQuery object
145
139
  $text.get(0).addEventListener("emoji.added", this._onTextInput);
@@ -164,14 +158,9 @@ export default class CommentsComponent {
164
158
  this.lastCommentId = parseInt($comment.data("comment-id"), 10);
165
159
 
166
160
  $target.append($container);
167
- $container.foundation();
161
+
168
162
  this._initializeComments($container);
169
- createCharacterCounter($(".add-comment textarea", $container));
170
- $container.find('a[target="_blank"]').each((_i, elem) => {
171
- const $link = $(elem);
172
- $link.data("external-link", new ExternalLink($link));
173
- });
174
- updateExternalDomainLinks($container)
163
+ document.dispatchEvent(new CustomEvent("comments:loaded", { detail: {commentsIds: [this.lastCommentId] }}));
175
164
  }
176
165
 
177
166
  /**
@@ -185,16 +174,18 @@ export default class CommentsComponent {
185
174
  */
186
175
  _finalizeCommentCreation($parent, fromCurrentUser) {
187
176
  if (fromCurrentUser) {
188
- const $add = $("> .add-comment", $parent);
189
- const $text = $("textarea", $add);
190
- const characterCounter = $text.data("remaining-characters-counter");
191
- $text.val("");
192
- if (characterCounter) {
193
- characterCounter.updateStatus();
194
- }
195
- if (!$add.parent().is(".comments")) {
196
- $add.addClass("hide");
197
- }
177
+ const $add = $(".add-comment", $parent);
178
+ $("textarea", $add).each((_i, text) => {
179
+ const $text = $(text);
180
+ // Reset textarea content
181
+ $text.val("")
182
+ // Update characterCounter component
183
+ const characterCounter = $text.data("remaining-characters-counter");
184
+ if (characterCounter) {
185
+ characterCounter.handleInput();
186
+ characterCounter.updateStatus();
187
+ }
188
+ })
198
189
  }
199
190
 
200
191
  // Restart the polling
@@ -230,7 +221,7 @@ export default class CommentsComponent {
230
221
  "commentable_gid": this.commentableGid,
231
222
  "root_depth": this.rootDepth,
232
223
  "order": this.order,
233
- "after": this.lastCommentId,
224
+ // From here, the rest of properties are optional
234
225
  ...(this.toggleTranslations && { "toggle_translations": this.toggleTranslations }),
235
226
  ...(this.lastCommentId && { "after": this.lastCommentId })
236
227
  }),
@@ -260,9 +251,9 @@ export default class CommentsComponent {
260
251
  * @returns {Void} - Returns nothing
261
252
  */
262
253
  _setLoading() {
263
- const $container = $("> .comments-container", this.$element);
264
- $("> .comments", $container).addClass("hide");
265
- $("> .loading-comments", $container).removeClass("hide");
254
+ const $container = $("> #comments", this.$element);
255
+ $("> .comments", $container).addClass("hidden");
256
+ $("> .loading-comments", $container).removeClass("hidden");
266
257
  }
267
258
 
268
259
  /**
@@ -283,13 +274,13 @@ export default class CommentsComponent {
283
274
  */
284
275
  _onToggleOpinion(ev) {
285
276
  let $btn = $(ev.target);
286
- if (!$btn.is(".button")) {
287
- $btn = $btn.parents(".button");
277
+ if (!$btn.is("button")) {
278
+ $btn = $btn.parents("button");
288
279
  }
289
280
 
290
281
  const $add = $btn.closest(".add-comment");
291
282
  const $form = $("form", $add);
292
- const $opinionButtons = $(".opinion-toggle .button", $add);
283
+ const $opinionButtons = $(".opinion-toggle button", $add);
293
284
  const $selectedState = $(".opinion-toggle .selected-state", $add);
294
285
  const $alignment = $(".alignment-input", $form);
295
286