Additionally:
* Rename methods and variables related to the parent/child previews for
consistency.
* Split off siblings into a separate post set.
* Increase limit of children/siblings displayed to max of 200.
This commit is contained in:
Toks
2013-04-29 16:56:54 -04:00
parent aee7bbee0f
commit 4775535c11
4 changed files with 30 additions and 20 deletions

View File

@@ -137,12 +137,15 @@
}
Danbooru.Post.initialize_post_relationship_previews = function() {
$("#parent-relationship-preview").hide();
$("#child-relationship-preview").hide();
var current_post_id = $("meta[name=post-id]").attr("content");
$("#post_" + current_post_id).css("background-color", "rgba(0,0,0,0.05)");
$("#parent-relationship-preview-link").click(function(e) {
$("#parent-relationship-preview").toggle();
if ($("#parent-relationship-preview").is(":visible")) {
$("#has-children-relationship-preview").hide();
$("#has-parent-relationship-preview").hide();
$("#has-children-relationship-preview-link").click(function(e) {
$("#has-children-relationship-preview").toggle();
if ($("#has-children-relationship-preview").is(":visible")) {
$(this).html("« hide");
}
else {
@@ -151,9 +154,9 @@
e.preventDefault();
});
$("#child-relationship-preview-link").click(function(e) {
$("#child-relationship-preview").toggle();
if ($("#child-relationship-preview").is(":visible")) {
$("#has-parent-relationship-preview-link").click(function(e) {
$("#has-parent-relationship-preview").toggle();
if ($("#has-parent-relationship-preview").is(":visible")) {
$(this).html("« hide");
}
else {

View File

@@ -22,8 +22,9 @@ class PostsController < ApplicationController
@post = Post.find(params[:id])
@post_flag = PostFlag.new(:post_id => @post.id)
@post_appeal = PostAppeal.new(:post_id => @post.id)
@parent_post_set = PostSets::Post.new("parent:#{@post.id} -id:#{@post.id}")
@child_post_set = PostSets::Post.new("id:#{@post.parent_id} status:any")
@children_post_set = PostSets::Post.new("parent:#{@post.id} -id:#{@post.id}", 1, 200)
@parent_post_set = PostSets::Post.new("id:#{@post.parent_id} status:any")
@siblings_post_set = PostSets::Post.new("parent:#{@post.parent_id} -id:#{@post.parent_id}", 1, 200)
respond_with(@post)
end

View File

@@ -41,30 +41,36 @@ module PostsHelper
end
end
def belongs_to_parent_message(post, child_post_set)
def has_parent_message(post, parent_post_set, siblings_post_set)
html = ""
html << "This post belongs to a "
html << link_to("parent", post_path(post.parent_id))
html << " (deleted)" if child_post_set.posts.first.is_deleted?
html << " (deleted)" if parent_post_set.posts.first.is_deleted?
if siblings_post_set.posts.count > 1
html << " and has "
text = siblings_post_set.posts.count > 2 ? "#{siblings_post_set.posts.count - 1} siblings" : "a sibling"
html << link_to(text, posts_path(:tags => "parent:#{post.parent_id}"))
end
html << " (#{link_to("learn more", wiki_pages_path(:title => "help:post_relationships"))}) "
html << link_to("show &raquo;".html_safe, "#", :id => "child-relationship-preview-link")
html << link_to("show &raquo;".html_safe, "#", :id => "has-parent-relationship-preview-link")
html.html_safe
end
def has_children_message(post, parent_post_set)
def has_children_message(post, children_post_set)
html = ""
html << "This post has "
text = parent_post_set.posts.count == 1 ? "a child" : "#{parent_post_set.posts.count} children"
text = children_post_set.posts.count == 1 ? "a child" : "#{children_post_set.posts.count} children"
html << link_to(text, posts_path(:tags => "parent:#{post.id}"))
html << " (#{link_to("learn more", wiki_pages_path(:title => "help:post_relationships"))}) "
html << link_to("show &raquo;".html_safe, "#", :id => "parent-relationship-preview-link")
html << link_to("show &raquo;".html_safe, "#", :id => "has-children-relationship-preview-link")
html.html_safe
end

View File

@@ -48,15 +48,15 @@
<% if post.parent_id %>
<div class="ui-corner-all ui-state-highlight notice notice-child">
<%= belongs_to_parent_message(post, @child_post_set) %>
<div id="child-relationship-preview"><%= @child_post_set.presenter.post_previews_html(self) %></div>
<%= has_parent_message(post, @parent_post_set, @siblings_post_set) %>
<div id="has-parent-relationship-preview"><%= @parent_post_set.presenter.post_previews_html(self) %><%= @siblings_post_set.presenter.post_previews_html(self) %></div>
</div>
<% end %>
<% if post.has_children? %>
<div class="ui-corner-all ui-state-highlight notice notice-parent">
<%= has_children_message(post, @parent_post_set) %>
<div id="parent-relationship-preview"><%= @parent_post_set.presenter.post_previews_html(self) %></div>
<%= has_children_message(post, @children_post_set) %>
<div id="has-children-relationship-preview"><%= @children_post_set.presenter.post_previews_html(self) %></div>
</div>
<% end %>