about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/admin/dashboard.coffee2
-rw-r--r--app/assets/stylesheets/admin/dashboard.scss5
-rw-r--r--app/controllers/admin/comments_controller.rb53
-rw-r--r--app/views/admin/comments/pending.haml52
-rw-r--r--config/routes.rb1
5 files changed, 74 insertions, 39 deletions
diff --git a/app/assets/javascripts/admin/dashboard.coffee b/app/assets/javascripts/admin/dashboard.coffee index 4fa6cd8..bc48315 100644 --- a/app/assets/javascripts/admin/dashboard.coffee +++ b/app/assets/javascripts/admin/dashboard.coffee
@@ -3,6 +3,8 @@
3# You can use CoffeeScript in this file: http://coffeescript.org/ 3# You can use CoffeeScript in this file: http://coffeescript.org/
4dash_ready = -> 4dash_ready = ->
5 $(".datepicker").datepicker({"dateFormat": "yy-mm-dd"}) 5 $(".datepicker").datepicker({"dateFormat": "yy-mm-dd"})
6 $("#check_all").change ->
7 $(".comment_ids").prop("checked", $(this).prop("checked"))
6 8
7$(document).ready(dash_ready) 9$(document).ready(dash_ready)
8$(document).on('turbolinks:load', dash_ready) 10$(document).on('turbolinks:load', dash_ready)
diff --git a/app/assets/stylesheets/admin/dashboard.scss b/app/assets/stylesheets/admin/dashboard.scss index 60c257a..44e13b3 100644 --- a/app/assets/stylesheets/admin/dashboard.scss +++ b/app/assets/stylesheets/admin/dashboard.scss
@@ -40,3 +40,8 @@
40 } 40 }
41 } 41 }
42} 42}
43
44#action-box {
45 text-align: center;
46 margin: 1em 0;
47}
diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index 6b4bff3..4d9502d 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb
@@ -33,22 +33,7 @@ class Admin::CommentsController < Admin::AdminController
33 33
34 def mark_spam 34 def mark_spam
35 @comment = Comment.find(params[:id]) 35 @comment = Comment.find(params[:id])
36 36 perform_mark_spam(@comment)
37 akismet_params = {
38 type: "comment",
39 text: @comment.body,
40 created_at: @comment.created_at,
41 author: @comment.username,
42 author_email: @comment.email,
43 author_url: @comment.website,
44 post_url: url_for(@comment.blog),
45 post_modified_at: @comment.blog.updated_at,
46 referrer: @comment.referrer
47 }
48
49 Akismet.spam @comment.request_ip, @comment.user_agent, akismet_params
50
51 @comment.destroy!
52 37
53 flash.notice = "Comment successfully marked as spam." 38 flash.notice = "Comment successfully marked as spam."
54 redirect_back fallback_location: pending_admin_comments_url 39 redirect_back fallback_location: pending_admin_comments_url
@@ -64,9 +49,45 @@ class Admin::CommentsController < Admin::AdminController
64 redirect_to admin_comments_url 49 redirect_to admin_comments_url
65 end 50 end
66 51
52 def mass
53 if params[:mass_action] == "Delete"
54 Comment.destroy_by(id: params[:comment_ids])
55
56 flash.notice = "Comments successfully deleted."
57 elsif params[:mass_action] == "Mark Spam"
58 @comments = Comment.find(params[:comment_ids])
59
60 @comments.each do |comment|
61 perform_mark_spam(comment)
62 end
63
64 flash.notice = "Comments successfully marked as spam."
65 end
66
67 redirect_back fallback_location: pending_admin_comments_url
68 end
69
67 private 70 private
68 71
69 def set_section 72 def set_section
70 @section = "comments" 73 @section = "comments"
71 end 74 end
75
76 def perform_mark_spam(comment)
77 akismet_params = {
78 type: "comment",
79 text: comment.body,
80 created_at: comment.created_at,
81 author: comment.username,
82 author_email: comment.email,
83 author_url: comment.website,
84 post_url: url_for(comment.blog),
85 post_modified_at: comment.blog.updated_at,
86 referrer: comment.referrer
87 }
88
89 Akismet.spam comment.request_ip, comment.user_agent, akismet_params
90
91 comment.destroy!
92 end
72end 93end
diff --git a/app/views/admin/comments/pending.haml b/app/views/admin/comments/pending.haml index 3303457..5352b12 100644 --- a/app/views/admin/comments/pending.haml +++ b/app/views/admin/comments/pending.haml
@@ -1,26 +1,32 @@
1- title "Pending Comments" 1- title "Pending Comments"
2= will_paginate @comments 2= will_paginate @comments
3%table#entries 3= form_tag mass_admin_comments_url, method: :post do
4 %tr 4 #action-box
5 %th Text 5 = select_tag "mass_action", options_for_select(["Delete", "Mark Spam"]), include_blank: true
6 %th Author 6 = submit_tag "Mass action", data: { confirm: "Are you sure you want to do this action?" }
7 %th Blog post 7 %table#entries
8 %th Date updated 8 %tr
9 %th 9 %th= check_box_tag "check_all"
10 - @comments.each do |comment| 10 %th Text
11 %tr{ class: cycle("even", "odd") } 11 %th Author
12 %td= comment.body 12 %th Blog post
13 %td 13 %th Date updated
14 %ul 14 %th
15 %li= comment.username 15 - @comments.each do |comment|
16 %li= comment.email 16 %tr{ class: cycle("even", "odd") }
17 - unless comment.website.empty? 17 %td= check_box_tag "comment_ids[]", comment.id, class: "comment_ids"
18 %li= comment.website 18 %td= comment.body
19 %td= link_to comment.blog.title, comment.blog 19 %td
20 %td= comment.created_at.strftime("%B %d, %Y, %l:%M%P") 20 %ul
21 %td 21 %li= comment.username
22 %ul.admin-actions 22 %li= comment.email
23 %li= link_to "Accept", accept_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to accept this comment?" } 23 - unless comment.website.empty?
24 %li= link_to "Reject", reject_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to reject this comment?" } 24 %li= comment.website
25 %li= link_to "Mark Spam", mark_spam_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to mark this comment as spam?" } 25 %td= link_to comment.blog.title, comment.blog
26 %td= comment.created_at.strftime("%B %d, %Y, %l:%M%P")
27 %td
28 %ul.admin-actions
29 %li= link_to "Accept", accept_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to accept this comment?" }
30 %li= link_to "Reject", reject_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to reject this comment?" }
31 %li= link_to "Mark Spam", mark_spam_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to mark this comment as spam?" }
26= will_paginate @comments 32= will_paginate @comments
diff --git a/config/routes.rb b/config/routes.rb index 42158c9..3fffa35 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -19,6 +19,7 @@ Rails.application.routes.draw do
19 resources :comments, only: [:index, :destroy] do 19 resources :comments, only: [:index, :destroy] do
20 collection do 20 collection do
21 get 'pending' 21 get 'pending'
22 post 'mass'
22 end 23 end
23 24
24 member do 25 member do