decidim-comments 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/decidim/comments/bundle.js +28 -23
  4. data/app/assets/javascripts/decidim/comments/bundle.js.map +1 -1
  5. data/app/commands/decidim/comments/create_comment.rb +10 -0
  6. data/app/forms/decidim/comments/comment_form.rb +1 -1
  7. data/app/frontend/comments/add_comment_form.component.jsx +171 -87
  8. data/app/frontend/comments/add_comment_form.component.test.jsx +41 -22
  9. data/app/frontend/comments/add_comment_form.mutation.graphql +5 -3
  10. data/app/frontend/comments/add_comment_form_commentable.fragment.graphql +4 -0
  11. data/app/frontend/comments/add_comment_form_session.fragment.graphql +6 -0
  12. data/app/frontend/comments/comment.component.jsx +18 -18
  13. data/app/frontend/comments/comment.component.test.jsx +22 -21
  14. data/app/frontend/comments/comment.fragment.graphql +4 -4
  15. data/app/frontend/comments/comment_data.fragment.graphql +4 -3
  16. data/app/frontend/comments/comment_order_selector.component.jsx +3 -3
  17. data/app/frontend/comments/comment_thread.component.jsx +8 -3
  18. data/app/frontend/comments/comment_thread.component.test.jsx +3 -3
  19. data/app/frontend/comments/comment_thread.fragment.graphql +1 -1
  20. data/app/frontend/comments/comments.component.jsx +52 -33
  21. data/app/frontend/comments/comments.component.test.jsx +51 -38
  22. data/app/frontend/comments/comments.query.graphql +10 -4
  23. data/app/frontend/comments/down_vote_button.component.jsx +6 -3
  24. data/app/frontend/comments/up_vote_button.component.jsx +7 -4
  25. data/app/frontend/comments/vote_button.component.jsx +5 -0
  26. data/app/frontend/comments/vote_button_component.test.jsx +1 -1
  27. data/app/frontend/entry.test.js +2 -0
  28. data/app/frontend/support/generate_comments_data.js +4 -4
  29. data/app/mailers/decidim/comments/comment_notification_mailer.rb +31 -0
  30. data/app/models/decidim/comments/comment.rb +13 -9
  31. data/app/queries/decidim/comments/{comments_with_replies.rb → sorted_comments.rb} +3 -8
  32. data/app/types/decidim/comments/commentable_interface.rb +44 -0
  33. data/app/types/decidim/comments/commentable_mutation_type.rb +29 -0
  34. data/app/types/decidim/comments/commentable_type.rb +14 -0
  35. data/app/views/decidim/comments/comment_notification_mailer/comment_created.html.erb +18 -0
  36. data/app/views/decidim/comments/comment_notification_mailer/reply_created.html.erb +18 -0
  37. data/config/locales/ca.yml +20 -4
  38. data/config/locales/en.yml +22 -5
  39. data/config/locales/es.yml +20 -4
  40. data/config/locales/eu.yml +5 -0
  41. data/lib/decidim/comments.rb +5 -0
  42. data/{app/types/decidim/comments → lib/decidim/comments/api}/add_comment_type.rb +0 -0
  43. data/{app/types/decidim/comments → lib/decidim/comments/api}/comment_mutation_type.rb +0 -0
  44. data/{app/types/decidim/comments → lib/decidim/comments/api}/comment_type.rb +11 -17
  45. data/lib/decidim/comments/commentable.rb +45 -0
  46. data/{app/helpers → lib}/decidim/comments/comments_helper.rb +15 -10
  47. data/lib/decidim/comments/mutation_extensions.rb +8 -16
  48. data/lib/decidim/comments/query_extensions.rb +5 -8
  49. data/lib/decidim/comments/test/factories.rb +3 -3
  50. metadata +21 -12
  51. data/app/frontend/comments/add_comment_form.fragment.graphql +0 -6
@@ -0,0 +1,5 @@
1
+ eu:
2
+ decidim:
3
+ comments:
4
+ comment_notification_mailer:
5
+ hello: Kaixo %{name},
@@ -6,5 +6,10 @@ module Decidim
6
6
  # It exposes a single entry point as a rails helper method to render
7
7
  # a React component which handle all the comments render and logic.
8
8
  module Comments
9
+ autoload :CommentsHelper, "decidim/comments/comments_helper"
10
+ autoload :AddCommentType, "decidim/comments/api/add_comment_type"
11
+ autoload :CommentMutationType, "decidim/comments/api/comment_mutation_type"
12
+ autoload :CommentType, "decidim/comments/api/comment_type"
13
+ autoload :Commentable, "decidim/comments/commentable"
9
14
  end
10
15
  end
@@ -6,6 +6,10 @@ module Decidim
6
6
  name "Comment"
7
7
  description "A comment"
8
8
 
9
+ interfaces [
10
+ Decidim::Comments::CommentableInterface
11
+ ]
12
+
9
13
  field :id, !types.ID, "The Comment's unique ID"
10
14
 
11
15
  field :body, !types.String, "The comment message"
@@ -16,28 +20,12 @@ module Decidim
16
20
  }
17
21
  end
18
22
 
19
- field :author, !Decidim::Api::AuthorInterface, "The comment's author" do
23
+ field :author, !Decidim::AuthorInterface, "The comment's author" do
20
24
  resolve lambda { |obj, _args, _ctx|
21
25
  obj.user_group || obj.author
22
26
  }
23
27
  end
24
28
 
25
- field :replies, !types[CommentType], "The comment's replies" do
26
- resolve lambda { |obj, _args, _ctx|
27
- obj.replies.sort_by(&:created_at)
28
- }
29
- end
30
-
31
- field :hasReplies, !types.Boolean, "Check if the comment has replies" do
32
- resolve lambda { |obj, _args, _ctx|
33
- obj.replies.size.positive?
34
- }
35
- end
36
-
37
- field :canHaveReplies, !types.Boolean, "Define if a comment can or not have replies" do
38
- property :can_have_replies?
39
- end
40
-
41
29
  field :alignment, types.Int, "The comment's alignment. Can be 0 (neutral), 1 (in favor) or -1 (against)'"
42
30
 
43
31
  field :upVotes, !types.Int, "The number of comment's upVotes" do
@@ -63,6 +51,12 @@ module Decidim
63
51
  obj.down_voted_by?(ctx[:current_user])
64
52
  }
65
53
  end
54
+
55
+ field :hasComments, !types.Boolean, "Check if the commentable has comments" do
56
+ resolve lambda { |obj, _args, _ctx|
57
+ obj.accepts_new_comments? && obj.comments.size.positive?
58
+ }
59
+ end
66
60
  end
67
61
  end
68
62
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Comments
7
+ # Shared behaviour for commentable models.
8
+ module Commentable
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ include Decidim::Authorable
13
+
14
+ has_many :comments, as: :commentable, foreign_key: "decidim_commentable_id", foreign_type: "decidim_commentable_type", class_name: "Decidim::Comments::Comment"
15
+
16
+ # Public: Wether the object's comments are visible or not.
17
+ def commentable?
18
+ true
19
+ end
20
+
21
+ # Public: Wether the object can have new comments or not.
22
+ def accepts_new_comments?
23
+ true
24
+ end
25
+
26
+ # Public: Wether the object's comments can have alignment or not. It enables the
27
+ # alignment selector in the add new comment form.
28
+ def comments_have_alignment?
29
+ false
30
+ end
31
+
32
+ # Public: Wether the object's comments can have have votes or not. It enables the
33
+ # upvote and downvote buttons for comments.
34
+ def comments_have_votes?
35
+ false
36
+ end
37
+
38
+ # Public: Identifies the commentable type in the API.
39
+ def commentable_type
40
+ self.class.name
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -3,22 +3,28 @@ module Decidim
3
3
  module Comments
4
4
  # A helper to expose the comments component for a commentable
5
5
  module CommentsHelper
6
- # Creates a Comments component which is rendered using `react_ujs`
7
- # from react-rails gem
6
+ # Render commentable comments inside the `expanded` template content.
8
7
  #
9
8
  # resource - A commentable resource
10
- # options - A hash of options (default: {})
11
- # :arguable - A boolean value to indicate if tihs option is available
9
+ def comments_for(resource)
10
+ return unless resource.commentable?
11
+ content_for :expanded do
12
+ inline_comments_for(resource)
13
+ end
14
+ end
15
+
16
+ # Creates a Comments component which is rendered using `ReactDOM`
12
17
  #
13
- # Returns a div which contain a RectComponent to be rendered by `react_ujs`
14
- def comments_for(resource, options = {})
15
- commentable_type = resource.class.name
18
+ # resource - A commentable resource
19
+ #
20
+ # Returns a div which contain a RectComponent
21
+ def inline_comments_for(resource)
22
+ return unless resource.commentable?
23
+ commentable_type = resource.commentable_type
16
24
  commentable_id = resource.id.to_s
17
25
  node_id = "comments-for-#{commentable_type.demodulize}-#{commentable_id}"
18
-
19
26
  react_comments_component(node_id, commentableType: commentable_type,
20
27
  commentableId: commentable_id,
21
- options: options.slice(:arguable, :votable),
22
28
  locale: I18n.locale)
23
29
  end
24
30
 
@@ -35,7 +41,6 @@ module Decidim
35
41
  {
36
42
  commentableType: "#{props[:commentableType]}",
37
43
  commentableId: "#{props[:commentableId]}",
38
- options: JSON.parse("#{j(props[:options].to_json)}"),
39
44
  locale: "#{props[:locale]}"
40
45
  }
41
46
  );
@@ -11,28 +11,20 @@ module Decidim
11
11
  # Returns nothing.
12
12
  def self.extend!(type)
13
13
  type.define do
14
- field :addComment, Decidim::Comments::CommentType do
15
- description "Add a new comment to a commentable"
16
- argument :commentableId, !types.String, "The commentable's ID"
17
- argument :commentableType, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
18
- argument :body, !types.String, "The comments's body"
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."
14
+ field :commentable, Decidim::Comments::CommentableMutationType do
15
+ description "A commentable"
21
16
 
22
- resolve lambda { |_obj, args, ctx|
23
- params = { "comment" => { "body" => args[:body], "alignment" => args[:alignment], "user_group_id" => args[:userGroupId] } }
24
- form = Decidim::Comments::CommentForm.from_params(params)
25
- commentable = args[:commentableType].constantize.find(args[:commentableId])
26
- Decidim::Comments::CreateComment.call(form, ctx[:current_user], commentable) do
27
- on(:ok) do |comment|
28
- return comment
29
- end
30
- end
17
+ argument :id, !types.String, "The commentable's ID"
18
+ argument :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
19
+
20
+ resolve lambda { |_obj, args, _ctx|
21
+ args[:type].constantize.find(args[:id])
31
22
  }
32
23
  end
33
24
 
34
25
  field :comment, Decidim::Comments::CommentMutationType do
35
26
  description "A comment"
27
+
36
28
  argument :id, !types.ID, "The comment's id"
37
29
 
38
30
  resolve lambda { |_obj, args, _ctx|
@@ -11,17 +11,14 @@ module Decidim
11
11
  # Returns nothing.
12
12
  def self.extend!(type)
13
13
  type.define do
14
- field :comments do
15
- description "Lists all commentable's comments."
16
- type !types[CommentType]
14
+ field :commentable do
15
+ type !CommentableType
17
16
 
18
- argument :commentableId, !types.String, "The commentable's ID"
19
- argument :commentableType, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
20
- argument :orderBy, types.String, "Order the comments"
17
+ argument :id, !types.String, "The commentable's ID"
18
+ argument :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`"
21
19
 
22
20
  resolve lambda { |_obj, args, _ctx|
23
- commentable = args[:commentableType].constantize.find(args[:commentableId])
24
- CommentsWithReplies.for(commentable, order_by: args[:orderBy])
21
+ args[:type].constantize.find(args[:id])
25
22
  }
26
23
  end
27
24
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  FactoryGirl.define do
3
- factory :comment, class: Decidim::Comments::Comment do
3
+ factory :comment, class: "Decidim::Comments::Comment" do
4
4
  author { build(:user, organization: commentable.organization) }
5
- commentable { build(:participatory_process) }
5
+ commentable { build(:dummy_resource) }
6
6
  body { Faker::Lorem.paragraph }
7
7
  end
8
8
 
9
- factory :comment_vote, class: Decidim::Comments::CommentVote do
9
+ factory :comment_vote, class: "Decidim::Comments::CommentVote" do
10
10
  comment { build(:comment) }
11
11
  author { build(:user, organization: comment.organization) }
12
12
  weight { [-1, 1].sample }
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.3
4
+ version: 0.0.5
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-02-01 00:00:00.000000000 Z
13
+ date: 2017-02-17 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.3
21
+ version: 0.0.5
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.3
28
+ version: 0.0.5
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rails
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -66,14 +66,14 @@ dependencies:
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.0.3
69
+ version: 0.0.5
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - '='
75
75
  - !ruby/object:Gem::Version
76
- version: 0.0.3
76
+ version: 0.0.5
77
77
  description: Pluggable comments system for some components.
78
78
  email:
79
79
  - josepjaume@gmail.com
@@ -99,8 +99,9 @@ files:
99
99
  - app/frontend/application/icon.component.test.jsx
100
100
  - app/frontend/comments/add_comment_form.component.jsx
101
101
  - app/frontend/comments/add_comment_form.component.test.jsx
102
- - app/frontend/comments/add_comment_form.fragment.graphql
103
102
  - app/frontend/comments/add_comment_form.mutation.graphql
103
+ - app/frontend/comments/add_comment_form_commentable.fragment.graphql
104
+ - app/frontend/comments/add_comment_form_session.fragment.graphql
104
105
  - app/frontend/comments/comment.component.jsx
105
106
  - app/frontend/comments/comment.component.test.jsx
106
107
  - app/frontend/comments/comment.fragment.graphql
@@ -135,20 +136,23 @@ files:
135
136
  - app/frontend/support/require_all.js
136
137
  - app/frontend/support/resolve_graphql_query.js
137
138
  - app/frontend/support/stub_component.js
138
- - app/helpers/decidim/comments/comments_helper.rb
139
+ - app/mailers/decidim/comments/comment_notification_mailer.rb
139
140
  - app/models/decidim/comments/application_record.rb
140
141
  - app/models/decidim/comments/comment.rb
141
142
  - app/models/decidim/comments/comment_vote.rb
142
143
  - app/models/decidim/comments/seed.rb
143
- - app/queries/decidim/comments/comments_with_replies.rb
144
+ - app/queries/decidim/comments/sorted_comments.rb
144
145
  - app/resolvers/decidim/comments/vote_comment_resolver.rb
145
- - app/types/decidim/comments/add_comment_type.rb
146
- - app/types/decidim/comments/comment_mutation_type.rb
147
- - app/types/decidim/comments/comment_type.rb
146
+ - app/types/decidim/comments/commentable_interface.rb
147
+ - app/types/decidim/comments/commentable_mutation_type.rb
148
+ - app/types/decidim/comments/commentable_type.rb
149
+ - app/views/decidim/comments/comment_notification_mailer/comment_created.html.erb
150
+ - app/views/decidim/comments/comment_notification_mailer/reply_created.html.erb
148
151
  - config/i18n-tasks.yml
149
152
  - config/locales/ca.yml
150
153
  - config/locales/en.yml
151
154
  - config/locales/es.yml
155
+ - config/locales/eu.yml
152
156
  - db/migrate/20161130143508_create_comments.rb
153
157
  - db/migrate/20161214082645_add_depth_to_comments.rb
154
158
  - db/migrate/20161216102820_add_alignment_to_comments.rb
@@ -156,6 +160,11 @@ files:
156
160
  - db/migrate/20170123102043_add_user_group_id_to_comments.rb
157
161
  - db/seeds.rb
158
162
  - lib/decidim/comments.rb
163
+ - lib/decidim/comments/api/add_comment_type.rb
164
+ - lib/decidim/comments/api/comment_mutation_type.rb
165
+ - lib/decidim/comments/api/comment_type.rb
166
+ - lib/decidim/comments/commentable.rb
167
+ - lib/decidim/comments/comments_helper.rb
159
168
  - lib/decidim/comments/engine.rb
160
169
  - lib/decidim/comments/mutation_extensions.rb
161
170
  - lib/decidim/comments/query_extensions.rb
@@ -1,6 +0,0 @@
1
- fragment AddCommentForm on Session {
2
- verifiedUserGroups {
3
- id
4
- name
5
- }
6
- }