decidim-comments 0.25.0.rc2 → 0.25.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0e368d7c967fbbadf3d8b8b1ccb568c0d013f67167eef0007772758f9e1b1a4
4
- data.tar.gz: 8235ff94668c55ec576442a620851e70a60753e3475fa904b3f91e1394f40c02
3
+ metadata.gz: 5025c82564955ebb8952a49e8e301256ef9c4465fbf8f52e5b2489124674cff4
4
+ data.tar.gz: 66a5ab9d8c0af6e7120e02a0220fa8777b9e0bbe6d5c862ac420c729194cedee
5
5
  SHA512:
6
- metadata.gz: fd688c1e740ef402ed0013475369601f19dc7242856315ac4993829300ded40df137a85ff307467171cc389974b0103f3167204d4c0c2abd7fce41e8ecd17001
7
- data.tar.gz: bd0be8a17ad9d33682d4896eab5a4bc961871b59b4e7886b09a678e04f1e692f1900a77d9e1041c4310588f4ab376eb3e5a0b018eb0d17c69d86fbc0819ad923
6
+ metadata.gz: da03ef21094993feba8baa55864c33292820678b7105a749abd68761522aae1b018796316f289ce0c847f10cd204d8f75df4530866f25d1742486674e9da85c3
7
+ data.tar.gz: 1cc6d927dbd821d7f0647c5dd22c30faeab751a39f948bcbde85f3cf269afded077dacc9935dea3cebf2b2e95f6aca4b5a21cffbdd2e92860c9a248039c3d9f2
@@ -37,12 +37,7 @@ export default class CommentsComponent {
37
37
  this.mounted = true;
38
38
  this._initializeComments(this.$element);
39
39
 
40
- $(".order-by__dropdown .is-submenu-item a", this.$element).on(
41
- "click.decidim-comments",
42
- () => {
43
- this._onInitOrder();
44
- }
45
- );
40
+ $(".order-by__dropdown .is-submenu-item a", this.$element).on("click.decidim-comments", () => this._onInitOrder());
46
41
  }
47
42
  }
48
43
 
@@ -68,14 +63,16 @@ export default class CommentsComponent {
68
63
  * Adds a new thread to the comments section.
69
64
  * @public
70
65
  * @param {String} threadHtml - The HTML content for the thread.
66
+ * @param {Boolean} fromCurrentUser - A boolean indicating whether the user
67
+ * herself was the author of the new thread. Defaults to false.
71
68
  * @returns {Void} - Returns nothing
72
69
  */
73
- addThread(threadHtml) {
70
+ addThread(threadHtml, fromCurrentUser = false) {
74
71
  const $parent = $(".comments:first", this.$element);
75
72
  const $comment = $(threadHtml);
76
73
  const $threads = $(".comment-threads", this.$element);
77
74
  this._addComment($threads, $comment);
78
- this._finalizeCommentCreation($parent);
75
+ this._finalizeCommentCreation($parent, fromCurrentUser);
79
76
  }
80
77
 
81
78
  /**
@@ -84,15 +81,17 @@ export default class CommentsComponent {
84
81
  * @param {Number} commentId - The ID of the comment for which to add the
85
82
  * reply to.
86
83
  * @param {String} replyHtml - The HTML content for the reply.
84
+ * @param {Boolean} fromCurrentUser - A boolean indicating whether the user
85
+ * herself was the author of the new reply. Defaults to false.
87
86
  * @returns {Void} - Returns nothing
88
87
  */
89
- addReply(commentId, replyHtml) {
88
+ addReply(commentId, replyHtml, fromCurrentUser = false) {
90
89
  const $parent = $(`#comment_${commentId}`);
91
90
  const $comment = $(replyHtml);
92
91
  const $replies = $(`#comment-${commentId}-replies`);
93
92
  this._addComment($replies, $comment);
94
93
  $replies.siblings(".comment__additionalreply").removeClass("hide");
95
- this._finalizeCommentCreation($parent);
94
+ this._finalizeCommentCreation($parent, fromCurrentUser);
96
95
  }
97
96
 
98
97
  /**
@@ -170,18 +169,22 @@ export default class CommentsComponent {
170
169
  * successfully.
171
170
  * @private
172
171
  * @param {jQuery} $parent - The parent comment element to finalize.
172
+ * @param {Boolean} fromCurrentUser - A boolean indicating whether the user
173
+ * herself was the author of the new comment.
173
174
  * @returns {Void} - Returns nothing
174
175
  */
175
- _finalizeCommentCreation($parent) {
176
- const $add = $("> .add-comment", $parent);
177
- const $text = $("textarea", $add);
178
- const characterCounter = $text.data("remaining-characters-counter");
179
- $text.val("");
180
- if (characterCounter) {
181
- characterCounter.updateStatus();
182
- }
183
- if (!$add.parent().is(".comments")) {
184
- $add.addClass("hide");
176
+ _finalizeCommentCreation($parent, fromCurrentUser) {
177
+ if (fromCurrentUser) {
178
+ const $add = $("> .add-comment", $parent);
179
+ const $text = $("textarea", $add);
180
+ const characterCounter = $text.data("remaining-characters-counter");
181
+ $text.val("");
182
+ if (characterCounter) {
183
+ characterCounter.updateStatus();
184
+ }
185
+ if (!$add.parent().is(".comments")) {
186
+ $add.addClass("hide");
187
+ }
185
188
  }
186
189
 
187
190
  // Restart the polling
@@ -207,9 +210,7 @@ export default class CommentsComponent {
207
210
  order: this.order,
208
211
  after: this.lastCommentId
209
212
  }
210
- }).done(() => {
211
- this._pollComments();
212
- });
213
+ }).done(() => this._pollComments());
213
214
  }, this.pollingInterval);
214
215
  }
215
216
 
@@ -558,17 +558,82 @@ describe("CommentsComponent", () => {
558
558
  "This is a dynamically added comment"
559
559
  ));
560
560
  });
561
+
562
+ it("does not clear the comment form text area", () => {
563
+ const commentSection = addComment[addComment.length - 1];
564
+ const textArea = $("textarea", commentSection);
565
+ textArea.val("I am writing a new comment...");
566
+
567
+ const newThread = generateCommentThread(999, "This is a dynamically added comment");
568
+ subject.addThread(newThread);
569
+
570
+ expect(textArea.val()).toEqual("I am writing a new comment...");
571
+ });
572
+
573
+ describe("as the current user", () => {
574
+ it("clears the comment form text area", () => {
575
+ const commentSection = addComment[addComment.length - 1];
576
+ const textArea = $("textarea", commentSection);
577
+ textArea.val("I am writing a new comment...");
578
+
579
+ const newThread = generateCommentThread(999, "This is a dynamically added comment");
580
+ subject.addThread(newThread, true);
581
+
582
+ expect(textArea.val()).toEqual("");
583
+ });
584
+ });
561
585
  });
562
586
 
563
587
  describe("addReply", () => {
588
+ const newReply = generateSingleComment(999, "This is a dynamically added reply");
589
+
564
590
  it("adds a new reply to an existing thread", () => {
565
- const newThread = generateSingleComment(999, "This is a dynamically added reply");
566
- subject.addReply(450, newThread);
591
+ subject.addReply(450, newReply);
567
592
 
568
593
  expect(subject.$element.html()).toEqual(expect.stringContaining(
569
594
  "This is a dynamically added reply"
570
595
  ));
571
596
  });
597
+
598
+ it("does not clear the reply comment form text area", () => {
599
+ const commentSection = $("#comment450-reply", subject.$element);
600
+ const textArea = $("textarea", commentSection);
601
+ textArea.val("I am writing a new comment...");
602
+
603
+ subject.addReply(450, newReply);
604
+
605
+ expect(textArea.val()).toEqual("I am writing a new comment...");
606
+ });
607
+
608
+ it("does not hide the reply form", () => {
609
+ const commentSection = $("#comment450-reply", subject.$element);
610
+ commentSection.removeClass("hide");
611
+
612
+ subject.addReply(450, newReply);
613
+
614
+ expect(commentSection.hasClass("hide")).toBeFalsy();
615
+ });
616
+
617
+ describe("as the current user", () => {
618
+ it("clears the comment form text area", () => {
619
+ const commentSection = $("#comment450-reply", subject.$element);
620
+ const textArea = $("textarea", commentSection);
621
+ textArea.val("I am writing a new comment...");
622
+
623
+ subject.addReply(450, newReply, true);
624
+
625
+ expect(textArea.val()).toEqual("");
626
+ });
627
+
628
+ it("hides the reply form", () => {
629
+ const commentSection = $("#comment450-reply", subject.$element);
630
+ commentSection.removeClass("hide");
631
+
632
+ subject.addReply(450, newReply, true);
633
+
634
+ expect(commentSection.hasClass("hide")).toBeTruthy();
635
+ });
636
+ });
572
637
  });
573
638
  });
574
639
 
@@ -33,12 +33,6 @@ module Decidim
33
33
  scope = base_scope
34
34
  .not_hidden
35
35
  .includes(:author, :user_group, :up_votes, :down_votes)
36
- if @options[:after]
37
- scope = scope.where(
38
- "decidim_comments_comments.id > ?",
39
- @options[:after]
40
- )
41
- end
42
36
 
43
37
  case @options[:order_by]
44
38
  when "older"
@@ -60,6 +54,14 @@ module Decidim
60
54
  id = @options[:id]
61
55
  return Comment.where(root_commentable: commentable, id: id) if id.present?
62
56
 
57
+ after = @options[:after]
58
+ if after.present?
59
+ return Comment.where(root_commentable: commentable).where(
60
+ "decidim_comments_comments.id > ?",
61
+ after
62
+ )
63
+ end
64
+
63
65
  Comment.where(commentable: commentable)
64
66
  end
65
67
 
@@ -6,9 +6,9 @@
6
6
  var $comments = $("#" + rootCommentableId);
7
7
  var component = $comments.data("comments");
8
8
  if (inReplyTo) {
9
- component.addReply(inReplyTo, commentHtml);
9
+ component.addReply(inReplyTo, commentHtml, true);
10
10
  } else {
11
- component.addThread(commentHtml);
11
+ component.addThread(commentHtml, true);
12
12
  }
13
13
 
14
14
  // Update the comments count
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-comments version.
5
5
  module Comments
6
6
  def self.version
7
- "0.25.0.rc2"
7
+ "0.25.0.rc3"
8
8
  end
9
9
  end
10
10
  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.25.0.rc2
4
+ version: 0.25.0.rc3
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-09-13 00:00:00.000000000 Z
13
+ date: 2021-09-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.25.0.rc2
21
+ version: 0.25.0.rc3
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.25.0.rc2
28
+ version: 0.25.0.rc3
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: redcarpet
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -52,28 +52,28 @@ dependencies:
52
52
  requirements:
53
53
  - - '='
54
54
  - !ruby/object:Gem::Version
55
- version: 0.25.0.rc2
55
+ version: 0.25.0.rc3
56
56
  type: :development
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
- version: 0.25.0.rc2
62
+ version: 0.25.0.rc3
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: decidim-dev
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - '='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.25.0.rc2
69
+ version: 0.25.0.rc3
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.25.0.rc2
76
+ version: 0.25.0.rc3
77
77
  description: Pluggable comments system for some components.
78
78
  email:
79
79
  - josepjaume@gmail.com