From c6d03f2d3ad410b80a31e3141dcabfe1dd5757f0 Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 25 Feb 2013 12:09:02 -0500 Subject: [PATCH] add tag seq nav --- app/assets/javascripts/posts.js | 20 ++++++++++----- .../stylesheets/specific/posts.css.scss | 11 ++++++-- app/controllers/posts_controller.rb | 9 +++++++ app/logical/post_search_context.rb | 25 +++++++++++++++++++ app/presenters/post_presenter.rb | 7 +++++- app/presenters/post_set_presenters/base.rb | 2 +- app/views/posts/partials/show/_pools.html.erb | 4 +-- .../posts/partials/show/_tag_seq.html.erb | 9 +++++++ app/views/posts/show.html.erb | 6 ++++- config/routes.rb | 1 + 10 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 app/logical/post_search_context.rb create mode 100644 app/views/posts/partials/show/_tag_seq.html.erb diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 715cfb571..18048f165 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -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); } })(); diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index 8037f4867..9e1d3ae41 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -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 { diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index fa96fc058..e54299d90 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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) diff --git a/app/logical/post_search_context.rb b/app/logical/post_search_context.rb new file mode 100644 index 000000000..db3b5b38a --- /dev/null +++ b/app/logical/post_search_context.rb @@ -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 diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index d691b7b73..537f4d99a 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -16,7 +16,12 @@ class PostPresenter < Presenter path = options[:path_prefix] || "/posts" html = %{
} - html << %{} + if options[:tags] + tag_param = "?tags=#{CGI::escape(options[:tags])}" + else + tag_param = nil + end + html << %{} html << %{#{h(post.tag_string)}} html << %{} html << %{
} diff --git a/app/presenters/post_set_presenters/base.rb b/app/presenters/post_set_presenters/base.rb index fb974cb11..6c117d28a 100644 --- a/app/presenters/post_set_presenters/base.rb +++ b/app/presenters/post_set_presenters/base.rb @@ -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 diff --git a/app/views/posts/partials/show/_pools.html.erb b/app/views/posts/partials/show/_pools.html.erb index c5e0951c9..53aec294c 100644 --- a/app/views/posts/partials/show/_pools.html.erb +++ b/app/views/posts/partials/show/_pools.html.erb @@ -1,3 +1,3 @@ -
+
+ diff --git a/app/views/posts/partials/show/_tag_seq.html.erb b/app/views/posts/partials/show/_tag_seq.html.erb new file mode 100644 index 000000000..b652f0ccd --- /dev/null +++ b/app/views/posts/partials/show/_tag_seq.html.erb @@ -0,0 +1,9 @@ + diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 5aad3c113..2a258d7d1 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -39,10 +39,14 @@ <%= @post.presenter.image_html(self) %> + <% 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 %> - +
  • Comments
  • Edit
  • diff --git a/config/routes.rb b/config/routes.rb index 2fc2d2559..e0493c2b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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]