about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-21 22:52:41 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-21 22:52:41 -0400
commit20f2479b33bc548c4736cdc1ceffde6e3af3a31d (patch)
treefcc7416ee5cc9302235fb47b716298d254343433
parent41155441c9412ab0dba0b62f606cdef5488343f1 (diff)
downloadthoughts-20f2479b33bc548c4736cdc1ceffde6e3af3a31d.tar.gz
thoughts-20f2479b33bc548c4736cdc1ceffde6e3af3a31d.tar.bz2
thoughts-20f2479b33bc548c4736cdc1ceffde6e3af3a31d.zip
Added quote editing
-rw-r--r--app/assets/stylesheets/admin/layout.scss13
-rw-r--r--app/controllers/admin/quotes_controller.rb20
-rw-r--r--app/views/admin/quotes/_form.html.haml27
-rw-r--r--app/views/admin/quotes/edit.html.haml3
-rw-r--r--app/views/admin/quotes/index.html.haml1
-rw-r--r--app/views/admin/quotes/pending.html.haml1
-rw-r--r--app/views/layouts/quotes.html.haml4
-rw-r--r--app/views/quotes/_quote.html.haml2
-rw-r--r--config/routes.rb2
9 files changed, 71 insertions, 2 deletions
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index dbf84d2..f0017ed 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss
@@ -152,6 +152,19 @@ body {
152 height: 100%; 152 height: 100%;
153 } 153 }
154 } 154 }
155
156 .halfbody-field {
157 height: 40%;
158
159 label {
160 display: none;
161 }
162
163 textarea {
164 width: 100%;
165 height: 100%;
166 }
167 }
155} 168}
156 169
157#entries { 170#entries {
diff --git a/app/controllers/admin/quotes_controller.rb b/app/controllers/admin/quotes_controller.rb index 2c09627..70a541f 100644 --- a/app/controllers/admin/quotes_controller.rb +++ b/app/controllers/admin/quotes_controller.rb
@@ -9,6 +9,22 @@ class Admin::QuotesController < Admin::AdminController
9 @quotes = Quote.pending.order(id: :desc).paginate(page: params[:page], per_page: 20) 9 @quotes = Quote.pending.order(id: :desc).paginate(page: params[:page], per_page: 20)
10 end 10 end
11 11
12 def edit
13 @quote = Quote.find(params[:id])
14 end
15
16 def update
17 @quote = Quote.find(params[:id])
18
19 if @quote.update(quote_params)
20 flash[:notice] = "Quote was successfully updated."
21 else
22 flash[:error] = "Error updating quote."
23 end
24
25 render :edit
26 end
27
12 def accept 28 def accept
13 @quote = Quote.find(params[:id]) 29 @quote = Quote.find(params[:id])
14 @quote.state = :published 30 @quote.state = :published
@@ -31,4 +47,8 @@ class Admin::QuotesController < Admin::AdminController
31 def set_section 47 def set_section
32 @section = "quotes" 48 @section = "quotes"
33 end 49 end
50
51 def quote_params
52 params.require(:quote).permit(:content, :state, :notes, :submitter, :tag_list)
53 end
34end 54end
diff --git a/app/views/admin/quotes/_form.html.haml b/app/views/admin/quotes/_form.html.haml new file mode 100644 index 0000000..920835b --- /dev/null +++ b/app/views/admin/quotes/_form.html.haml
@@ -0,0 +1,27 @@
1%fieldset#content
2 %h2 Quote ##{f.object.id}
3 .halfbody-field
4 = f.label :content
5 = f.text_area :content
6 %h3 Notes
7 .halfbody-field
8 = f.label :notes
9 = f.text_area :notes
10%fieldset#details
11 - if f.object.errors.any?
12 #errors.details-module
13 %h3 Error!
14 %ul
15 - f.object.errors.full_messages.each do |error|
16 %li= error
17 - unless f.object.new_record?
18 #entry-preview-link.details-module= link_to "View quote", quote_url(f.object.id), target: "entry-preview"
19 .details-module
20 .tags-field
21 = f.label :tag_list, "Tags"
22 = f.text_field :tag_list, type: :tags, value: f.object.tag_list.join(",")
23 .details-module
24 .published-field
25 = f.label :state
26 = f.select :state, Quote.state.options
27 .details-module= f.submit
diff --git a/app/views/admin/quotes/edit.html.haml b/app/views/admin/quotes/edit.html.haml new file mode 100644 index 0000000..47ff2d1 --- /dev/null +++ b/app/views/admin/quotes/edit.html.haml
@@ -0,0 +1,3 @@
1- title "Editing Quote \##{@quote.id}"
2= form_for @quote, url: admin_quote_url(@quote.id), html: { id: "entry-form" } do |f|
3 = render partial: "form", locals: { f: f }
diff --git a/app/views/admin/quotes/index.html.haml b/app/views/admin/quotes/index.html.haml index afe2c20..c1a4866 100644 --- a/app/views/admin/quotes/index.html.haml +++ b/app/views/admin/quotes/index.html.haml
@@ -16,5 +16,6 @@
16 %td 16 %td
17 %ul.admin-actions 17 %ul.admin-actions
18 %li= link_to "View", quote 18 %li= link_to "View", quote
19 %li= link_to "Edit", edit_admin_quote_url(quote)
19 %li= link_to "Delete", admin_quote_url(quote), method: :delete, data: { confirm: "Are you sure?" } 20 %li= link_to "Delete", admin_quote_url(quote), method: :delete, data: { confirm: "Are you sure?" }
20= will_paginate @quotes 21= will_paginate @quotes
diff --git a/app/views/admin/quotes/pending.html.haml b/app/views/admin/quotes/pending.html.haml index 14d6cf8..ef52099 100644 --- a/app/views/admin/quotes/pending.html.haml +++ b/app/views/admin/quotes/pending.html.haml
@@ -15,6 +15,7 @@
15 %td= quote.created_at.strftime("%B %d, %Y, %l:%M%P") 15 %td= quote.created_at.strftime("%B %d, %Y, %l:%M%P")
16 %td 16 %td
17 %ul.admin-actions 17 %ul.admin-actions
18 %li= link_to "Edit", edit_admin_quote_url(quote)
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 "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 %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 21= will_paginate @quotes
diff --git a/app/views/layouts/quotes.html.haml b/app/views/layouts/quotes.html.haml index f42eee0..98a7a86 100644 --- a/app/views/layouts/quotes.html.haml +++ b/app/views/layouts/quotes.html.haml
@@ -11,7 +11,7 @@
11 %body 11 %body
12 #wrap 12 #wrap
13 %header#banner 13 %header#banner
14 %h1#banner-title= link_to "The Four Island Quotes DB", root_path 14 %h1#banner-title= link_to "The Four Island Quotes DB", quotes_url
15 #banner-abbr FIQDB 15 #banner-abbr FIQDB
16 .cleardiv 16 .cleardiv
17 %nav#top-bar 17 %nav#top-bar
@@ -25,6 +25,8 @@
25 %li= link_to_unless_current "Tags", tags_quotes_url 25 %li= link_to_unless_current "Tags", tags_quotes_url
26 %li= link_to_unless_current "Stats", stats_quotes_url 26 %li= link_to_unless_current "Stats", stats_quotes_url
27 %li= link_to_unless_current "Feed", latest_quotes_url(:atom) 27 %li= link_to_unless_current "Feed", latest_quotes_url(:atom)
28 - if user_signed_in?
29 %li= link_to_unless_current "Admin", admin_url
28 .cleardiv 30 .cleardiv
29 #page-body 31 #page-body
30 - if flash[:notice] 32 - if flash[:notice]
diff --git a/app/views/quotes/_quote.html.haml b/app/views/quotes/_quote.html.haml index 2a9fb37..46b0266 100644 --- a/app/views/quotes/_quote.html.haml +++ b/app/views/quotes/_quote.html.haml
@@ -5,6 +5,8 @@
5 %span.quote-rating{ :id => "quote-rating-#{quote.id}" }= "+#{quote.upvotes}/-#{quote.downvotes}" 5 %span.quote-rating{ :id => "quote-rating-#{quote.id}" }= "+#{quote.upvotes}/-#{quote.downvotes}"
6 %span.vote-link{ :id => "quote-downvote-link-#{quote.id}" }= link_to_unless (quote.new_record? or quote.already_downvoted?(request.remote_ip)), "Down", downvote_quote_path(quote.id), :remote => true, :rel => "nofollow", :class => "quote-downvote-link", method: :post 6 %span.vote-link{ :id => "quote-downvote-link-#{quote.id}" }= link_to_unless (quote.new_record? or quote.already_downvoted?(request.remote_ip)), "Down", downvote_quote_path(quote.id), :remote => true, :rel => "nofollow", :class => "quote-downvote-link", method: :post
7 %datetime= quote.published_date 7 %datetime= quote.published_date
8 - if user_signed_in? and !quote.new_record?
9 = link_to "Edit", edit_admin_quote_path(quote), :class => "quote-edit-link"
8 %blockquote.quote-body= raw quote_format(h(quote.content)) 10 %blockquote.quote-body= raw quote_format(h(quote.content))
9 - if !quote.new_record? and quote.has_extra? 11 - if !quote.new_record? and quote.has_extra?
10 .quote-footer 12 .quote-footer
diff --git a/config/routes.rb b/config/routes.rb index 59589aa..1671d54 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -28,7 +28,7 @@ Rails.application.routes.draw do
28 end 28 end
29 end 29 end
30 30
31 resources :quotes, only: [:index, :destroy] do 31 resources :quotes do
32 collection do 32 collection do
33 get 'pending' 33 get 'pending'
34 end 34 end