Class: Admin::FeedbackController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- BaseController
- Admin::FeedbackController
- Defined in:
- app/controllers/admin/feedback_controller.rb
Constant Summary collapse
- ONLY_DOMAIN =
%w(unapproved presumed_ham presumed_spam ham spam).freeze
Instance Method Summary collapse
- #article ⇒ Object
- #bulkops ⇒ Object
- #change_state ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #update ⇒ Object
Methods included from BlogHelper
Instance Method Details
#article ⇒ Object
74 75 76 77 78 79 |
# File 'app/controllers/admin/feedback_controller.rb', line 74 def article @article = this_blog.articles.find(params[:id]) @feedback = @article.comments @feedback = @feedback.ham if params[:ham] && params[:spam].blank? @feedback = @feedback.spam if params[:spam] && params[:ham].blank? end |
#bulkops ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/controllers/admin/feedback_controller.rb', line 96 def bulkops ids = (params[:feedback_check] || {}).keys.map(&:to_i) items = Feedback.find(ids) @unexpired = true bulkop = if (params[:bulkop_top] || {}).empty? params[:bulkop_bottom] else params[:bulkop_top] end case bulkop when "Delete Checked Items" count = 0 ids.each do |id| count += Feedback.delete(id) end flash[:success] = I18n.t("admin.feedback.bulkops.success_deleted", count: count) when "Mark Checked Items as Ham" update_feedback(items, :mark_as_ham!) flash[:success] = I18n.t("admin.feedback.bulkops.success_mark_as_ham", count: ids.size) when "Mark Checked Items as Spam" update_feedback(items, :mark_as_spam!) flash[:success] = I18n.t("admin.feedback.bulkops.success_mark_as_spam", count: ids.size) when "Confirm Classification of Checked Items" update_feedback(items, :confirm_classification!) flash[:success] = I18n.t("admin.feedback.bulkops.success_classification", count: ids.size) when "Delete all spam" if request.post? Feedback.where(state: "spam").delete_all flash[:success] = I18n.t("admin.feedback.bulkops.success_deleted_spam") end else flash[:error] = I18n.t("admin.feedback.bulkops.error") end if params[:article_id] redirect_to action: "article", id: params[:article_id], confirmed: params[:confirmed], published: params[:published] else redirect_to action: "index", page: params[:page], search: params[:search], confirmed: params[:confirmed], published: params[:published] end end |
#change_state ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/admin/feedback_controller.rb', line 81 def change_state return unless request.xhr? @feedback = Feedback.find(params[:id]) new_state = @feedback.change_state! respond_to do |format| if new_state == "ham" format.js { render "ham" } else format.js { render "spam" } end end end |
#create ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/admin/feedback_controller.rb', line 28 def create @article = Article.find(params[:article_id]) @comment = @article.comments.build(comment_params) @comment.user_id = current_user.id if request.post? && @comment.save # We should probably wave a spam filter over this, but for now, just mark # it as published. @comment.mark_as_ham @comment.save! flash[:success] = I18n.t("admin.feedback.create.success") end redirect_to action: "article", id: @article.id end |
#destroy ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/admin/feedback_controller.rb', line 58 def destroy @record = Feedback.find params[:id] unless @record.article.user_id == current_user.id return redirect_to admin_feedback_index_url unless current_user.admin? end begin @record.destroy flash[:success] = I18n.t("admin.feedback.destroy.success") rescue ActiveRecord::RecordNotFound flash[:error] = I18n.t("admin.feedback.destroy.error") end redirect_to action: "article", id: @record.article.id end |
#edit ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/controllers/admin/feedback_controller.rb', line 19 def edit @comment = Comment.find(params[:id]) @article = @comment.article unless @article.access_by? current_user redirect_to admin_feedback_index_url nil end end |
#index ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/admin/feedback_controller.rb', line 6 def index scoped_feedback = this_blog.feedback if params[:only].present? @only_param = ONLY_DOMAIN.dup.delete(params[:only]) scoped_feedback = scoped_feedback.send(@only_param) if @only_param end params.delete(:page) if params[:page].blank? || params[:page] == "0" @feedback = scoped_feedback.paginated(params[:page], this_blog.admin_display_elements) end |
#update ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/admin/feedback_controller.rb', line 43 def update comment = Comment.find(params[:id]) unless comment.article.access_by? current_user redirect_to admin_feedback_index_url return end comment.attributes = comment_params if request.post? && comment.save flash[:success] = I18n.t("admin.feedback.update.success") redirect_to action: "article", id: comment.article.id else redirect_to action: "edit", id: comment.id end end |