diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/images/comment_add.png | bin | 0 -> 530 bytes | |||
-rw-r--r-- | app/assets/images/cross.png | bin | 0 -> 655 bytes | |||
-rw-r--r-- | app/assets/javascripts/application.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/main/comments.coffee | 14 | ||||
-rw-r--r-- | app/assets/stylesheets/main/entries.scss | 20 | ||||
-rw-r--r-- | app/controllers/admin/comments_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/comments_controller.rb | 6 | ||||
-rw-r--r-- | app/mailers/comment_mailer.rb | 5 | ||||
-rw-r--r-- | app/models/comment.rb | 3 | ||||
-rw-r--r-- | app/views/comment_mailer/reply_comment_email.html.haml | 14 | ||||
-rw-r--r-- | app/views/comment_mailer/reply_comment_email.text.erb | 19 | ||||
-rw-r--r-- | app/views/comments/_comment.html.haml | 1 | ||||
-rw-r--r-- | app/views/comments/_form.html.haml | 6 |
13 files changed, 92 insertions, 1 deletions
diff --git a/app/assets/images/comment_add.png b/app/assets/images/comment_add.png new file mode 100644 index 0000000..75e78de --- /dev/null +++ b/app/assets/images/comment_add.png | |||
Binary files differ | |||
diff --git a/app/assets/images/cross.png b/app/assets/images/cross.png new file mode 100644 index 0000000..1514d51 --- /dev/null +++ b/app/assets/images/cross.png | |||
Binary files differ | |||
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index cd58a9c..d8f72b4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js | |||
@@ -17,3 +17,4 @@ | |||
17 | //= require jquery-ui | 17 | //= require jquery-ui |
18 | //= require js-routes | 18 | //= require js-routes |
19 | //= require_tree ./admin | 19 | //= require_tree ./admin |
20 | //= require_tree ./main | ||
diff --git a/app/assets/javascripts/main/comments.coffee b/app/assets/javascripts/main/comments.coffee new file mode 100644 index 0000000..d33e200 --- /dev/null +++ b/app/assets/javascripts/main/comments.coffee | |||
@@ -0,0 +1,14 @@ | |||
1 | comments_ready = -> | ||
2 | $(".comment-reply-to").click -> | ||
3 | $("#comment_reply_to_id").val($(this).data("commentId")) | ||
4 | $("#comment-reply-msg .comment-reply-author").text($(this).data("commentAuthor")) | ||
5 | $("#comment-reply-msg").show() | ||
6 | return false | ||
7 | |||
8 | $(".comment-reply-cancel").click -> | ||
9 | $("#comment_reply_to_id").val("") | ||
10 | $("#comment-reply-msg").hide() | ||
11 | return false | ||
12 | |||
13 | $(document).ready(comments_ready) | ||
14 | $(document).on('turbolinks:load', comments_ready) | ||
diff --git a/app/assets/stylesheets/main/entries.scss b/app/assets/stylesheets/main/entries.scss index 8d5796f..dd6b248 100644 --- a/app/assets/stylesheets/main/entries.scss +++ b/app/assets/stylesheets/main/entries.scss | |||
@@ -251,9 +251,29 @@ | |||
251 | float: right; | 251 | float: right; |
252 | margin-top: 1em; | 252 | margin-top: 1em; |
253 | } | 253 | } |
254 | |||
255 | .comment-reply-to { | ||
256 | float: right; | ||
257 | margin-right: 0.5em; | ||
258 | |||
259 | img { | ||
260 | display: block; | ||
261 | } | ||
262 | } | ||
254 | } | 263 | } |
255 | 264 | ||
256 | #comment-form { | 265 | #comment-form { |
266 | #comment-reply-msg { | ||
267 | display: none; | ||
268 | margin-top: 1em; | ||
269 | margin-bottom: 0; | ||
270 | margin-left: 0; | ||
271 | |||
272 | .comment-reply-author { | ||
273 | font-weight: bold; | ||
274 | } | ||
275 | } | ||
276 | |||
257 | fieldset { | 277 | fieldset { |
258 | border: 0; | 278 | border: 0; |
259 | 279 | ||
diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index ccde3e6..9958232 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb | |||
@@ -14,6 +14,10 @@ class Admin::CommentsController < Admin::AdminController | |||
14 | @comment.status = :published | 14 | @comment.status = :published |
15 | @comment.save! | 15 | @comment.save! |
16 | 16 | ||
17 | if @comment.reply_to and @comment.reply_to.email != @comment.blog.user.email and @comment.reply_to.email != current_user.email | ||
18 | CommentMailer.with(comment: @comment).reply_comment_email.deliver_later | ||
19 | end | ||
20 | |||
17 | flash.notice = "Comment successfully published." | 21 | flash.notice = "Comment successfully published." |
18 | redirect_to pending_admin_comments_url | 22 | redirect_to pending_admin_comments_url |
19 | end | 23 | end |
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index a444dba..2f3117f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb | |||
@@ -46,6 +46,10 @@ class CommentsController < ApplicationController | |||
46 | 46 | ||
47 | if @comment.status == :published | 47 | if @comment.status == :published |
48 | CommentMailer.with(comment: @comment).new_comment_email.deliver_later | 48 | CommentMailer.with(comment: @comment).new_comment_email.deliver_later |
49 | |||
50 | if @comment.reply_to and @comment.reply_to.email != @comment.blog.user.email | ||
51 | CommentMailer.with(comment: @comment).reply_comment_email.deliver_later | ||
52 | end | ||
49 | else | 53 | else |
50 | CommentMailer.with(comment: @comment).new_pending_comment_email.deliver_later | 54 | CommentMailer.with(comment: @comment).new_pending_comment_email.deliver_later |
51 | end | 55 | end |
@@ -60,6 +64,6 @@ class CommentsController < ApplicationController | |||
60 | private | 64 | private |
61 | 65 | ||
62 | def comment_params | 66 | def comment_params |
63 | params.require(:comment).permit(:username, :email, :website, :body) | 67 | params.require(:comment).permit(:username, :email, :website, :body, :reply_to_id) |
64 | end | 68 | end |
65 | end | 69 | end |
diff --git a/app/mailers/comment_mailer.rb b/app/mailers/comment_mailer.rb index aeed1b0..41feede 100644 --- a/app/mailers/comment_mailer.rb +++ b/app/mailers/comment_mailer.rb | |||
@@ -8,4 +8,9 @@ class CommentMailer < ApplicationMailer | |||
8 | @comment = params[:comment] | 8 | @comment = params[:comment] |
9 | mail(to: @comment.blog.user.email, subject: "[Four Island] Pending comment on #{@comment.blog.title}") | 9 | mail(to: @comment.blog.user.email, subject: "[Four Island] Pending comment on #{@comment.blog.title}") |
10 | end | 10 | end |
11 | |||
12 | def reply_comment_email | ||
13 | @comment = params[:comment] | ||
14 | mail(to: @comment.reply_to.email, subject: "[Four Island] Reply to your comment on #{@comment.blog.title}") | ||
15 | end | ||
11 | end | 16 | end |
diff --git a/app/models/comment.rb b/app/models/comment.rb index 9697100..b85f3b6 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb | |||
@@ -3,6 +3,9 @@ class Comment < ApplicationRecord | |||
3 | 3 | ||
4 | belongs_to :blog | 4 | belongs_to :blog |
5 | 5 | ||
6 | has_many :replies, class_name: "Comment", foreign_key: "reply_to_id" | ||
7 | belongs_to :reply_to, class_name: "Comment", optional: true | ||
8 | |||
6 | validates :body, presence: true | 9 | validates :body, presence: true |
7 | validates :username, presence: true | 10 | validates :username, presence: true |
8 | validates :email, presence: true, format: URI::MailTo::EMAIL_REGEXP | 11 | validates :email, presence: true, format: URI::MailTo::EMAIL_REGEXP |
diff --git a/app/views/comment_mailer/reply_comment_email.html.haml b/app/views/comment_mailer/reply_comment_email.html.haml new file mode 100644 index 0000000..22009ee --- /dev/null +++ b/app/views/comment_mailer/reply_comment_email.html.haml | |||
@@ -0,0 +1,14 @@ | |||
1 | %p | ||
2 | A reply has been posted to your comment on | ||
3 | = succeed "." do | ||
4 | = link_to @comment.blog.title, @comment.blog | ||
5 | The original comment: | ||
6 | %blockquote= @comment.reply_to.body | ||
7 | %p | ||
8 | = @comment.username | ||
9 | left the following response: | ||
10 | %blockquote= @comment.body | ||
11 | %p | ||
12 | Posted: | ||
13 | = @comment.published_at.strftime("%B #{@comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") | ||
14 | %p= link_to "See the comment on the web", blog_url(@comment.blog, anchor: "comment-#{@comment.id}") | ||
diff --git a/app/views/comment_mailer/reply_comment_email.text.erb b/app/views/comment_mailer/reply_comment_email.text.erb new file mode 100644 index 0000000..bd60692 --- /dev/null +++ b/app/views/comment_mailer/reply_comment_email.text.erb | |||
@@ -0,0 +1,19 @@ | |||
1 | A reply has been posted to your comment on <%= @comment.blog.title %>. The original comment: | ||
2 | |||
3 | --- | ||
4 | |||
5 | <%= @comment.reply_to.body %> | ||
6 | |||
7 | --- | ||
8 | |||
9 | <%= @comment.username %> posted the following response: | ||
10 | |||
11 | --- | ||
12 | |||
13 | <%= @comment.body %> | ||
14 | |||
15 | --- | ||
16 | |||
17 | Posted: <%= @comment.published_at.strftime("%B #{@comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") %> | ||
18 | |||
19 | See the comment on the web: <%= blog_url(@comment.blog, anchor: "comment-#{@comment.id}") %> | ||
diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 3ad21e9..225b5d9 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml | |||
@@ -11,3 +11,4 @@ | |||
11 | = link_to comment.username, comment.website | 11 | = link_to comment.username, comment.website |
12 | on | 12 | on |
13 | = comment.published_at.strftime("%B #{comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") | 13 | = comment.published_at.strftime("%B #{comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") |
14 | = link_to (image_tag "comment_add.png"), "#", class: "comment-reply-to", title: "Reply to comment", data: { comment_id: comment.id, comment_author: comment.username } | ||
diff --git a/app/views/comments/_form.html.haml b/app/views/comments/_form.html.haml index f6df807..eb374c7 100644 --- a/app/views/comments/_form.html.haml +++ b/app/views/comments/_form.html.haml | |||
@@ -1,6 +1,12 @@ | |||
1 | = form_for @comment || blog.comments.new, html: { id: "comment-form" } do |f| | 1 | = form_for @comment || blog.comments.new, html: { id: "comment-form" } do |f| |
2 | = f.hidden_field :reply_to_id | ||
2 | %fieldset#comment-body-field | 3 | %fieldset#comment-body-field |
3 | %blockquote.bubble.rounded.bottom | 4 | %blockquote.bubble.rounded.bottom |
5 | #comment-reply-msg | ||
6 | = link_to (image_tag "cross"), "#", class: "comment-reply-cancel" | ||
7 | Replying to comment by | ||
8 | = succeed ":" do | ||
9 | %span.comment-reply-author | ||
4 | = f.label :body | 10 | = f.label :body |
5 | = f.text_area :body | 11 | = f.text_area :body |
6 | %cite.bubble Feel free to post a comment! You may use Markdown. | 12 | %cite.bubble Feel free to post a comment! You may use Markdown. |