add story cache showing for manually-specified unavailable stories
This commit is contained in:
parent
5efe3ce6c3
commit
9c73c87d28
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -17,6 +17,13 @@
|
|||
:placeholder => "Short id of story into which this story " <<
|
||||
"be merged" %>
|
||||
</div>
|
||||
<div class="boxline">
|
||||
<%= 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" %>
|
||||
</div>
|
||||
<% if @story.user_id != @user.id %>
|
||||
<div class="boxline">
|
||||
<%= f.label :moderation_reason, "Mod Reason:",
|
||||
|
|
|
@ -9,6 +9,31 @@
|
|||
<%= raw @story.markeddown_description %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @story.is_unavailable && @story.story_cache.present? %>
|
||||
<a id="story_text_expander">Source URL considered unavailable as of <%=
|
||||
time_ago_in_words_label(@story.unavailable_at) %> ago, cached text
|
||||
available</a>
|
||||
<div id="collapsed_story_text">
|
||||
<p>
|
||||
<em>All story content copyright of its respective owner.</em>
|
||||
</p>
|
||||
|
||||
<div class="story_text">
|
||||
<blockquote>
|
||||
<%= simple_format(@story.story_cache) %>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById("story_text_expander").addEventListener("click",
|
||||
function() {
|
||||
document.getElementById("collapsed_story_text").style.display = "block";
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if !@story.previewing %>
|
||||
|
|
5
db/migrate/20150106195555_add_story_unavailable.rb
Normal file
5
db/migrate/20150106195555_add_story_unavailable.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddStoryUnavailable < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :stories, :unavailable_at, :datetime
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue