From 9c73c87d28db0c5fef9ed20a4aaafc856b1b8750 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Tue, 6 Jan 2015 14:22:18 -0600 Subject: [PATCH] add story cache showing for manually-specified unavailable stories --- app/assets/stylesheets/application.css | 13 +++++++++- app/controllers/stories_controller.rb | 4 +-- app/indices/story_index.rb | 2 ++ app/models/story.rb | 21 ++++++++++++++++ app/views/stories/edit.html.erb | 7 ++++++ app/views/stories/show.html.erb | 25 +++++++++++++++++++ .../20150106195555_add_story_unavailable.rb | 5 ++++ db/schema.rb | 3 ++- 8 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20150106195555_add_story_unavailable.rb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 59a780b..7d7b4ad 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -619,17 +619,28 @@ div.story_text img { max-width: 100%; } +div#collapsed_story_text { + display: none; +} +a#story_text_expander { + display: block; +} + div.comment_text { max-width: 700px; } div.comment_text blockquote, -div.markdown_help blockquote { +div.markdown_help blockquote, +div.story_text blockquote { font-style: italic; margin: 0.25em 0 0 0.5em; padding: 0 0 0 1em; border-left: 2px solid gray; } +div#collapsed_story_text div.story_text blockquote { + font-style: normal; +} div.comment_text pre, div.markdown_help pre { margin-left: 1em; diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index e9adc73..4e9f002 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -257,13 +257,13 @@ private def story_params p = params.require(:story).permit( :title, :url, :description, :moderation_reason, :seen_previous, - :merge_story_short_id, :tags_a => [], + :merge_story_short_id, :is_unavailable, :tags_a => [], ) if @user.is_moderator? p else - p.except(:moderation_reason, :merge_story_short_id) + p.except(:moderation_reason, :merge_story_short_id, :is_unavailable) end end diff --git a/app/indices/story_index.rb b/app/indices/story_index.rb index b395f7d..c05c780 100644 --- a/app/indices/story_index.rb +++ b/app/indices/story_index.rb @@ -5,6 +5,7 @@ ThinkingSphinx::Index.define :story, :with => :active_record do indexes title indexes url indexes user.username, :as => :author + indexes story_cache has created_at, :sortable => true has hotness, is_expired @@ -15,6 +16,7 @@ ThinkingSphinx::Index.define :story, :with => :active_record do set_property :field_weights => { :upvotes => 15, :title => 10, + :story_cache => 10, :tags => 5, } diff --git a/app/models/story.rb b/app/models/story.rb index 3754004..2acb65f 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -295,6 +295,14 @@ class Story < ActiveRecord::Base self.created_at >= RECENT_DAYS.days.ago end + def is_unavailable + self.unavailable_at != nil + end + def is_unavailable=(what) + self.unavailable_at = (what.to_i == 1 && !self.is_unavailable ? + Time.now : nil) + end + def is_undeletable_by_user?(user) if user && user.is_moderator? return true @@ -311,6 +319,11 @@ class Story < ActiveRecord::Base end all_changes = self.changes.merge(self.tagging_changes) + all_changes.delete("unavailable_at") + + if !all_changes.any? + return + end m = Moderation.new m.moderator_user_id = self.editor.try(:id) @@ -441,6 +454,14 @@ class Story < ActiveRecord::Base self.short_id end + def update_availability + if self.is_unavailable && !self.unavailable_at + self.unavailable_at = Time.now + elsif self.unavailable_at && !self.is_unavailable + self.unavailable_at = nil + end + end + def update_comments_count! comments = self.merged_comments.arrange_for_user(nil) diff --git a/app/views/stories/edit.html.erb b/app/views/stories/edit.html.erb index 4221259..00d5644 100644 --- a/app/views/stories/edit.html.erb +++ b/app/views/stories/edit.html.erb @@ -17,6 +17,13 @@ :placeholder => "Short id of story into which this story " << "be merged" %> +
+ <%= f.label :unavailable_at, "Unavailable:", + :class => "required" %> + <%= f.check_box :is_unavailable %> + <%= f.label :unavailable_at, "Source URL is unavailable, " << + "enable display of cached text", :class => "normal" %> +
<% if @story.user_id != @user.id %>
<%= f.label :moderation_reason, "Mod Reason:", diff --git a/app/views/stories/show.html.erb b/app/views/stories/show.html.erb index 16e4378..7745cc6 100644 --- a/app/views/stories/show.html.erb +++ b/app/views/stories/show.html.erb @@ -9,6 +9,31 @@ <%= raw @story.markeddown_description %>
<% end %> + + <% if @story.is_unavailable && @story.story_cache.present? %> + Source URL considered unavailable as of <%= + time_ago_in_words_label(@story.unavailable_at) %> ago, cached text + available +
+

+ All story content copyright of its respective owner. +

+ +
+
+ <%= simple_format(@story.story_cache) %> +
+
+
+ + + <% end %> <% if !@story.previewing %> diff --git a/db/migrate/20150106195555_add_story_unavailable.rb b/db/migrate/20150106195555_add_story_unavailable.rb new file mode 100644 index 0000000..b25dcde --- /dev/null +++ b/db/migrate/20150106195555_add_story_unavailable.rb @@ -0,0 +1,5 @@ +class AddStoryUnavailable < ActiveRecord::Migration + def change + add_column :stories, :unavailable_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index c3e4020..fbe04bb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141114184921) do +ActiveRecord::Schema.define(version: 20150106195555) do create_table "comments", force: true do |t| t.datetime "created_at", null: false @@ -114,6 +114,7 @@ ActiveRecord::Schema.define(version: 20141114184921) do t.text "story_cache", limit: 16777215 t.integer "comments_count", default: 0, null: false t.integer "merged_story_id" + t.datetime "unavailable_at" end add_index "stories", ["hotness"], name: "hotness_idx", using: :btree