Skip to content

Commit

Permalink
Merge pull request #2333 from joseluistorres/issue_with_count_for_big…
Browse files Browse the repository at this point in the history
…_tables_2283

adding the pagination_count option for index page #2283
  • Loading branch information
seanlinsley committed Aug 2, 2013
2 parents 3cbaaaa + 15fc073 commit 779d009
Show file tree
Hide file tree
Showing 37 changed files with 116 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/locales/bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bg:
one: "Показване на <b>1</b> %{model}"
one_page: "Показване на <b>всички %{n}</b> %{model}"
multiple: "Показване %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> от общо <b>%{total}</b>"
multiple_without_total: "Показване %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "запис"
other: "записи"
Expand Down
1 change: 1 addition & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ca:
one: "S'està mostrant <b>1</b> %{model}"
one_page: "S'estan mostrant <b>tots %{n}</b> %{model}"
multiple: "S'estan mostrant %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> de <b>%{total}</b> en total"
multiple_without_total: "S'estan mostrant %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "entrada"
other: "entrades"
Expand Down
1 change: 1 addition & 0 deletions config/locales/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cs:
one: "Zobrazena <b>1</b> položka"
one_page: "Počet zobrazených položek %{n}"
multiple: "<b>%{from}&nbsp;-&nbsp;%{to}</b> z <b>%{total}</b>"
multiple_without_total: "<b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "položka"
few: "položky"
Expand Down
1 change: 1 addition & 0 deletions config/locales/da.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ da:
one: "Viser <b>1</b> %{model}"
one_page: "Viser <b>alle %{n}</b> %{model}"
multiple: "Viser %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> af <b>%{total}</b> i alt"
multiple_without_total: "Viser %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "post"
other: "poster"
Expand Down
1 change: 1 addition & 0 deletions config/locales/de-CH.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
one: "Zeige <b>1</b> %{model}"
one_page: "Zeige <b>alle %{n}</b> %{model}"
multiple: "Zeige %{model} <b>%{from}&nbsp;–&nbsp;%{to}</b> von <b>%{total}</b>"
multiple_without_total: "Zeige %{model} <b>%{from}&nbsp;–&nbsp;%{to}</b>"
entry:
one: "Eintrag"
other: "Einträge"
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ de:
one: "Zeige <b>1</b> %{model}"
one_page: "Zeige <b>alle %{n}</b> %{model}"
multiple: "Zeige %{model} <b>%{from}&nbsp;–&nbsp;%{to}</b> von <b>%{total}</b>"
multiple_without_total: "Zeige %{model} <b>%{from}&nbsp;–&nbsp;%{to}</b>"
entry:
one: "Eintrag"
other: "Einträge"
Expand Down
1 change: 1 addition & 0 deletions config/locales/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
one: "Displaying <b>1</b> %{model}"
one_page: "Displaying <b>all %{n}</b> %{model}"
multiple: "Displaying %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> of <b>%{total}</b> in total"
multiple_without_total: "Displaying %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "entry"
other: "entries"
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ en:
one: "Displaying <b>1</b> %{model}"
one_page: "Displaying <b>all %{n}</b> %{model}"
multiple: "Displaying %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> of <b>%{total}</b> in total"
multiple_without_total: "Displaying %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "entry"
other: "entries"
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ es:
one: "Mostrando <b>1</b> %{model}"
one_page: "Mostrando <b>un total de %{n}</b> %{model}"
multiple: "Mostrando %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> de un total de <b>%{total}</b>"
multiple_without_total: "Mostrando %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
blank_slate:
content: "No hay %{resource_name} aún."
link: "Añadir"
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fr:
one: "Affichage de <b>1</b> %{model}"
one_page: "Affichage de <b>tous les %{n}</b> %{model}"
multiple: "Affichage de %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> sur un total de <b>%{total}</b>"
multiple_without_total: "Affichage de %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "entrée"
other: "entrées"
Expand Down
1 change: 1 addition & 0 deletions config/locales/he.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ he:
one: "מציג <b>1</b> %{model}"
one_page: "הצגת <b>כל %{n}</b> %{model}"
multiple: "מציג %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> מתוך <b>%{total}</b> בסך הכל"
multiple_without_total: "מציג %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "רשומה בודדה"
other: "רשומות"
Expand Down
1 change: 1 addition & 0 deletions config/locales/hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ hr:
one: "Prikazan <b>1</b> %{model}"
one_page: "Prikazano <b>svih %{n}</b> %{model}"
multiple: "Prikazani %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> od ukupno <b>%{total}</b>"
multiple_without_total: "Prikazani %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "zapis"
few: "zapisa"
Expand Down
1 change: 1 addition & 0 deletions config/locales/hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ hu:
one: "<b>Egy</b> %{model} megjelenítése"
one_page: "<b>Az összes (%{n} db)</b> %{model} megjelenítése"
multiple: "%{model} listájának megjelenítése, <b>%{from}&nbsp;-&nbsp;%{to}</b>/<b>%{total}</b> "
multiple_without_total: "%{model} listájának megjelenítése, <b>%{from}&nbsp;-&nbsp;%{to}</b> "
entry:
one: "elem"
other: "elem"
Expand Down
1 change: 1 addition & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ it:
one: "Sto mostrando <b>1</b> %{model}"
one_page: "Sto mostrando <b>%{n}</b> %{model}. Lista completa."
multiple: "Sto mostrando %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> di <b>%{total}</b> in totale"
multiple_without_total: "Sto mostrando %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "voce"
other: "voci"
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ja:
one: "<b>1</b> 件の %{model} を表示しています"
one_page: "<b>全 %{n}</b> 件の %{model} を表示しています"
multiple: "全 <b>%{total}</b> 件中 <b>%{from}&nbsp;-&nbsp;%{to}</b> 件の %{model} を表示しています"
multiple_without_total: "<b>%{from}&nbsp;-&nbsp;%{to}</b> 件の %{model} を表示しています"
entry: レコード
any: "任意"
blank_slate:
Expand Down
1 change: 1 addition & 0 deletions config/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ko:
one: "<b>1</b> %{model} 표시중"
one_page: "<b>전체 %{n}</b> %{model} 표시중"
multiple: "전체 <b>%{total}</b> 중 <b>%{from}&nbsp;-&nbsp;%{to}</b> %{model} 표시중"
multiple_without_total: "중 <b>%{from}&nbsp;-&nbsp;%{to}</b> %{model} 표시중"
any: "어떤"
blank_slate:
content: "아직 %{resource_name} 이/가 없습니다."
Expand Down
1 change: 1 addition & 0 deletions config/locales/lt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ lt:
one: 'Rodoma <B> 1 </ b> %{model}'
one_page: 'Rodoma <b>visi %{n} </ b> %{model}'
multiple: 'Rodomi %{model} <b>%{iš}&nbsp;-&nbsp;%{to} </ b> iš<b>%{total} </ b> iš viso'
multiple_without_total: 'Rodomi %{model} <b>%{iš}&nbsp;-&nbsp;%{to} </ b> '
entry:
one: 'įrašas'
other: 'įrašai'
Expand Down
1 change: 1 addition & 0 deletions config/locales/lv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ lv:
one: "<b>1</b> ieraksts"
one_page: "<b>%{n}</b> ieraksti"
multiple: "<b>%{from}&nbsp;-&nbsp;%{to}</b> ieraksti no <b>%{total}</b> kopā"
multiple_without_total: "<b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "ieraksts"
other: "ieraksti"
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ nl:
one: "Geeft <b>1</b> %{model} weer"
one_page: "Geeft <b>%{n}</b> %{model} weer"
multiple: "Geeft %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> van de <b>%{total}</b> weer"
multiple_without_total: "Geeft %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "entry"
other: "entries"
Expand Down
1 change: 1 addition & 0 deletions config/locales/no-NB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
one: "Viser <b>1</b> %{model}"
one_page: "Viser <b>alle %{n}</b> %{model}"
multiple: "Viser %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> av <b>%{total}</b> totalt"
multiple_without_total: "Viser %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
any: "Noen"
blank_slate:
content: "Her er det ingen %{resource_name} enda."
Expand Down
1 change: 1 addition & 0 deletions config/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pl:
one: "Wyświetlanie <b>1</b> %{model}"
one_page: "Wyświetlanie <b>wszystkich %{n}</b> %{model}"
multiple: "Wyświetlanie %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> z <b>%{total}</b>"
multiple_without_total: "Wyświetlanie %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
any: "Jakikolwiek"
blank_slate:
content: "Nie ma jeszcze zasobu %{resource_name}."
Expand Down
1 change: 1 addition & 0 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
one: "Exibindo <b>1</b> %{model}"
one_page: "Exibindo <b>todos(as) os(as) %{n}</b> %{model}"
multiple: "Exibindo %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> de um total de <b>%{total}</b>"
multiple_without_total: "Exibindo %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "registro"
other: "registros"
Expand Down
1 change: 1 addition & 0 deletions config/locales/pt-PT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
one: "Mostrando <b>1</b> %{model}"
one_page: "Mostrando <b>todos(as) os(as) %{n}</b> %{model}"
multiple: "Mostrando %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> de um total de <b>%{total}</b>"
multiple_without_total: "Mostrando %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "registro"
other: "registros"
Expand Down
1 change: 1 addition & 0 deletions config/locales/ro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ro:
one: "Afisare <b>1</b> %{model}"
one_page: "Sunt afisate <b>toate %{n}</b> inregistrarile"
multiple: "Sunt afisate <b>%{from}&nbsp;-&nbsp;%{to}</b> din <b>%{total}</b> inregistrari"
multiple_without_total: "Sunt afisate <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "inregistrare"
other: "inregistrari"
Expand Down
1 change: 1 addition & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ru:
one: "Результат: <b>1</b> %{model}"
one_page: "Результат: <b>%{n}</b> %{model}"
multiple: "Результат: %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> из <b>%{total}</b>"
multiple_without_total: "Результат: %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "запись"
other: "записей"
Expand Down
1 change: 1 addition & 0 deletions config/locales/sv-SE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
one: "Visar <b>1</b> utav %{model}"
one_page: "Visar <b>alla %{n}</b> utav %{model}"
multiple: "Visar %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> av <b>%{total}</b> totalt"
multiple_without_total: "Visar %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "inlägg"
other: "inlägg"
Expand Down
1 change: 1 addition & 0 deletions config/locales/tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tr:
one: "<b>1</b> %{model} kaydı görüntüleniyor"
one_page: "<b>%{n}</b> kayıt %{model} modelinde görüntüleniyor"
multiple: "%{model} toplam %{total} kayıt bulundu. <b>%{from} ile %{to} arası</b> arası görüntüleniyor"
multiple_without_total: "%{model}. <b>%{from} ile %{to} arası</b> arası görüntüleniyor"
entry:
one: "Girdi"
other: "Girdiler"
Expand Down
1 change: 1 addition & 0 deletions config/locales/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ uk:
one: "Результат: <b>1</b> %{model}"
one_page: "Результат: <b>%{n}</b> %{model}"
multiple: "Результат: %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> з <b>%{total}</b>"
multiple_without_total: "Результат: %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>"
entry:
one: "запис"
other: "записів"
Expand Down
1 change: 1 addition & 0 deletions config/locales/vi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ vi:
one: "Đang hiển thị <b>1</b> %{model}"
one_page: "Đang hiển thị <b>tất cả %{n}</b> %{model}"
multiple: "Đang hiển thị %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> of <b>%{total}</b> trong tất cả."
multiple_without_total: "Đang hiển thị %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b>."
entry:
one: "entry"
other: "entries"
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
one: "显示 <b>1</b> %{model}"
one_page: "显示 <b>所有 %{n}</b> %{model}"
multiple: "显示所有 <b>%{total}</b> %{model}中的<b>%{from}&nbsp;-&nbsp;%{to}</b> 条"
multiple_without_total: "%{model}中的<b>%{from}&nbsp;-&nbsp;%{to}</b> 条"
entry:
one: "条目"
other: "条目"
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
one: "顯示 <b>1</b> %{model}"
one_page: "顯示 <b>全部 %{n}</b> %{model}"
multiple: "總計 <b>%{total}</b> 顯示 %{model} 中<b>%{from}&nbsp;-&nbsp;%{to}</b> 筆"
multiple_without_total: "顯示 %{model} 中<b>%{from}&nbsp;-&nbsp;%{to}</b> 筆"
entry:
one: ""
other: ""
Expand Down
12 changes: 12 additions & 0 deletions docs/3-index-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ You can also disable pagination:
config.paginate = false
end

If you have a very large database, you might want to disable SELECT COUNT(*) queries caused by the pagination info at the bottom of the page:

ActiveAdmin.register Post do

# disable pagination total
index :pagination_total => false do
#...
end

end

## Disable CSV, XML and JSON export

You can remove links to download CSV, XML and JSON exports:
Expand Down Expand Up @@ -177,3 +188,4 @@ If you want to customize download links for every resource throughout the applic
config.download_links = [:csv, :xml, :json, :pdf]

end

15 changes: 15 additions & 0 deletions features/index/pagination.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@ Feature: Index Pagination
Given 31 posts exist
When I am on the index page for posts
Then I should not see pagination

Scenario: Viewing index with pagination_total set to false
Given an index configuration of:
"""
ActiveAdmin.register Post do
index :pagination_total => false do
end
end
"""
Given 100 posts exist
When I am on the index page for posts
Then I should see pagination with 2 pages
Then I should see "Displaying Posts 1 - 30"
And I should not see "Displaying Posts 1 - 30 of 100 in total"

11 changes: 9 additions & 2 deletions lib/active_admin/views/components/paginated_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def build(collection, options = {})
@collection = collection
@param_name = options.delete(:param_name)
@download_links = options.delete(:download_links)
@display_total = options.delete(:pagination_total) { true }

unless collection.respond_to?(:num_pages)
raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
Expand Down Expand Up @@ -106,8 +107,14 @@ def page_entries_info(options = {})
end
else
offset = (collection.current_page - 1) * collection.limit_value
total = collection.total_count
I18n.t('active_admin.pagination.multiple', :model => entries_name, :from => offset + 1, :to => offset + collection_size, :total => total)
if @display_total
total = collection.total_count
I18n.t 'active_admin.pagination.multiple', :model => entries_name, :total => total,
:from => offset + 1, :to => offset + collection_size
else
I18n.t 'active_admin.pagination.multiple_without_total', :model => entries_name,
:from => offset + 1, :to => offset + collection_size
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/active_admin/views/pages/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ def render_index
renderer_class = find_index_renderer_class(config[:as])
paginator = config[:paginator].nil? ? true : config[:paginator]
download_links = config[:download_links].nil? ? active_admin_config.namespace.download_links : config[:download_links]
pagination_total = config[:pagination_total].nil? ? true : config[:pagination_total]

paginated_collection(collection, :entry_name => active_admin_config.resource_label,
:entries_name => active_admin_config.plural_resource_label(:count => collection_size),
:download_links => download_links,
:paginator => paginator) do
:paginator => paginator,
:pagination_total => pagination_total) do
div :class => 'index_content' do
insert_tag(renderer_class, config, collection)
end
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def load_defaults!
ActiveAdmin.register(Category)
ActiveAdmin.register(User)
ActiveAdmin.register(Post){ belongs_to :user, :optional => true }
ActiveAdmin.register(Store){
index :pagination_total => false do
end
}
reload_menus!
end

Expand Down
42 changes: 42 additions & 0 deletions spec/unit/views/components/paginated_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,48 @@ def paginated_collection(*args)
end
end

context "when having the param :pagination_total set to true " do
let(:view) do
view = mock_action_view
view.request.stub!(:query_parameters).and_return({:controller => 'admin/stores', :action => 'index', :page => '1'})
view.controller.params = {:controller => 'admin/stores', :action => 'index'}
view
end

let(:collection) do
stores = [Store.new] * 1000
Kaminari.paginate_array(stores).page(1).per(30)
end

let(:pagination) { paginated_collection(collection, :pagination_total => true) }

it "should show the total item counts" do
info = pagination.find_by_class('pagination_information').first.content.gsub('&nbsp;',' ')
info.should eq "Displaying Bookstores <b>1 - 30</b> of <b>1000</b> in total"
end

end

context "when having the param :pagination_total set to false " do
let(:view) do
view = mock_action_view
view.request.stub!(:query_parameters).and_return({:controller => 'admin/stores', :action => 'index', :page => '1'})
view.controller.params = {:controller => 'admin/stores', :action => 'index'}
view
end

let(:collection) do
stores = [Store.new] * 1000
Kaminari.paginate_array(stores).page(1).per(30)
end

let(:pagination) { paginated_collection(collection, :pagination_total => false) }

it "should not show the total item counts" do
info = pagination.find_by_class('pagination_information').first.content.gsub('&nbsp;',' ')
info.should eq "Displaying Bookstores <b>1 - 30</b>"
end

end
end
end

0 comments on commit 779d009

Please sign in to comment.