decidim-comments 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/decidim/comments/bundle.js +15 -15
- data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
- data/app/commands/decidim/comments/create_comment.rb +2 -1
- data/app/forms/decidim/comments/comment_form.rb +1 -0
- data/app/frontend/application/apollo_client.js +1 -1
- data/app/frontend/application/application.component.jsx +1 -1
- data/app/frontend/comments/add_comment_form.component.jsx +76 -20
- data/app/frontend/comments/add_comment_form.component.test.jsx +77 -22
- data/app/frontend/comments/add_comment_form.fragment.graphql +6 -0
- data/app/frontend/comments/add_comment_form.mutation.graphql +2 -2
- data/app/frontend/comments/comment.component.jsx +15 -15
- data/app/frontend/comments/comment.component.test.jsx +42 -41
- data/app/frontend/comments/comment_order_selector.component.jsx +1 -1
- data/app/frontend/comments/comment_thread.component.jsx +7 -7
- data/app/frontend/comments/comment_thread.component.test.jsx +21 -19
- data/app/frontend/comments/comments.component.jsx +21 -17
- data/app/frontend/comments/comments.component.test.jsx +47 -32
- data/app/frontend/comments/comments.query.graphql +6 -3
- data/app/frontend/comments/down_vote_button.component.jsx +21 -10
- data/app/frontend/comments/up_vote_button.component.jsx +23 -12
- data/app/frontend/comments/vote_button.component.jsx +15 -7
- data/app/frontend/comments/vote_button_component.test.jsx +7 -2
- data/app/frontend/entry.js +1 -8
- data/app/frontend/support/generate_user_data.js +13 -0
- data/app/frontend/support/generate_user_group_data.js +14 -0
- data/app/helpers/decidim/comments/comments_helper.rb +10 -15
- data/app/models/decidim/comments/comment.rb +5 -7
- data/app/types/decidim/comments/comment_type.rb +5 -1
- data/config/locales/ca.yml +5 -1
- data/config/locales/en.yml +4 -1
- data/config/locales/es.yml +5 -1
- data/db/migrate/20170123102043_add_user_group_id_to_comments.rb +5 -0
- data/lib/decidim/comments/engine.rb +0 -1
- data/lib/decidim/comments/mutation_extensions.rb +2 -1
- metadata +10 -28
- data/app/frontend/support/generate_current_user_data.js +0 -13
- data/app/types/decidim/comments/author_type.rb +0 -15
data/app/frontend/entry.js
CHANGED
@@ -8,16 +8,9 @@ window.DecidimComments.renderCommentsComponent = (nodeId, props) => {
|
|
8
8
|
var node = $(`#${nodeId}`)[0];
|
9
9
|
|
10
10
|
ReactDOM.render(
|
11
|
-
React.createElement(Comments,props),
|
11
|
+
React.createElement(Comments, props),
|
12
12
|
node
|
13
13
|
);
|
14
|
-
|
15
|
-
function unmountComponent() {
|
16
|
-
ReactDOM.unmountComponentAtNode(node);
|
17
|
-
$(document).off('turbolinks:before-render', unmountComponent);
|
18
|
-
}
|
19
|
-
|
20
|
-
$(document).on('turbolinks:before-render', unmountComponent);
|
21
14
|
};
|
22
15
|
|
23
16
|
// Load component locales from yaml files
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { name } from 'faker/locale/en';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Generate random user data to emulate a database real content
|
5
|
+
* @returns {Object} - An object representing user data
|
6
|
+
*/
|
7
|
+
const generateUserData = () => {
|
8
|
+
return {
|
9
|
+
name: name.findName()
|
10
|
+
};
|
11
|
+
};
|
12
|
+
|
13
|
+
export default generateUserData;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { random, company } from 'faker/locale/en';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Generate random user group data to emulate a database real content
|
5
|
+
* @returns {Object} - An object representing user group data
|
6
|
+
*/
|
7
|
+
const generateUserGrouprData = () => {
|
8
|
+
return {
|
9
|
+
id: random.uuid(),
|
10
|
+
name: company.companyName()
|
11
|
+
};
|
12
|
+
};
|
13
|
+
|
14
|
+
export default generateUserGrouprData;
|
@@ -28,22 +28,17 @@ module Decidim
|
|
28
28
|
# props - A hash corresponding to Comments component props
|
29
29
|
def react_comments_component(node_id, props)
|
30
30
|
content_tag("div", "", id: node_id) +
|
31
|
+
javascript_include_tag("decidim/comments/comments") +
|
31
32
|
javascript_tag(%{
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
commentableId: "#{props[:commentableId]}",
|
42
|
-
options: JSON.parse("#{j(props[:options].to_json)}"),
|
43
|
-
locale: "#{props[:locale]}"
|
44
|
-
}
|
45
|
-
);
|
46
|
-
});
|
33
|
+
window.DecidimComments.renderCommentsComponent(
|
34
|
+
'#{node_id}',
|
35
|
+
{
|
36
|
+
commentableType: "#{props[:commentableType]}",
|
37
|
+
commentableId: "#{props[:commentableId]}",
|
38
|
+
options: JSON.parse("#{j(props[:options].to_json)}"),
|
39
|
+
locale: "#{props[:locale]}"
|
40
|
+
}
|
41
|
+
);
|
47
42
|
})
|
48
43
|
end
|
49
44
|
end
|
@@ -5,6 +5,8 @@ module Decidim
|
|
5
5
|
# comment on them. The will be able to create conversations between users
|
6
6
|
# to discuss or share their thoughts about the resource.
|
7
7
|
class Comment < ApplicationRecord
|
8
|
+
include Decidim::Authorable
|
9
|
+
|
8
10
|
# Limit the max depth of a comment tree. If C is a comment and R is a reply:
|
9
11
|
# C (depth 0)
|
10
12
|
# |--R (depth 1)
|
@@ -13,16 +15,16 @@ module Decidim
|
|
13
15
|
# |--R (depth 3)
|
14
16
|
MAX_DEPTH = 3
|
15
17
|
|
16
|
-
belongs_to :author, foreign_key: "decidim_author_id", class_name: Decidim::User
|
17
18
|
belongs_to :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", polymorphic: true
|
18
19
|
has_many :replies, as: :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", class_name: Comment
|
19
20
|
has_many :up_votes, -> { where(weight: 1) }, foreign_key: "decidim_comment_id", class_name: CommentVote, dependent: :destroy
|
20
21
|
has_many :down_votes, -> { where(weight: -1) }, foreign_key: "decidim_comment_id", class_name: CommentVote, dependent: :destroy
|
22
|
+
|
21
23
|
validates :author, :commentable, :body, presence: true
|
22
|
-
validate :commentable_can_have_replies
|
23
24
|
validates :depth, numericality: { greater_than_or_equal_to: 0 }
|
24
25
|
validates :alignment, inclusion: { in: [0, 1, -1] }
|
25
|
-
|
26
|
+
|
27
|
+
validate :commentable_can_have_replies
|
26
28
|
|
27
29
|
before_save :compute_depth
|
28
30
|
|
@@ -61,10 +63,6 @@ module Decidim
|
|
61
63
|
def compute_depth
|
62
64
|
self.depth = commentable.depth + 1 if commentable.respond_to?(:depth)
|
63
65
|
end
|
64
|
-
|
65
|
-
def same_organization
|
66
|
-
errors.add(:commentable, :invalid) unless author.organization == organization
|
67
|
-
end
|
68
66
|
end
|
69
67
|
end
|
70
68
|
end
|
@@ -16,7 +16,11 @@ module Decidim
|
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
|
-
field :author, !
|
19
|
+
field :author, !Decidim::Api::AuthorInterface, "The comment's author" do
|
20
|
+
resolve lambda { |obj, _args, _ctx|
|
21
|
+
obj.user_group || obj.author
|
22
|
+
}
|
23
|
+
end
|
20
24
|
|
21
25
|
field :replies, !types[CommentType], "The comment's replies" do
|
22
26
|
resolve lambda { |obj, _args, _ctx|
|
data/config/locales/ca.yml
CHANGED
@@ -11,6 +11,8 @@ ca:
|
|
11
11
|
label: Comentari
|
12
12
|
placeholder: Què en penses d'això?
|
13
13
|
submit: Envia
|
14
|
+
user_group_id:
|
15
|
+
label: Comentar com a
|
14
16
|
opinion:
|
15
17
|
against: Hi estic en contra
|
16
18
|
in_favor: Hi estic a favor
|
@@ -23,13 +25,15 @@ ca:
|
|
23
25
|
reply: Respondre
|
24
26
|
comment_order_selector:
|
25
27
|
order:
|
26
|
-
|
28
|
+
best_rated: Més ben valorats
|
29
|
+
most_discussed: Més discutit
|
27
30
|
older: Més antic
|
28
31
|
recent: Recent
|
29
32
|
title: 'Ordenar per:'
|
30
33
|
comment_thread:
|
31
34
|
title: Conversa amb %{authorName}
|
32
35
|
comments:
|
36
|
+
loading: Carregant els comentaris ...
|
33
37
|
title: "%{count} comentaris"
|
34
38
|
featured_comment:
|
35
39
|
title: Comentari destacat
|
data/config/locales/en.yml
CHANGED
@@ -12,6 +12,8 @@ en:
|
|
12
12
|
label: Comment
|
13
13
|
placeholder: What do you think about this?
|
14
14
|
submit: Send
|
15
|
+
user_group_id:
|
16
|
+
label: Comment as
|
15
17
|
opinion:
|
16
18
|
against: I am against
|
17
19
|
in_favor: I am in favor
|
@@ -24,7 +26,8 @@ en:
|
|
24
26
|
reply: Reply
|
25
27
|
comment_order_selector:
|
26
28
|
order:
|
27
|
-
|
29
|
+
best_rated: Best rated
|
30
|
+
most_discussed: Most discussed
|
28
31
|
older: Older
|
29
32
|
recent: Recent
|
30
33
|
title: 'Order by:'
|
data/config/locales/es.yml
CHANGED
@@ -11,6 +11,8 @@ es:
|
|
11
11
|
label: Comentario
|
12
12
|
placeholder: '¿Qué piensas sobre esto?'
|
13
13
|
submit: Enviar
|
14
|
+
user_group_id:
|
15
|
+
label: Comentar como
|
14
16
|
opinion:
|
15
17
|
against: Estoy en contra
|
16
18
|
in_favor: Estoy a favor
|
@@ -23,13 +25,15 @@ es:
|
|
23
25
|
reply: Respuesta
|
24
26
|
comment_order_selector:
|
25
27
|
order:
|
26
|
-
|
28
|
+
best_rated: Mejor valoración
|
29
|
+
most_discussed: Más discutidos
|
27
30
|
older: Más antiguo
|
28
31
|
recent: Reciente
|
29
32
|
title: 'Ordenar por:'
|
30
33
|
comment_thread:
|
31
34
|
title: Conversación con %{authorName}
|
32
35
|
comments:
|
36
|
+
loading: Cargando los comentarios ...
|
33
37
|
title: "%{count} comentarios"
|
34
38
|
featured_comment:
|
35
39
|
title: Comentario destacado
|
@@ -17,9 +17,10 @@ module Decidim
|
|
17
17
|
argument :commentableType, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
|
18
18
|
argument :body, !types.String, "The comments's body"
|
19
19
|
argument :alignment, types.Int, "The comment's alignment. Can be 0 (neutral), 1 (in favor) or -1 (against)'", default_value: 0
|
20
|
+
argument :userGroupId, types.ID, "The comment's user group id. Replaces the author."
|
20
21
|
|
21
22
|
resolve lambda { |_obj, args, ctx|
|
22
|
-
params = { "comment" => { "body" => args[:body], "alignment" => args[:alignment] } }
|
23
|
+
params = { "comment" => { "body" => args[:body], "alignment" => args[:alignment], "user_group_id" => args[:userGroupId] } }
|
23
24
|
form = Decidim::Comments::CommentForm.from_params(params)
|
24
25
|
commentable = args[:commentableType].constantize.find(args[:commentableId])
|
25
26
|
Decidim::Comments::CreateComment.call(form, ctx[:current_user], commentable) do
|
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.0.
|
4
|
+
version: 0.0.3
|
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: 2017-01
|
13
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: decidim-core
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.0.
|
21
|
+
version: 0.0.3
|
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.0.
|
28
|
+
version: 0.0.3
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rails
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,40 +60,20 @@ dependencies:
|
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '4.0'
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: turbolinks
|
65
|
-
requirement: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 5.0.0
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 5.0.0.1
|
73
|
-
type: :runtime
|
74
|
-
prerelease: false
|
75
|
-
version_requirements: !ruby/object:Gem::Requirement
|
76
|
-
requirements:
|
77
|
-
- - "~>"
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: 5.0.0
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 5.0.0.1
|
83
63
|
- !ruby/object:Gem::Dependency
|
84
64
|
name: decidim-dev
|
85
65
|
requirement: !ruby/object:Gem::Requirement
|
86
66
|
requirements:
|
87
67
|
- - '='
|
88
68
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.0.
|
69
|
+
version: 0.0.3
|
90
70
|
type: :development
|
91
71
|
prerelease: false
|
92
72
|
version_requirements: !ruby/object:Gem::Requirement
|
93
73
|
requirements:
|
94
74
|
- - '='
|
95
75
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.0.
|
76
|
+
version: 0.0.3
|
97
77
|
description: Pluggable comments system for some components.
|
98
78
|
email:
|
99
79
|
- josepjaume@gmail.com
|
@@ -119,6 +99,7 @@ files:
|
|
119
99
|
- app/frontend/application/icon.component.test.jsx
|
120
100
|
- app/frontend/comments/add_comment_form.component.jsx
|
121
101
|
- app/frontend/comments/add_comment_form.component.test.jsx
|
102
|
+
- app/frontend/comments/add_comment_form.fragment.graphql
|
122
103
|
- app/frontend/comments/add_comment_form.mutation.graphql
|
123
104
|
- app/frontend/comments/comment.component.jsx
|
124
105
|
- app/frontend/comments/comment.component.test.jsx
|
@@ -148,7 +129,8 @@ files:
|
|
148
129
|
- app/frontend/entry.test.js
|
149
130
|
- app/frontend/support/asset_url.js
|
150
131
|
- app/frontend/support/generate_comments_data.js
|
151
|
-
- app/frontend/support/
|
132
|
+
- app/frontend/support/generate_user_data.js
|
133
|
+
- app/frontend/support/generate_user_group_data.js
|
152
134
|
- app/frontend/support/load_translations.js
|
153
135
|
- app/frontend/support/require_all.js
|
154
136
|
- app/frontend/support/resolve_graphql_query.js
|
@@ -161,7 +143,6 @@ files:
|
|
161
143
|
- app/queries/decidim/comments/comments_with_replies.rb
|
162
144
|
- app/resolvers/decidim/comments/vote_comment_resolver.rb
|
163
145
|
- app/types/decidim/comments/add_comment_type.rb
|
164
|
-
- app/types/decidim/comments/author_type.rb
|
165
146
|
- app/types/decidim/comments/comment_mutation_type.rb
|
166
147
|
- app/types/decidim/comments/comment_type.rb
|
167
148
|
- config/i18n-tasks.yml
|
@@ -172,6 +153,7 @@ files:
|
|
172
153
|
- db/migrate/20161214082645_add_depth_to_comments.rb
|
173
154
|
- db/migrate/20161216102820_add_alignment_to_comments.rb
|
174
155
|
- db/migrate/20161219150806_create_comment_votes.rb
|
156
|
+
- db/migrate/20170123102043_add_user_group_id_to_comments.rb
|
175
157
|
- db/seeds.rb
|
176
158
|
- lib/decidim/comments.rb
|
177
159
|
- lib/decidim/comments/engine.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { name } from 'faker/locale/en';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Generate random current user data to emulate a database real content
|
5
|
-
* @returns {Object} - An object representing current user data
|
6
|
-
*/
|
7
|
-
const generateCurrentUserData = () => {
|
8
|
-
return {
|
9
|
-
name: name.findName()
|
10
|
-
};
|
11
|
-
};
|
12
|
-
|
13
|
-
export default generateCurrentUserData;
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module Decidim
|
3
|
-
module Comments
|
4
|
-
# This type represents an author who owns a resource
|
5
|
-
AuthorType = GraphQL::ObjectType.define do
|
6
|
-
name "Author"
|
7
|
-
description "An author"
|
8
|
-
|
9
|
-
field :name, !types.String, "The user's name"
|
10
|
-
field :avatarUrl, !types.String, "The user's avatar url" do
|
11
|
-
resolve ->(obj, _args, _ctx) { obj.avatar.url }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|