about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/quotes_controller.rb34
-rw-r--r--app/helpers/admin/quotes_helper.rb2
-rw-r--r--app/views/admin/quotes/index.html.haml20
-rw-r--r--app/views/admin/quotes/pending.html.haml20
-rw-r--r--app/views/layouts/admin.html.haml4
-rw-r--r--app/views/quote_mailer/pending_quote_email.html.haml1
-rw-r--r--app/views/quote_mailer/pending_quote_email.text.erb2
-rw-r--r--config/routes.rb10
-rw-r--r--test/controllers/admin/quotes_controller_test.rb13
9 files changed, 106 insertions, 0 deletions
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 @@
1class Admin::QuotesController < Admin::AdminController
2 before_action :set_section
3
4 def index
5 @quotes = Quote.published.order(id: :desc).paginate(page: params[:page], per_page: 20)
6 end
7
8 def pending
9 @quotes = Quote.pending.order(id: :desc).paginate(page: params[:page], per_page: 20)
10 end
11
12 def accept
13 @quote = Quote.find(params[:id])
14 @quote.state = :published
15 @quote.save!
16
17 flash.notice = "Quote successfully accepted."
18 redirect_to pending_admin_quotes_url
19 end
20
21 def destroy
22 @quote = Quote.find(params[:id])
23 @quote.destroy!
24
25 flash.notice = "Quote successfully rejected."
26 redirect_to pending_admin_quotes_url
27 end
28
29 private
30
31 def set_section
32 @section = "quotes"
33 end
34end
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 @@
1module Admin::QuotesHelper
2end
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 @@
1- title "Quotes"
2= will_paginate @quotes
3%table#entries
4 %tr
5 %th ID
6 %th Content
7 %th Submitter
8 %th Date submitted
9 %th
10 - @quotes.each do |quote|
11 %tr{ class: cycle("even", "odd") }
12 %td= quote.id
13 %td= quote_format(quote.content)
14 %td= quote.submitter
15 %td= quote.created_at.strftime("%B %d, %Y, %l:%M%P")
16 %td
17 %ul.admin-actions
18 %li= link_to "View", quote
19 %li= link_to "Delete", admin_quote_url(quote), method: :delete, data: { confirm: "Are you sure?" }
20= 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 @@
1- title "Pending Quotes"
2= will_paginate @quotes
3%table#entries
4 %tr
5 %th ID
6 %th Content
7 %th Submitter
8 %th Date submitted
9 %th
10 - @quotes.each do |quote|
11 %tr{ class: cycle("even", "odd") }
12 %td= quote.id
13 %td= quote_format(quote.content)
14 %td= quote.submitter
15 %td= quote.created_at.strftime("%B %d, %Y, %l:%M%P")
16 %td
17 %ul.admin-actions
18 %li= link_to "Accept", accept_admin_quote_url(quote), method: :post, data: { confirm: "Are you sure you want to accept this quote?" }
19 %li= link_to "Reject", admin_quote_url(quote), method: :delete, data: { confirm: "Are you sure you want to reject this quote?" }
20= 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 @@
41 = link_to "Comments", admin_comments_url, class: "major-link" 41 = link_to "Comments", admin_comments_url, class: "major-link"
42 %ul.minors 42 %ul.minors
43 %li.minor= link_to "Pending", pending_admin_comments_url 43 %li.minor= link_to "Pending", pending_admin_comments_url
44 %li{major_sidebar_attrs("quotes")}
45 = link_to "Quotes", admin_quotes_url, class: "major-link"
46 %ul.minors
47 %li.minor= link_to "Pending", pending_admin_quotes_url
44 #main 48 #main
45 = yield 49 = 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 @@
10%p 10%p
11 Submitted: 11 Submitted:
12 = @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") 12 = @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P")
13%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:
13--- 13---
14 14
15Posted: <%= @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") %> 15Posted: <%= @quote.created_at.strftime("%B #{@quote.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") %>
16
17Go to the admin panel: <%= pending_admin_quotes_url %>
diff --git a/config/routes.rb b/config/routes.rb index 493102b..7e22946 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -27,6 +27,16 @@ Rails.application.routes.draw do
27 post 'mark_spam' 27 post 'mark_spam'
28 end 28 end
29 end 29 end
30
31 resources :quotes, only: [:index, :destroy] do
32 collection do
33 get 'pending'
34 end
35
36 member do
37 post 'accept'
38 end
39 end
30 end 40 end
31 41
32 devise_for :users, controllers: { 42 devise_for :users, controllers: {
diff --git a/test/controllers/admin/quotes_controller_test.rb b/test/controllers/admin/quotes_controller_test.rb new file mode 100644 index 0000000..4f5939b --- /dev/null +++ b/test/controllers/admin/quotes_controller_test.rb
@@ -0,0 +1,13 @@
1require "test_helper"
2
3class Admin::QuotesControllerTest < ActionDispatch::IntegrationTest
4 test "should get index" do
5 get admin_quotes_index_url
6 assert_response :success
7 end
8
9 test "should get pending" do
10 get admin_quotes_pending_url
11 assert_response :success
12 end
13end