about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-07-04 10:42:21 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-07-04 10:42:21 -0400
commitd48adb741c5c30ba3f2d3c039a7e342b43add352 (patch)
treecbc25ac929e73702142a5ec5728a98dc54d88602 /app
parent66353403efcc9c0b16c82ea8ab9860ca8a44aa4c (diff)
downloadthoughts-d48adb741c5c30ba3f2d3c039a7e342b43add352.tar.gz
thoughts-d48adb741c5c30ba3f2d3c039a7e342b43add352.tar.bz2
thoughts-d48adb741c5c30ba3f2d3c039a7e342b43add352.zip
Added blog drafts
An unpublished post is not viewable unless you are logged in. The "Create record" field is disabled for unpublished posts, though this is only in JavaScript and the backend will not disallow creating records for unpublished posts if forced to. Unpublishing a post does not destroy records for that post.

This only applies to blog posts, currently; streams and stream updates cannot be drafted. Unpublished posts still require titles and slugs. There is no autosaving functionality yet.

refs #1
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/admin/records.coffee24
-rw-r--r--app/assets/stylesheets/admin/layout.scss6
-rw-r--r--app/controllers/admin/blogs_controller.rb8
-rw-r--r--app/controllers/blogs_controller.rb3
-rw-r--r--app/models/blog.rb21
-rw-r--r--app/views/admin/blogs/_form.html.haml4
-rw-r--r--app/views/admin/blogs/drafts.html.haml10
-rw-r--r--app/views/admin/blogs/index.html.haml4
-rw-r--r--app/views/blogs/show.html.haml2
-rw-r--r--app/views/layouts/admin.html.haml1
10 files changed, 74 insertions, 9 deletions
diff --git a/app/assets/javascripts/admin/records.coffee b/app/assets/javascripts/admin/records.coffee index 69cd471..3a1ed51 100644 --- a/app/assets/javascripts/admin/records.coffee +++ b/app/assets/javascripts/admin/records.coffee
@@ -1,9 +1,25 @@
1# Place all the behaviors and hooks related to the matching controller here. 1# Place all the behaviors and hooks related to the matching controller here.
2# All this logic will automatically be available in application.js. 2# All this logic will automatically be available in application.js.
3# You can use CoffeeScript in this file: http://coffeescript.org/ 3# You can use CoffeeScript in this file: http://coffeescript.org/
4
5create_record_toggle = (checked) ->
6 if checked
7 $(".record-description-field").show()
8 else
9 $(".record-description-field").hide()
10
11published_field_toggle = (checked) ->
12 if checked
13 $(".should-create-record-field input[type=checkbox]").prop("disabled", false)
14 else
15 $(".should-create-record-field input[type=checkbox]").prop("disabled", true)
16 $(".should-create-record-field input[type=checkbox]").prop("checked", false)
17 create_record_toggle(false)
18
4$(document).on "turbolinks:load", -> 19$(document).on "turbolinks:load", ->
20 if $(".published-field").length > 0
21 published_field_toggle($(".published-field input[type=checkbox]").prop("checked"))
5 $(".should-create-record-field input[type=checkbox]").change -> 22 $(".should-create-record-field input[type=checkbox]").change ->
6 if $(".should-create-record-field input[type=checkbox]").prop("checked") 23 create_record_toggle($(this).prop("checked"))
7 $(".record-description-field").show() 24 $(".published-field input[type=checkbox]").change ->
8 else 25 published_field_toggle($(this).prop("checked"))
9 $(".record-description-field").hide()
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index 6645709..f68cf6a 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss
@@ -190,6 +190,12 @@ body {
190 } 190 }
191} 191}
192 192
193.published-field {
194 label {
195 font-size: .75em;
196 }
197}
198
193.record-description-field { 199.record-description-field {
194 display: none; 200 display: none;
195 margin-top: 1em; 201 margin-top: 1em;
diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index fa46ab8..9706df3 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb
@@ -2,7 +2,11 @@ class Admin::BlogsController < Admin::AdminController
2 before_action :set_section 2 before_action :set_section
3 3
4 def index 4 def index
5 @blogs = Blog.order(created_at: :desc) 5 @blogs = Blog.where(published: true).order(published_at: :desc)
6 end
7
8 def drafts
9 @blogs = Blog.where(published: false).order(updated_at: :desc)
6 end 10 end
7 11
8 def new 12 def new
@@ -42,7 +46,7 @@ class Admin::BlogsController < Admin::AdminController
42 private 46 private
43 47
44 def blog_params 48 def blog_params
45 params.require(:blog).permit(:title, :body, :slug, records_attributes: [:description, :_destroy]) 49 params.require(:blog).permit(:title, :body, :slug, :published, records_attributes: [:description, :_destroy])
46 end 50 end
47 51
48 def set_section 52 def set_section
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 5e72601..f31287b 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb
@@ -2,6 +2,9 @@ class BlogsController < ApplicationController
2 2
3 def show 3 def show
4 @blog = Blog.find_by_slug(params[:slug]) 4 @blog = Blog.find_by_slug(params[:slug])
5
6 raise ActiveRecord::RecordNotFound unless @blog
7 raise ActiveRecord::RecordNotFound unless @blog.published or user_signed_in?
5 end 8 end
6 9
7end 10end
diff --git a/app/models/blog.rb b/app/models/blog.rb index 1ace11b..495c6eb 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb
@@ -6,7 +6,28 @@ class Blog < ApplicationRecord
6 6
7 accepts_nested_attributes_for :records, allow_destroy: true 7 accepts_nested_attributes_for :records, allow_destroy: true
8 8
9 before_save :set_published_at
10
9 def path 11 def path
10 "/says/#{slug}" 12 "/says/#{slug}"
11 end 13 end
14
15 def posted_at
16 if published
17 published_at
18 else
19 updated_at
20 end
21 end
22
23 private
24 def set_published_at
25 if self.published
26 if self.published_at.blank?
27 self.published_at = DateTime.now
28 end
29 else
30 self.published_at = nil
31 end
32 end
12end 33end
diff --git a/app/views/admin/blogs/_form.html.haml b/app/views/admin/blogs/_form.html.haml index 4a1c410..2066aed 100644 --- a/app/views/admin/blogs/_form.html.haml +++ b/app/views/admin/blogs/_form.html.haml
@@ -16,6 +16,10 @@
16 - f.object.errors.full_messages.each do |error| 16 - f.object.errors.full_messages.each do |error|
17 %li= error 17 %li= error
18 .details-module 18 .details-module
19 .published-field
20 = f.check_box :published
21 = f.label :published
22 .details-module
19 = f.fields_for :records, Record.new do |builder| 23 = f.fields_for :records, Record.new do |builder|
20 .should-create-record-field 24 .should-create-record-field
21 = builder.check_box :_destroy, {checked: false}, "0", "1" 25 = builder.check_box :_destroy, {checked: false}, "0", "1"
diff --git a/app/views/admin/blogs/drafts.html.haml b/app/views/admin/blogs/drafts.html.haml new file mode 100644 index 0000000..91d3214 --- /dev/null +++ b/app/views/admin/blogs/drafts.html.haml
@@ -0,0 +1,10 @@
1%table#entries
2 %tr
3 %th Title
4 %th Last updated
5 %th
6 - @blogs.each do |blog|
7 %tr{ class: cycle("even", "odd") }
8 %td= blog.title
9 %td= blog.updated_at.strftime("%B %d, %Y, %l:%M%P")
10 %td= link_to "Edit", edit_admin_blog_url(blog)
diff --git a/app/views/admin/blogs/index.html.haml b/app/views/admin/blogs/index.html.haml index 448617a..c5db4f1 100644 --- a/app/views/admin/blogs/index.html.haml +++ b/app/views/admin/blogs/index.html.haml
@@ -1,10 +1,10 @@
1%table#entries 1%table#entries
2 %tr 2 %tr
3 %th Title 3 %th Title
4 %th Date created 4 %th Date published
5 %th 5 %th
6 - @blogs.each do |blog| 6 - @blogs.each do |blog|
7 %tr{ class: cycle("even", "odd") } 7 %tr{ class: cycle("even", "odd") }
8 %td= blog.title 8 %td= blog.title
9 %td= blog.created_at.strftime("%B %d, %Y, %l:%M%P") 9 %td= blog.published_at.strftime("%B %d, %Y, %l:%M%P")
10 %td= link_to "Edit", edit_admin_blog_url(blog) 10 %td= link_to "Edit", edit_admin_blog_url(blog)
diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index c44d3f4..48c07dc 100644 --- a/app/views/blogs/show.html.haml +++ b/app/views/blogs/show.html.haml
@@ -3,4 +3,4 @@
3%footer#blog-footer 3%footer#blog-footer
4 This entry was posted on 4 This entry was posted on
5 = succeed "." do 5 = succeed "." do
6 %time= @blog.created_at.strftime("%B #{@blog.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") 6 %time= @blog.posted_at.strftime("%B #{@blog.posted_at.day.ordinalize}, %Y at %-I:%M:%S%P")
diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 68bbd96..cb48c50 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml
@@ -24,6 +24,7 @@
24 = link_to "Blogs", admin_blogs_url, class: "major-link" 24 = link_to "Blogs", admin_blogs_url, class: "major-link"
25 %ul.minors 25 %ul.minors
26 %li.minor= link_to "New blog", new_admin_blog_url 26 %li.minor= link_to "New blog", new_admin_blog_url
27 %li.minor= link_to "Drafts", drafts_admin_blogs_url
27 %li{major_sidebar_attrs("streams")} 28 %li{major_sidebar_attrs("streams")}
28 = link_to "Streams", admin_streams_url, class: "major-link" 29 = link_to "Streams", admin_streams_url, class: "major-link"
29 %ul.minors 30 %ul.minors