Commit 1d670fa8 authored by azul's avatar azul

cleanup: pagination helpers and link renderers

parent 0639d1eb
......@@ -40,11 +40,7 @@ module Common::Application::PaginationOptions
#
def pagination_link_renderer
if defined? page_search_path
if xhr_page_search?
LinkRenderer::AjaxPages
else
LinkRenderer::Pages
end
LinkRenderer::AjaxPages
elsif request.xhr?
request.format == :html ?
LinkRenderer::ModalAjax :
......
......@@ -5,7 +5,6 @@
module Common::PageSearch
def self.included(base)
base.class_eval do
helper_method :xhr_page_search?
helper_method :page_search_path
helper_method :show_filter?
end
......@@ -41,14 +40,6 @@ module Common::PageSearch
parse_filter_path(params[:path] || params[:filter] || [])
end
#
# controllers that include this mixin should redefine this to true if they
# want the page search to not be ajax based.
#
def xhr_page_search?
true
end
#
# the page search code relies on this being defined by controllers that
# include this mixin.
......
......@@ -10,7 +10,7 @@ class Me::PagesController < Me::BaseController
if request.xhr?
# note: pagination_params is used just for defaults,
# normal pagination is done through @path.
@pages = Page.paginate_by_path(@path, options_for_me(method: :sphinx), pagination_params).compact
@pages = Page.paginate_by_path(@path, options_for_me(method: :sphinx), pagination_params)
end
render template: 'common/pages/search/index', locals: { columns: :updated_with_owner }
end
......
#
# This is a link renderer for displaying a list of pages filtered by path_finder.
#
# For example: /public/page/3
#
# The link to 'next' will be: /public/page/4
#
# NEEDS TO BE WRITTEN
#
# FIXME
class LinkRenderer::Pages < WillPaginate::ViewHelpers::LinkRenderer
end
......@@ -6,5 +6,5 @@
= render partial: 'group', collection: group_list,
spacer_template: 'common/divider'
= pagination_links(@groups, params: params.except(:utf8))
= pagination_links(@groups, params: params.permit(:controller, :action, :path, :q))
......@@ -13,3 +13,4 @@ title: "Crabgrass Testing"
raise_i18n_exceptions: true
enforce_ssl: false
pagination_size: 5
......@@ -11,6 +11,7 @@ class Me::PagesControllerTest < ActionController::TestCase
login_as users(:blue)
post :index, xhr: true
assert !assigns(:pages).empty?, 'blue should have some pages to render'
assert_respond_to assigns(:pages), :total_entries
assert_response :success
end
......
......@@ -26,8 +26,9 @@ class Person::DirectoryControllerTest < ActionController::TestCase
get :index, params: { path: 'peers' }
assert_response :success
users = assigns(:users)
assert_equal 10, users.count
assert_right_order users(:blue).peers, users
assert_equal 10, users.total_entries
assert_equal 5, users.length
assert_right_order users(:blue).peers.limit(5), users
end
def test_pagination
......@@ -37,7 +38,6 @@ class Person::DirectoryControllerTest < ActionController::TestCase
end
get :index, params: { path: 'peers' }
assert_response :success
## FIXME: 'count' doesn't work here, because it loses pagination params.
on_page = users(:blue).peers.count - 9
on_page = 3 if on_page > 9
assert_equal on_page, assigns(:users).length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment