decidim-comments 0.24.3 → 0.25.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -20
- data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
- data/app/cells/decidim/comments/comment/actions.erb +1 -1
- data/app/cells/decidim/comments/comment/deletion_data.erb +1 -0
- data/app/cells/decidim/comments/comment/show.erb +30 -21
- data/app/cells/decidim/comments/comment/utilities.erb +40 -12
- data/app/cells/decidim/comments/comment/votes.erb +6 -6
- data/app/cells/decidim/comments/comment_cell.rb +29 -0
- data/app/cells/decidim/comments/comment_form/show.erb +1 -1
- data/app/cells/decidim/comments/comments/add_comment.erb +10 -6
- data/app/cells/decidim/comments/comments/order_control.erb +4 -5
- data/app/cells/decidim/comments/comments/show.erb +2 -4
- data/app/cells/decidim/comments/comments/user_comments_blocked_warning.erb +5 -1
- data/app/cells/decidim/comments/comments_cell.rb +24 -2
- data/app/cells/decidim/comments/edit_comment_modal_form/show.erb +29 -0
- data/app/cells/decidim/comments/edit_comment_modal_form_cell.rb +53 -0
- data/app/commands/decidim/comments/create_comment.rb +2 -1
- data/app/commands/decidim/comments/delete_comment.rb +46 -0
- data/app/commands/decidim/comments/update_comment.rb +62 -0
- data/app/controllers/decidim/comments/comments_controller.rb +63 -6
- data/app/events/decidim/comments/comment_voted_event.rb +9 -0
- data/app/models/decidim/comments/comment.rb +24 -1
- data/app/packs/src/decidim/comments/comments.component.js +300 -0
- data/app/{assets/javascripts → packs/src}/decidim/comments/comments.component.test.js +116 -26
- data/app/packs/src/decidim/comments/comments.component_for_testing.js +8 -0
- data/app/packs/src/decidim/comments/comments.js +1 -0
- data/app/permissions/decidim/comments/permissions.rb +10 -1
- data/app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb +1 -1
- data/app/queries/decidim/comments/metrics/comments_metric_manage.rb +1 -1
- data/app/queries/decidim/comments/sorted_comments.rb +8 -6
- data/app/views/decidim/comments/comments/_delete.html.erb +5 -0
- data/app/views/decidim/comments/comments/_edited_comment.html.erb +1 -0
- data/app/views/decidim/comments/comments/create.js.erb +4 -2
- data/app/views/decidim/comments/comments/delete.js.erb +17 -0
- data/app/views/decidim/comments/comments/deletion_error.js.erb +1 -0
- data/app/views/decidim/comments/comments/reload.js.erb +2 -0
- data/app/views/decidim/comments/comments/update.js.erb +8 -0
- data/app/views/decidim/comments/comments/update_error.js.erb +1 -0
- data/config/assets.rb +5 -0
- data/config/locales/ar.yml +0 -1
- data/config/locales/ca.yml +7 -1
- data/config/locales/cs.yml +25 -1
- data/config/locales/de.yml +7 -1
- data/config/locales/el.yml +0 -1
- data/config/locales/en.yml +25 -1
- data/config/locales/es-MX.yml +7 -1
- data/config/locales/es-PY.yml +7 -1
- data/config/locales/es.yml +7 -1
- data/config/locales/fi-plain.yml +25 -1
- data/config/locales/fi.yml +25 -1
- data/config/locales/fr-CA.yml +25 -1
- data/config/locales/fr-LU.yml +162 -0
- data/config/locales/fr.yml +25 -1
- data/config/locales/gl.yml +25 -1
- data/config/locales/hu.yml +0 -1
- data/config/locales/it.yml +38 -1
- data/config/locales/ja.yml +35 -1
- data/config/locales/lb-LU.yml +1 -0
- data/config/locales/lv.yml +0 -1
- data/config/locales/nl.yml +27 -2
- data/config/locales/no.yml +0 -1
- data/config/locales/pl.yml +7 -1
- data/config/locales/pt-BR.yml +61 -0
- data/config/locales/pt.yml +0 -1
- data/config/locales/ro-RO.yml +25 -1
- data/config/locales/sk.yml +0 -1
- data/config/locales/sr-CS.yml +0 -1
- data/config/locales/sv.yml +25 -1
- data/config/locales/tr-TR.yml +0 -1
- data/config/locales/zh-CN.yml +0 -1
- data/db/migrate/20200706123136_make_comments_handle_i18n.rb +1 -1
- data/db/migrate/20210402124534_add_participatory_process_to_comments.rb +12 -0
- data/db/migrate/20210529095942_add_deleted_at_column_to_comments.rb +7 -0
- data/lib/decidim/comments/commentable.rb +6 -1
- data/lib/decidim/comments/commentable_with_component.rb +33 -0
- data/lib/decidim/comments/engine.rb +1 -9
- data/lib/decidim/comments/test/factories.rb +1 -0
- data/lib/decidim/comments/version.rb +1 -1
- data/lib/decidim/comments.rb +1 -0
- data/lib/tasks/decidim_comments.rake +15 -0
- metadata +32 -29
- data/app/assets/config/decidim_comments_manifest.js +0 -1
- data/app/assets/javascripts/decidim/comments/comments.component.js.es6 +0 -292
- data/app/assets/javascripts/decidim/comments/comments.js.erb +0 -10
- data/config/locales/ja-JP.yml +0 -120
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Comments
|
7
|
+
# Commentable overriding some methods to include settings and
|
8
|
+
# authorizations given by a component the resource belongs to
|
9
|
+
module CommentableWithComponent
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Decidim::Comments::Commentable
|
12
|
+
|
13
|
+
included do
|
14
|
+
# Public: Overrides the `commentable?` Commentable concern method.
|
15
|
+
def commentable?
|
16
|
+
component.settings.comments_enabled?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Overrides the `accepts_new_comments?` Commentable concern method.
|
20
|
+
def accepts_new_comments?
|
21
|
+
commentable? && !component.current_settings.comments_blocked
|
22
|
+
end
|
23
|
+
|
24
|
+
# Public: Whether the object can have new comments or not.
|
25
|
+
def user_allowed_to_comment?(user)
|
26
|
+
return unless can_participate?(user)
|
27
|
+
|
28
|
+
ActionAuthorizer.new(user, "comment", component, self).authorize.ok?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -4,11 +4,7 @@ require "rails"
|
|
4
4
|
require "active_support/all"
|
5
5
|
|
6
6
|
require "decidim/core"
|
7
|
-
require "jquery-rails"
|
8
|
-
require "sassc-rails"
|
9
|
-
require "foundation-rails"
|
10
7
|
require "foundation_rails_helper"
|
11
|
-
require "autoprefixer-rails"
|
12
8
|
|
13
9
|
require "decidim/comments/query_extensions"
|
14
10
|
require "decidim/comments/mutation_extensions"
|
@@ -20,15 +16,11 @@ module Decidim
|
|
20
16
|
isolate_namespace Decidim::Comments
|
21
17
|
|
22
18
|
routes do
|
23
|
-
resources :comments,
|
19
|
+
resources :comments, except: [:new, :edit] do
|
24
20
|
resources :votes, only: [:create]
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
28
|
-
initializer "decidim_comments.assets" do |app|
|
29
|
-
app.config.assets.precompile += %w(decidim_comments_manifest.js)
|
30
|
-
end
|
31
|
-
|
32
24
|
initializer "decidim_comments.query_extensions" do
|
33
25
|
Decidim::Api::QueryType.include QueryExtensions
|
34
26
|
end
|
@@ -8,6 +8,7 @@ FactoryBot.define do
|
|
8
8
|
commentable { build(:dummy_resource) }
|
9
9
|
root_commentable { commentable }
|
10
10
|
body { Decidim::Faker::Localized.paragraph }
|
11
|
+
participatory_space { commentable.try(:participatory_space) }
|
11
12
|
|
12
13
|
after(:build) do |comment, evaluator|
|
13
14
|
comment.body = if evaluator.body.is_a?(String)
|
data/lib/decidim/comments.rb
CHANGED
@@ -12,6 +12,7 @@ module Decidim
|
|
12
12
|
module Comments
|
13
13
|
autoload :CommentsHelper, "decidim/comments/comments_helper"
|
14
14
|
autoload :Commentable, "decidim/comments/commentable"
|
15
|
+
autoload :CommentableWithComponent, "decidim/comments/commentable_with_component"
|
15
16
|
autoload :CommentSerializer, "decidim/comments/comment_serializer"
|
16
17
|
autoload :CommentVoteSerializer, "decidim/comments/comment_vote_serializer"
|
17
18
|
autoload :Export, "decidim/comments/export"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :decidim_comments do
|
4
|
+
desc "Adds participatory_process_id to comments if they are associated with a participatory process"
|
5
|
+
task update_participatory_process_in_comments: :environment do
|
6
|
+
Decidim::Comments::Comment.find_each do |c|
|
7
|
+
c.participatory_space = if c.root_commentable.is_a?(Decidim::Participable)
|
8
|
+
c.root_commentable
|
9
|
+
else
|
10
|
+
c.commentable.try(:participatory_space)
|
11
|
+
end
|
12
|
+
c.save(validate: false)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decidim-comments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.25.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep Jaume Rey Peroy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-09-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: decidim-core
|
@@ -18,28 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.25.0.rc4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - '='
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: jquery-rails
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - "~>"
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '4.4'
|
36
|
-
type: :runtime
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '4.4'
|
28
|
+
version: 0.25.0.rc4
|
43
29
|
- !ruby/object:Gem::Dependency
|
44
30
|
name: redcarpet
|
45
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,28 +52,28 @@ dependencies:
|
|
66
52
|
requirements:
|
67
53
|
- - '='
|
68
54
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
55
|
+
version: 0.25.0.rc4
|
70
56
|
type: :development
|
71
57
|
prerelease: false
|
72
58
|
version_requirements: !ruby/object:Gem::Requirement
|
73
59
|
requirements:
|
74
60
|
- - '='
|
75
61
|
- !ruby/object:Gem::Version
|
76
|
-
version: 0.
|
62
|
+
version: 0.25.0.rc4
|
77
63
|
- !ruby/object:Gem::Dependency
|
78
64
|
name: decidim-dev
|
79
65
|
requirement: !ruby/object:Gem::Requirement
|
80
66
|
requirements:
|
81
67
|
- - '='
|
82
68
|
- !ruby/object:Gem::Version
|
83
|
-
version: 0.
|
69
|
+
version: 0.25.0.rc4
|
84
70
|
type: :development
|
85
71
|
prerelease: false
|
86
72
|
version_requirements: !ruby/object:Gem::Requirement
|
87
73
|
requirements:
|
88
74
|
- - '='
|
89
75
|
- !ruby/object:Gem::Version
|
90
|
-
version: 0.
|
76
|
+
version: 0.25.0.rc4
|
91
77
|
description: Pluggable comments system for some components.
|
92
78
|
email:
|
93
79
|
- josepjaume@gmail.com
|
@@ -99,14 +85,11 @@ extra_rdoc_files: []
|
|
99
85
|
files:
|
100
86
|
- README.md
|
101
87
|
- Rakefile
|
102
|
-
- app/assets/config/decidim_comments_manifest.js
|
103
88
|
- app/assets/javascripts/decidim/comments/bundle.js.map
|
104
|
-
- app/assets/javascripts/decidim/comments/comments.component.js.es6
|
105
|
-
- app/assets/javascripts/decidim/comments/comments.component.test.js
|
106
|
-
- app/assets/javascripts/decidim/comments/comments.js.erb
|
107
89
|
- app/cells/decidim/comments/comment/actions.erb
|
108
90
|
- app/cells/decidim/comments/comment/alignment_badge.erb
|
109
91
|
- app/cells/decidim/comments/comment/author.erb
|
92
|
+
- app/cells/decidim/comments/comment/deletion_data.erb
|
110
93
|
- app/cells/decidim/comments/comment/show.erb
|
111
94
|
- app/cells/decidim/comments/comment/utilities.erb
|
112
95
|
- app/cells/decidim/comments/comment/votes.erb
|
@@ -129,7 +112,11 @@ files:
|
|
129
112
|
- app/cells/decidim/comments/comments/single_comment_warning.erb
|
130
113
|
- app/cells/decidim/comments/comments/user_comments_blocked_warning.erb
|
131
114
|
- app/cells/decidim/comments/comments_cell.rb
|
115
|
+
- app/cells/decidim/comments/edit_comment_modal_form/show.erb
|
116
|
+
- app/cells/decidim/comments/edit_comment_modal_form_cell.rb
|
132
117
|
- app/commands/decidim/comments/create_comment.rb
|
118
|
+
- app/commands/decidim/comments/delete_comment.rb
|
119
|
+
- app/commands/decidim/comments/update_comment.rb
|
133
120
|
- app/commands/decidim/comments/vote_comment.rb
|
134
121
|
- app/controllers/decidim/comments/application_controller.rb
|
135
122
|
- app/controllers/decidim/comments/comments_controller.rb
|
@@ -150,6 +137,10 @@ files:
|
|
150
137
|
- app/models/decidim/comments/comment.rb
|
151
138
|
- app/models/decidim/comments/comment_vote.rb
|
152
139
|
- app/models/decidim/comments/seed.rb
|
140
|
+
- app/packs/src/decidim/comments/comments.component.js
|
141
|
+
- app/packs/src/decidim/comments/comments.component.test.js
|
142
|
+
- app/packs/src/decidim/comments/comments.component_for_testing.js
|
143
|
+
- app/packs/src/decidim/comments/comments.js
|
153
144
|
- app/permissions/decidim/comments/permissions.rb
|
154
145
|
- app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb
|
155
146
|
- app/queries/decidim/comments/metrics/comments_metric_manage.rb
|
@@ -160,12 +151,19 @@ files:
|
|
160
151
|
- app/services/decidim/comments/new_comment_notification_creator.rb
|
161
152
|
- app/views/decidim/comments/comments/_comment.html.erb
|
162
153
|
- app/views/decidim/comments/comments/_comments.html.erb
|
154
|
+
- app/views/decidim/comments/comments/_delete.html.erb
|
155
|
+
- app/views/decidim/comments/comments/_edited_comment.html.erb
|
163
156
|
- app/views/decidim/comments/comments/create.js.erb
|
157
|
+
- app/views/decidim/comments/comments/delete.js.erb
|
158
|
+
- app/views/decidim/comments/comments/deletion_error.js.erb
|
164
159
|
- app/views/decidim/comments/comments/error.js.erb
|
165
160
|
- app/views/decidim/comments/comments/index.js.erb
|
166
161
|
- app/views/decidim/comments/comments/reload.js.erb
|
162
|
+
- app/views/decidim/comments/comments/update.js.erb
|
163
|
+
- app/views/decidim/comments/comments/update_error.js.erb
|
167
164
|
- app/views/decidim/comments/votes/create.js.erb
|
168
165
|
- app/views/decidim/comments/votes/error.js.erb
|
166
|
+
- config/assets.rb
|
169
167
|
- config/locales/am-ET.yml
|
170
168
|
- config/locales/ar-SA.yml
|
171
169
|
- config/locales/ar.yml
|
@@ -192,6 +190,7 @@ files:
|
|
192
190
|
- config/locales/fi-plain.yml
|
193
191
|
- config/locales/fi.yml
|
194
192
|
- config/locales/fr-CA.yml
|
193
|
+
- config/locales/fr-LU.yml
|
195
194
|
- config/locales/fr.yml
|
196
195
|
- config/locales/ga-IE.yml
|
197
196
|
- config/locales/gl.yml
|
@@ -202,10 +201,10 @@ files:
|
|
202
201
|
- config/locales/is-IS.yml
|
203
202
|
- config/locales/is.yml
|
204
203
|
- config/locales/it.yml
|
205
|
-
- config/locales/ja-JP.yml
|
206
204
|
- config/locales/ja.yml
|
207
205
|
- config/locales/ko-KR.yml
|
208
206
|
- config/locales/ko.yml
|
207
|
+
- config/locales/lb-LU.yml
|
209
208
|
- config/locales/lt-LT.yml
|
210
209
|
- config/locales/lt.yml
|
211
210
|
- config/locales/lv.yml
|
@@ -248,6 +247,8 @@ files:
|
|
248
247
|
- db/migrate/20200320105911_index_foreign_keys_in_decidim_comments_comments.rb
|
249
248
|
- db/migrate/20200706123136_make_comments_handle_i18n.rb
|
250
249
|
- db/migrate/20200828101910_add_commentable_counter_cache_to_comments.rb
|
250
|
+
- db/migrate/20210402124534_add_participatory_process_to_comments.rb
|
251
|
+
- db/migrate/20210529095942_add_deleted_at_column_to_comments.rb
|
251
252
|
- db/seeds.rb
|
252
253
|
- lib/decidim/api/add_comment_type.rb
|
253
254
|
- lib/decidim/api/comment_mutation_type.rb
|
@@ -262,6 +263,7 @@ files:
|
|
262
263
|
- lib/decidim/comments/comment_serializer.rb
|
263
264
|
- lib/decidim/comments/comment_vote_serializer.rb
|
264
265
|
- lib/decidim/comments/commentable.rb
|
266
|
+
- lib/decidim/comments/commentable_with_component.rb
|
265
267
|
- lib/decidim/comments/comments_helper.rb
|
266
268
|
- lib/decidim/comments/engine.rb
|
267
269
|
- lib/decidim/comments/export.rb
|
@@ -274,6 +276,7 @@ files:
|
|
274
276
|
- lib/decidim/comments/test/shared_examples/comment_voted_event.rb
|
275
277
|
- lib/decidim/comments/test/shared_examples/create_comment_context.rb
|
276
278
|
- lib/decidim/comments/version.rb
|
279
|
+
- lib/tasks/decidim_comments.rake
|
277
280
|
homepage: https://github.com/decidim/decidim
|
278
281
|
licenses:
|
279
282
|
- AGPL-3.0
|
@@ -289,9 +292,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
289
292
|
version: '2.7'
|
290
293
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
291
294
|
requirements:
|
292
|
-
- - "
|
295
|
+
- - ">"
|
293
296
|
- !ruby/object:Gem::Version
|
294
|
-
version:
|
297
|
+
version: 1.3.1
|
295
298
|
requirements: []
|
296
299
|
rubygems_version: 3.1.2
|
297
300
|
signing_key:
|
@@ -1 +0,0 @@
|
|
1
|
-
//= link decidim/comments/comments.js
|
@@ -1,292 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* A plain Javascript component that handles the comments.
|
3
|
-
*
|
4
|
-
* @class
|
5
|
-
* @augments Component
|
6
|
-
*/
|
7
|
-
((exports) => {
|
8
|
-
const $ = exports.$; // eslint-disable-line
|
9
|
-
|
10
|
-
class CommentsComponent {
|
11
|
-
constructor($element, config) {
|
12
|
-
this.$element = $element;
|
13
|
-
this.commentableGid = config.commentableGid;
|
14
|
-
this.commentsUrl = config.commentsUrl;
|
15
|
-
this.rootDepth = config.rootDepth;
|
16
|
-
this.order = config.order;
|
17
|
-
this.lastCommentId = config.lastCommentId;
|
18
|
-
this.pollingInterval = config.pollingInterval || 15000;
|
19
|
-
this.id = this.$element.attr("id") || this._getUID();
|
20
|
-
this.mounted = false;
|
21
|
-
}
|
22
|
-
|
23
|
-
/**
|
24
|
-
* Handles the logic for mounting the component
|
25
|
-
* @public
|
26
|
-
* @returns {Void} - Returns nothing
|
27
|
-
*/
|
28
|
-
mountComponent() {
|
29
|
-
if (this.$element.length > 0 && !this.mounted) {
|
30
|
-
this.mounted = true;
|
31
|
-
this._initializeComments(this.$element);
|
32
|
-
|
33
|
-
$(".order-by__dropdown .is-submenu-item a", this.$element).on(
|
34
|
-
"click.decidim-comments",
|
35
|
-
() => {
|
36
|
-
this._onInitOrder();
|
37
|
-
}
|
38
|
-
);
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Handles the logic for unmounting the component
|
44
|
-
* @public
|
45
|
-
* @returns {Void} - Returns nothing
|
46
|
-
*/
|
47
|
-
unmountComponent() {
|
48
|
-
if (this.mounted) {
|
49
|
-
this.mounted = false;
|
50
|
-
this._stopPolling();
|
51
|
-
|
52
|
-
$(".add-comment .opinion-toggle .button", this.$element).off("click.decidim-comments");
|
53
|
-
$(".add-comment textarea", this.$element).off("input.decidim-comments");
|
54
|
-
$(".order-by__dropdown .is-submenu-item a", this.$element).off("click.decidim-comments");
|
55
|
-
$(".add-comment form", this.$element).off("submit.decidim-comments");
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Adds a new thread to the comments section.
|
61
|
-
* @public
|
62
|
-
* @param {String} threadHtml - The HTML content for the thread.
|
63
|
-
* @returns {Void} - Returns nothing
|
64
|
-
*/
|
65
|
-
addThread(threadHtml) {
|
66
|
-
const $parent = $(".comments:first", this.$element);
|
67
|
-
const $comment = $(threadHtml);
|
68
|
-
const $threads = $(".comment-threads", this.$element);
|
69
|
-
this._addComment($threads, $comment);
|
70
|
-
this._finalizeCommentCreation($parent);
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Adds a new reply to an existing comment.
|
75
|
-
* @public
|
76
|
-
* @param {Number} commentId - The ID of the comment for which to add the
|
77
|
-
* reply to.
|
78
|
-
* @param {String} replyHtml - The HTML content for the reply.
|
79
|
-
* @returns {Void} - Returns nothing
|
80
|
-
*/
|
81
|
-
addReply(commentId, replyHtml) {
|
82
|
-
const $parent = $(`#comment_${commentId}`);
|
83
|
-
const $comment = $(replyHtml);
|
84
|
-
const $replies = $(`#comment-${commentId}-replies`);
|
85
|
-
this._addComment($replies, $comment);
|
86
|
-
$replies.siblings(".comment__additionalreply").removeClass("hide");
|
87
|
-
this._finalizeCommentCreation($parent);
|
88
|
-
}
|
89
|
-
|
90
|
-
/**
|
91
|
-
* Generates a unique identifier for the form.
|
92
|
-
* @private
|
93
|
-
* @returns {String} - Returns a unique identifier
|
94
|
-
*/
|
95
|
-
_getUID() {
|
96
|
-
return `comments-${new Date().setUTCMilliseconds()}-${Math.floor(Math.random() * 10000000)}`;
|
97
|
-
}
|
98
|
-
|
99
|
-
/**
|
100
|
-
* Initializes the comments for the given parent element.
|
101
|
-
* @private
|
102
|
-
* @param {jQuery} $parent The parent element to initialize.
|
103
|
-
* @returns {Void} - Returns nothing
|
104
|
-
*/
|
105
|
-
_initializeComments($parent) {
|
106
|
-
$(".add-comment", $parent).each((_i, el) => {
|
107
|
-
const $add = $(el);
|
108
|
-
const $form = $("form", $add);
|
109
|
-
const $opinionButtons = $(".opinion-toggle .button", $add);
|
110
|
-
const $text = $("textarea", $form);
|
111
|
-
|
112
|
-
$opinionButtons.on("click.decidim-comments", this._onToggleOpinion);
|
113
|
-
$text.on("input.decidim-comments", this._onTextInput);
|
114
|
-
|
115
|
-
$(document).trigger("attach-mentions-element", [$text.get(0)]);
|
116
|
-
|
117
|
-
$form.on("submit.decidim-comments", () => {
|
118
|
-
const $submit = $("button[type='submit']", $form);
|
119
|
-
|
120
|
-
$submit.attr("disabled", "disabled");
|
121
|
-
this._stopPolling();
|
122
|
-
});
|
123
|
-
});
|
124
|
-
|
125
|
-
this._pollComments();
|
126
|
-
}
|
127
|
-
|
128
|
-
/**
|
129
|
-
* Adds the given comment element to the given target element and
|
130
|
-
* initializes it.
|
131
|
-
* @private
|
132
|
-
* @param {jQuery} $target - The target element to add the comment to.
|
133
|
-
* @param {jQuery} $container - The comment container element to add.
|
134
|
-
* @returns {Void} - Returns nothing
|
135
|
-
*/
|
136
|
-
_addComment($target, $container) {
|
137
|
-
let $comment = $(".comment", $container);
|
138
|
-
if ($comment.length < 1) {
|
139
|
-
// In case of a reply
|
140
|
-
$comment = $container;
|
141
|
-
}
|
142
|
-
this.lastCommentId = parseInt($comment.data("comment-id"), 10);
|
143
|
-
|
144
|
-
$target.append($container);
|
145
|
-
$container.foundation();
|
146
|
-
this._initializeComments($container);
|
147
|
-
if (exports.Decidim.createCharacterCounter) {
|
148
|
-
exports.Decidim.createCharacterCounter($(".add-comment textarea", $container));
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
/**
|
153
|
-
* Finalizes the new comment creation after the comment adding finishes
|
154
|
-
* successfully.
|
155
|
-
* @private
|
156
|
-
* @param {jQuery} $parent - The parent comment element to finalize.
|
157
|
-
* @returns {Void} - Returns nothing
|
158
|
-
*/
|
159
|
-
_finalizeCommentCreation($parent) {
|
160
|
-
const $add = $("> .add-comment", $parent);
|
161
|
-
const $text = $("textarea", $add);
|
162
|
-
const characterCounter = $text.data("remaining-characters-counter");
|
163
|
-
$text.val("");
|
164
|
-
if (characterCounter) {
|
165
|
-
characterCounter.updateStatus();
|
166
|
-
}
|
167
|
-
if (!$add.parent().is(".comments")) {
|
168
|
-
$add.addClass("hide");
|
169
|
-
}
|
170
|
-
|
171
|
-
// Restart the polling
|
172
|
-
this._pollComments();
|
173
|
-
}
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Sets a timeout to poll new comments.
|
177
|
-
* @private
|
178
|
-
* @returns {Void} - Returns nothing
|
179
|
-
*/
|
180
|
-
_pollComments() {
|
181
|
-
this._stopPolling();
|
182
|
-
|
183
|
-
this.pollTimeout = setTimeout(() => {
|
184
|
-
$.ajax({
|
185
|
-
url: this.commentsUrl,
|
186
|
-
method: "GET",
|
187
|
-
contentType: "application/javascript",
|
188
|
-
data: {
|
189
|
-
"commentable_gid": this.commentableGid,
|
190
|
-
"root_depth": this.rootDepth,
|
191
|
-
order: this.order,
|
192
|
-
after: this.lastCommentId
|
193
|
-
}
|
194
|
-
}).done(() => {
|
195
|
-
this._pollComments();
|
196
|
-
});
|
197
|
-
}, this.pollingInterval);
|
198
|
-
}
|
199
|
-
|
200
|
-
/**
|
201
|
-
* Stops polling for new comments.
|
202
|
-
* @private
|
203
|
-
* @returns {Void} - Returns nothing
|
204
|
-
*/
|
205
|
-
_stopPolling() {
|
206
|
-
if (this.pollTimeout) {
|
207
|
-
clearTimeout(this.pollTimeout);
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
/**
|
212
|
-
* Sets the loading comments element visible in the view.
|
213
|
-
* @private
|
214
|
-
* @returns {Void} - Returns nothing
|
215
|
-
*/
|
216
|
-
_setLoading() {
|
217
|
-
const $container = $("> .comments-container", this.$element);
|
218
|
-
$("> .comments", $container).addClass("hide");
|
219
|
-
$("> .loading-comments", $container).removeClass("hide");
|
220
|
-
}
|
221
|
-
|
222
|
-
/**
|
223
|
-
* Event listener for the ordering links.
|
224
|
-
* @private
|
225
|
-
* @returns {Void} - Returns nothing
|
226
|
-
*/
|
227
|
-
_onInitOrder() {
|
228
|
-
this._stopPolling();
|
229
|
-
this._setLoading();
|
230
|
-
}
|
231
|
-
|
232
|
-
/**
|
233
|
-
* Event listener for the opinion toggle buttons.
|
234
|
-
* @private
|
235
|
-
* @param {Event} ev - The event object.
|
236
|
-
* @returns {Void} - Returns nothing
|
237
|
-
*/
|
238
|
-
_onToggleOpinion(ev) {
|
239
|
-
let $btn = $(ev.target);
|
240
|
-
if (!$btn.is(".button")) {
|
241
|
-
$btn = $btn.parents(".button");
|
242
|
-
}
|
243
|
-
|
244
|
-
const $add = $btn.closest(".add-comment");
|
245
|
-
const $form = $("form", $add);
|
246
|
-
const $opinionButtons = $(".opinion-toggle .button", $add);
|
247
|
-
const $alignment = $(".alignment-input", $form);
|
248
|
-
|
249
|
-
$opinionButtons.removeClass("is-active");
|
250
|
-
$btn.addClass("is-active");
|
251
|
-
|
252
|
-
if ($btn.is(".opinion-toggle--ok")) {
|
253
|
-
$alignment.val(1);
|
254
|
-
} else if ($btn.is(".opinion-toggle--meh")) {
|
255
|
-
$alignment.val(0);
|
256
|
-
} else if ($btn.is(".opinion-toggle--ko")) {
|
257
|
-
$alignment.val(-1);
|
258
|
-
}
|
259
|
-
}
|
260
|
-
|
261
|
-
/**
|
262
|
-
* Event listener for the comment field text input.
|
263
|
-
* @private
|
264
|
-
* @param {Event} ev - The event object.
|
265
|
-
* @returns {Void} - Returns nothing
|
266
|
-
*/
|
267
|
-
_onTextInput(ev) {
|
268
|
-
const $text = $(ev.target);
|
269
|
-
const $add = $text.closest(".add-comment");
|
270
|
-
const $form = $("form", $add);
|
271
|
-
const $submit = $("button[type='submit']", $form);
|
272
|
-
|
273
|
-
if ($text.val().length > 0) {
|
274
|
-
$submit.removeAttr("disabled");
|
275
|
-
} else {
|
276
|
-
$submit.attr("disabled", "disabled");
|
277
|
-
}
|
278
|
-
}
|
279
|
-
}
|
280
|
-
|
281
|
-
exports.Decidim = exports.Decidim || {};
|
282
|
-
exports.Decidim.CommentsComponent = CommentsComponent;
|
283
|
-
|
284
|
-
$(() => {
|
285
|
-
$("[data-decidim-comments]").each((_i, el) => {
|
286
|
-
const $el = $(el);
|
287
|
-
const comments = new CommentsComponent($el, $el.data("decidim-comments"));
|
288
|
-
comments.mountComponent();
|
289
|
-
$(el).data("comments", comments);
|
290
|
-
});
|
291
|
-
});
|
292
|
-
})(window);
|