From d365294db7edd79f01b51ac30413707a556f84bb Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 13 Oct 2023 13:13:28 -0400 Subject: Added pending comment page to admin panel --- app/controllers/admin/comments_controller.rb | 24 +++++++++++++++++++++++- app/views/admin/comments/pending.haml | 25 +++++++++++++++++++++++++ app/views/layouts/admin.html.haml | 2 ++ config/routes.rb | 11 ++++++++++- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 app/views/admin/comments/pending.haml diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index bd255ad..ccde3e6 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -2,7 +2,29 @@ class Admin::CommentsController < Admin::AdminController before_action :set_section def index - @comments = Comment.order(updated_at: :desc).paginate(page: params[:page], per_page: 20) + @comments = Comment.where(status: :published).order(updated_at: :desc).paginate(page: params[:page], per_page: 20) + end + + def pending + @comments = Comment.where(status: :pending).order(updated_at: :desc).paginate(page: params[:page], per_page: 20) + end + + def accept + @comment = Comment.find(params[:id]) + @comment.status = :published + @comment.save! + + flash.notice = "Comment successfully published." + redirect_to pending_admin_comments_url + end + + def reject + @comment = Comment.find(params[:id]) + @comment.status = :rejected + @comment.save! + + flash.notice = "Comment successfully rejected." + redirect_to pending_admin_comments_url end def destroy diff --git a/app/views/admin/comments/pending.haml b/app/views/admin/comments/pending.haml new file mode 100644 index 0000000..6abf371 --- /dev/null +++ b/app/views/admin/comments/pending.haml @@ -0,0 +1,25 @@ +- title "Pending Comments" += will_paginate @comments +%table#entries + %tr + %th Text + %th Author + %th Blog post + %th Date updated + %th + - @comments.each do |comment| + %tr{ class: cycle("even", "odd") } + %td= comment.body + %td + %ul + %li= comment.username + %li= comment.email + - unless comment.website.empty? + %li= comment.website + %td= link_to comment.blog.title, comment.blog + %td= comment.published_at.strftime("%B %d, %Y, %l:%M%P") + %td + %ul.admin-actions + %li= link_to "Accept", accept_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to accept this comment?" } + %li= link_to "Reject", reject_admin_comment_url(comment), method: :post, data: { confirm: "Are you sure you want to reject this comment?" } += will_paginate @comments diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 0f54183..3949b5e 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -39,5 +39,7 @@ %li.minor= link_to "New game", new_admin_game_url %li{major_sidebar_attrs("comments")} = link_to "Comments", admin_comments_url, class: "major-link" + %ul.minors + %li.minor= link_to "Pending", pending_admin_comments_url #main = yield diff --git a/config/routes.rb b/config/routes.rb index 5aa1558..4b68dc3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,16 @@ Rails.application.routes.draw do resources :games, except: [:show] - resources :comments, only: [:index, :destroy] + resources :comments, only: [:index, :destroy] do + collection do + get 'pending' + end + + member do + post 'accept' + post 'reject' + end + end end devise_for :users, controllers: { -- cgit 1.4.1