Merge pull request #3238 from evazion/fix-1156
Fix #1156: Allow sequential search navigator to work without a search.
This commit is contained in:
@@ -1,25 +1,20 @@
|
|||||||
class PostSearchContext
|
class PostSearchContext
|
||||||
attr_reader :params, :post_id
|
extend Memoist
|
||||||
|
attr_reader :id, :seq, :tags
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@params = params
|
@id = params[:id].to_i
|
||||||
raise unless params[:seq].present?
|
@seq = params[:seq]
|
||||||
raise unless params[:id].present?
|
@tags = params[:tags].presence || "status:any"
|
||||||
|
|
||||||
@post_id = find_post_id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_post_id
|
def post_id
|
||||||
if params[:seq] == "prev"
|
if seq == "prev"
|
||||||
post = Post.tag_match(params[:tags]).where("posts.id > ?", params[:id].to_i).reorder("posts.id asc").first
|
Post.tag_match(tags).where("posts.id > ?", id).reorder("posts.id asc").first.try(:id)
|
||||||
else
|
else
|
||||||
post = Post.tag_match(params[:tags]).where("posts.id < ?", params[:id].to_i).reorder("posts.id desc").first
|
Post.tag_match(tags).where("posts.id < ?", id).reorder("posts.id desc").first.try(:id)
|
||||||
end
|
|
||||||
|
|
||||||
if post
|
|
||||||
post.id
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
memoize :post_id
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -189,7 +189,11 @@ class PostPresenter < Presenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def has_nav_links?(template)
|
def has_nav_links?(template)
|
||||||
(CurrentUser.user.enable_sequential_post_navigation && template.params[:tags].present? && template.params[:tags] !~ /(?:^|\s)(?:order|ordfav|ordpool):/) || @post.pools.undeleted.any? || @post.favorite_groups(active_id=template.params[:favgroup_id]).any?
|
has_sequential_navigation?(template) || @post.pools.undeleted.any? || @post.favorite_groups(active_id=template.params[:favgroup_id]).any?
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_sequential_navigation?(template)
|
||||||
|
CurrentUser.user.enable_sequential_post_navigation && template.params[:tags] !~ /(?:^|\s)(?:order|ordfav|ordpool):/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_footer_for_pool_html(template)
|
def post_footer_for_pool_html(template)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<% if (position == "bottom" && CurrentUser.user.new_post_navigation_layout) || (position == "top" && !CurrentUser.user.new_post_navigation_layout) %>
|
<% if (position == "bottom" && CurrentUser.user.new_post_navigation_layout) || (position == "top" && !CurrentUser.user.new_post_navigation_layout) %>
|
||||||
<div id="nav-links" class="ui-corner-all nav-notice">
|
<div id="nav-links" class="ui-corner-all nav-notice">
|
||||||
<% if CurrentUser.user.enable_sequential_post_navigation && params[:tags].present? && params[:tags] !~ /(?:^|\s)(?:order|ordfav|ordpool):/ %>
|
<% if post.presenter.has_sequential_navigation?(self) %>
|
||||||
<%= render "posts/partials/show/search_seq", :post => post %>
|
<%= render "posts/partials/show/search_seq", :post => post %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li class="active">
|
<li class="active">
|
||||||
<%= link_to "‹ prev".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "prev"), :rel => "prev nofollow", :class => "prev" %>
|
<%= link_to "‹ prev".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "prev"), :rel => "prev nofollow", :class => "prev" %>
|
||||||
<span class="search-name">Search: <%= params[:tags] %></span>
|
<span class="search-name">Search: <%= params[:tags].presence || "status:any" %></span>
|
||||||
<%= link_to "next ›".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "next"), :rel => "next nofollow", :class => "next" %>
|
<%= link_to "next ›".html_safe, show_seq_post_path(post, :tags => params[:tags], :seq => "next"), :rel => "next nofollow", :class => "next" %>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user