diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 569054498..627fcad92 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -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 { diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 263fff8f0..834cdda48 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index baf9df0d5..205ad10e1 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -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 »".html_safe, "#", :id => "child-relationship-preview-link") + html << link_to("show »".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 »".html_safe, "#", :id => "parent-relationship-preview-link") + html << link_to("show »".html_safe, "#", :id => "has-children-relationship-preview-link") html.html_safe end diff --git a/app/views/posts/partials/show/_notices.html.erb b/app/views/posts/partials/show/_notices.html.erb index 31f763675..73e21be68 100644 --- a/app/views/posts/partials/show/_notices.html.erb +++ b/app/views/posts/partials/show/_notices.html.erb @@ -48,15 +48,15 @@ <% if post.parent_id %>
- <%= belongs_to_parent_message(post, @child_post_set) %> -
<%= @child_post_set.presenter.post_previews_html(self) %>
+ <%= has_parent_message(post, @parent_post_set, @siblings_post_set) %> +
<%= @parent_post_set.presenter.post_previews_html(self) %><%= @siblings_post_set.presenter.post_previews_html(self) %>
<% end %> <% if post.has_children? %>
- <%= has_children_message(post, @parent_post_set) %> -
<%= @parent_post_set.presenter.post_previews_html(self) %>
+ <%= has_children_message(post, @children_post_set) %> +
<%= @children_post_set.presenter.post_previews_html(self) %>
<% end %>