add tag seq nav

This commit is contained in:
albert
2013-02-25 12:09:02 -05:00
parent 2aa141aa69
commit c6d03f2d3a
10 changed files with 81 additions and 13 deletions

View File

@@ -50,18 +50,26 @@
} }
Danbooru.Post.nav_pool_prev = function() { Danbooru.Post.nav_pool_prev = function() {
location.href = $("#pool-nav a.active[rel=prev]").attr("href"); if ($("#tag-seq-nav").length) {
location.href = $("#tag-seq-nav a[rel=prev]").attr("href");
} else {
location.href = $("#pool-nav a.active[rel=prev]").attr("href");
}
} }
Danbooru.Post.nav_pool_next = function() { Danbooru.Post.nav_pool_next = function() {
location.href = $("#pool-nav a.active[rel=next]").attr("href"); if ($("#tag-seq-nav").length) {
location.href = $("#tag-seq-nav a[rel=next]").attr("href");
} else {
location.href = $("#pool-nav a.active[rel=next]").attr("href");
}
} }
Danbooru.Post.nav_pool_scroll = function() { Danbooru.Post.nav_pool_scroll = function() {
var scroll_top = $(window).scrollTop() + $(window).height(); var scroll_top = $(window).scrollTop() + $(window).height();
if (scroll_top > $("#image").height() + $("#image").offset().top + 100) { if (scroll_top > $("#image").height() + $("#image").offset().top + 100) {
location.href = $("#pool-nav a.active[rel=next]").attr("href"); Danbooru.Post.nav_pool_next();
return; return;
} }
@@ -321,10 +329,10 @@
if (width > 1000) { if (width > 1000) {
width = 1000; width = 1000;
} }
if (width < 400) { if (width > 700) {
$("#pool-nav li").css("textAlign", "left"); width = 700
} }
$("#pool-nav").width(width); $("#pool-nav,#tag-seq-nav").width(width);
} }
})(); })();

View File

@@ -122,6 +122,13 @@ div#c-posts {
} }
} }
div.nav-notice {
padding: 1em;
margin-bottom: 1em;
background: #EEE;
border: 1px solid #AAA;
}
aside#sidebar #tag-list h2 { aside#sidebar #tag-list h2 {
font-size: $h4_size; font-size: $h4_size;
} }
@@ -205,11 +212,11 @@ div#c-posts {
float: right; float: right;
} }
.pool-name { .pool-name, .tag-name {
margin: 0 1em; margin: 0 1em;
} }
#pool-nav { #pool-nav, #tag-seq-nav {
margin: 1em 0; margin: 1em 0;
li { li {

View File

@@ -27,6 +27,15 @@ class PostsController < ApplicationController
respond_with(@post) respond_with(@post)
end end
def show_seq
context = PostSearchContext.new(params)
if context.post_id
redirect_to(post_path(context.post_id, :tags => params[:tags]))
else
redirect_to(post_path(params[:id], :tags => params[:tags]))
end
end
def update def update
@post = Post.find(params[:id]) @post = Post.find(params[:id])
@post.update_attributes(params[:post], :as => CurrentUser.role) @post.update_attributes(params[:post], :as => CurrentUser.role)

View File

@@ -0,0 +1,25 @@
class PostSearchContext
attr_reader :params, :post_id
def initialize(params)
@params = params
raise unless params[:seq].present?
raise unless params[:id].present?
@post_id = find_post_id
end
def find_post_id
if params[:seq] == "prev"
post = Post.tag_match(params[:tags]).where("posts.id > ?", params[:id].to_i).reorder("posts.id asc").first
else
post = Post.tag_match(params[:tags]).where("posts.id < ?", params[:id].to_i).reorder("posts.id desc").first
end
if post
post.id
else
nil
end
end
end

View File

@@ -16,7 +16,12 @@ class PostPresenter < Presenter
path = options[:path_prefix] || "/posts" path = options[:path_prefix] || "/posts"
html = %{<article class="post-preview" id="post_#{post.id}" data-id="#{post.id}" data-tags="#{h(post.tag_string)}" data-uploader="#{h(post.uploader_name)}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}" data-flags="#{flags.join(' ')}" data-parent-id="#{post.parent_id}" data-has-children="#{post.has_children?}" data-score="#{post.score}">} html = %{<article class="post-preview" id="post_#{post.id}" data-id="#{post.id}" data-tags="#{h(post.tag_string)}" data-uploader="#{h(post.uploader_name)}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}" data-flags="#{flags.join(' ')}" data-parent-id="#{post.parent_id}" data-has-children="#{post.has_children?}" data-score="#{post.score}">}
html << %{<a href="#{path}/#{post.id}">} if options[:tags]
tag_param = "?tags=#{CGI::escape(options[:tags])}"
else
tag_param = nil
end
html << %{<a href="#{path}/#{post.id}#{tag_param}">}
html << %{<img src="#{post.preview_file_url}" alt="#{h(post.tag_string)}">} html << %{<img src="#{post.preview_file_url}" alt="#{h(post.tag_string)}">}
html << %{</a>} html << %{</a>}
html << %{</article>} html << %{</article>}

View File

@@ -12,7 +12,7 @@ module PostSetPresenters
end end
posts.each do |post| posts.each do |post|
html << PostPresenter.preview(post) html << PostPresenter.preview(post, :tags => template.params[:tags])
end end
html.html_safe html.html_safe

View File

@@ -1,3 +1,3 @@
<section id="pool-nav"> <div id="pool-nav" class="ui-corner-all nav-notice">
<%= @post.presenter.pool_html(self) %> <%= @post.presenter.pool_html(self) %>
</section> </div>

View File

@@ -0,0 +1,9 @@
<div id="tag-seq-nav" class="ui-corner-all nav-notice">
<ul>
<li>
<%= link_to "&laquo;prev".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "prev"), :rel => "prev" %>
<span class="tag-name">Search: <%= params[:tags] %></span>
<%= link_to "next&raquo;".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "next"), :rel => "next" %>
</li>
</ul>
</div>

View File

@@ -39,6 +39,10 @@
<%= @post.presenter.image_html(self) %> <%= @post.presenter.image_html(self) %>
</section> </section>
<% if params[:tags] %>
<%= render "posts/partials/show/tag_seq", :post => @post %>
<% end %>
<% if @post.pools.active.any? %> <% if @post.pools.active.any? %>
<%= render "posts/partials/show/pools", :post => @post %> <%= render "posts/partials/show/pools", :post => @post %>
<% end %> <% end %>

View File

@@ -134,6 +134,7 @@ Danbooru::Application.routes.draw do
resources :votes, :controller => "post_votes", :only => [:create, :destroy] resources :votes, :controller => "post_votes", :only => [:create, :destroy]
member do member do
put :revert put :revert
get :show_seq
end end
end end
resources :post_appeals, :only => [:new, :index, :create] resources :post_appeals, :only => [:new, :index, :create]