From 0d50b1f18993827cb6862efeedea528b64fad164 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Oct 2023 13:24:24 -0400 Subject: Added quote moderation panel --- app/controllers/admin/quotes_controller.rb | 34 ++++++++++++++++++++++ app/helpers/admin/quotes_helper.rb | 2 ++ app/views/admin/quotes/index.html.haml | 20 +++++++++++++ app/views/admin/quotes/pending.html.haml | 20 +++++++++++++ app/views/layouts/admin.html.haml | 4 +++ .../quote_mailer/pending_quote_email.html.haml | 1 + .../quote_mailer/pending_quote_email.text.erb | 2 ++ 7 files changed, 83 insertions(+) create mode 100644 app/controllers/admin/quotes_controller.rb create mode 100644 app/helpers/admin/quotes_helper.rb create mode 100644 app/views/admin/quotes/index.html.haml create mode 100644 app/views/admin/quotes/pending.html.haml (limited to 'app') diff --git a/app/controllers/admin/quotes_controller.rb b/app/controllers/admin/quotes_controller.rb new file mode 100644 index 0000000..2c09627 --- /dev/null +++ b/app/controllers/admin/quotes_controller.rb @@ -0,0 +1,34 @@ +class Admin::QuotesController < Admin::AdminController + before_action :set_section + + def index + @quotes = Quote.published.order(id: :desc).paginate(page: params[:page], per_page: 20) + end + + def pending + @quotes = Quote.pending.order(id: :desc).paginate(page: params[:page], per_page: 20) + end + + def accept + @quote = Quote.find(params[:id]) + @quote.state = :published + @quote.save! + + flash.notice = "Quote successfully accepted." + redirect_to pending_admin_quotes_url + end + + def destroy + @quote = Quote.find(params[:id]) + @quote.destroy! + + flash.notice = "Quote successfully rejected." + redirect_to pending_admin_quotes_url + end + + private + + def set_section + @section = "quotes" + end +end diff --git a/app/helpers/admin/quotes_helper.rb b/app/helpers/admin/quotes_helper.rb new file mode 100644 index 0000000..3dde719 --- /dev/null +++ b/app/helpers/admin/quotes_helper.rb @@ -0,0 +1,2 @@ +module Admin::QuotesHelper +end diff --git a/app/views/admin/quotes/index.html.haml b/app/views/admin/quotes/index.html.haml new file mode 100644 index 0000000..afe2c20 --- /dev/null +++ b/app/views/admin/quotes/index.html.haml @@ -0,0 +1,20 @@ +- title "Quotes" += will_paginate @quotes +%table#entries + %tr + %th ID + %th Content + %th Submitter + %th Date submitted + %th + - @quotes.each do |quote| + %tr{ class: cycle("even", "odd") } + %td= quote.id + %td= quote_format(quote.content) + %td= quote.submitter + %td= quote.created_at.strftime("%B %d, %Y, %l:%M%P") + %td + %ul.admin-actions + %li= link_to "View", quote + %li= link_to "Delete", admin_quote_url(quote), method: :delete, data: { confirm: "Are you sure?" } += will_paginate @quotes diff --git a/app/views/admin/quotes/pending.html.haml b/app/views/admin/quotes/pending.html.haml new file mode 100644 index 0000000..14d6cf8 --- /dev/null +++ b/app/views/admin/quotes/pending.html.haml @@ -0,0 +1,20 @@ +- title "Pending Quotes" += will_paginate @quotes +%table#entries + %tr + %th ID + %th Content + %th Submitter + %th Date submitted + %th + - @quotes.each do |quote| + %tr{ class: cycle("even", "odd") } + %td= quote.id + %td= quote_format(quote.content) + %td= quote.submitter + %td= quote.created_at.strftime("%B %d, %Y, %l:%M%P") + %td + %ul.admin-actions + %li= link_to "Accept", accept_admin_quote_url(quote), method: :post, data: { confirm: "Are you sure you want to accept this quote?" } + %li= link_to "Reject", admin_quote_url(quote), method: :delete, data: { confirm: "Are you sure you want to reject this quote?" } += will_paginate @quotes diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 3949b5e..e3fc92f 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -41,5 +41,9 @@ = link_to "Comments", admin_comments_url, class: "major-link" %ul.minors %li.minor= link_to "Pending", pending_admin_comments_url + %li{major_sidebar_attrs("quotes")} + = link_to "Quotes", admin_quotes_url, class: "major-link" + %ul.minors + %li.minor= link_to "Pending", pending_admin_quotes_url #main = yield diff --git a/app/views/quote_mailer/pending_quote_email.html.haml b/app/views/quote_mailer/pending_quote_email.html.haml index fff825d..df72594 100644 --- a/app/views/quote_mailer/pending_quote_email.html.haml +++ b/app/views/quote_mailer/pending_quote_email.html.haml @@ -10,3 +10,4 @@ %p Submitted: = @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") +%p= link_to "Go to the admin panel", pending_admin_quotes_url diff --git a/app/views/quote_mailer/pending_quote_email.text.erb b/app/views/quote_mailer/pending_quote_email.text.erb index 818fc4a..b9d71bb 100644 --- a/app/views/quote_mailer/pending_quote_email.text.erb +++ b/app/views/quote_mailer/pending_quote_email.text.erb @@ -13,3 +13,5 @@ Here is the quote: --- Posted: <%= @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") %> + +Go to the admin panel: <%= pending_admin_quotes_url %> -- cgit 1.4.1