From 0129891213e31bd3388787230600258a736a24cf Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 24 Jul 2017 19:30:30 -0500 Subject: [PATCH] Fix #1156: Allow sequential search navigator to work without a search. --- app/logical/post_search_context.rb | 27 ++++++++----------- app/presenters/post_presenter.rb | 6 ++++- .../posts/partials/show/_nav_links.html.erb | 2 +- .../posts/partials/show/_search_seq.html.erb | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/logical/post_search_context.rb b/app/logical/post_search_context.rb index 67ddde396..729dc490a 100644 --- a/app/logical/post_search_context.rb +++ b/app/logical/post_search_context.rb @@ -1,25 +1,20 @@ class PostSearchContext - attr_reader :params, :post_id + extend Memoist + attr_reader :id, :seq, :tags def initialize(params) - @params = params - raise unless params[:seq].present? - raise unless params[:id].present? - - @post_id = find_post_id + @id = params[:id].to_i + @seq = params[:seq] + @tags = params[:tags].presence || "status:any" 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 + def post_id + if seq == "prev" + Post.tag_match(tags).where("posts.id > ?", id).reorder("posts.id asc").first.try(:id) 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 + Post.tag_match(tags).where("posts.id < ?", id).reorder("posts.id desc").first.try(:id) end end + + memoize :post_id end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 5c3b8c347..579e5129a 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -189,7 +189,11 @@ class PostPresenter < Presenter end 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 def post_footer_for_pool_html(template) diff --git a/app/views/posts/partials/show/_nav_links.html.erb b/app/views/posts/partials/show/_nav_links.html.erb index 306e4194f..21858d94d 100644 --- a/app/views/posts/partials/show/_nav_links.html.erb +++ b/app/views/posts/partials/show/_nav_links.html.erb @@ -1,6 +1,6 @@ <% if (position == "bottom" && CurrentUser.user.new_post_navigation_layout) || (position == "top" && !CurrentUser.user.new_post_navigation_layout) %>