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() {
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() {
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() {
var scroll_top = $(window).scrollTop() + $(window).height();
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;
}
@@ -321,10 +329,10 @@
if (width > 1000) {
width = 1000;
}
if (width < 400) {
$("#pool-nav li").css("textAlign", "left");
if (width > 700) {
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 {
font-size: $h4_size;
}
@@ -205,11 +212,11 @@ div#c-posts {
float: right;
}
.pool-name {
.pool-name, .tag-name {
margin: 0 1em;
}
#pool-nav {
#pool-nav, #tag-seq-nav {
margin: 1em 0;
li {

View File

@@ -27,6 +27,15 @@ class PostsController < ApplicationController
respond_with(@post)
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
@post = Post.find(params[:id])
@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"
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 << %{</a>}
html << %{</article>}

View File

@@ -12,7 +12,7 @@ module PostSetPresenters
end
posts.each do |post|
html << PostPresenter.preview(post)
html << PostPresenter.preview(post, :tags => template.params[:tags])
end
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) %>
</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,10 +39,14 @@
<%= @post.presenter.image_html(self) %>
</section>
<% if params[:tags] %>
<%= render "posts/partials/show/tag_seq", :post => @post %>
<% end %>
<% if @post.pools.active.any? %>
<%= render "posts/partials/show/pools", :post => @post %>
<% end %>
<menu id="post-sections">
<li><a href="#comments">Comments</a></li>
<li><a href="#edit" id="post-edit-link">Edit</a></li>

View File

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