Skip to content

Instantly share code, notes, and snippets.

@rajeevkannav
Created September 5, 2018 13:22
Show Gist options
  • Save rajeevkannav/d14bbea2583d6b381c1ed742b2ec024b to your computer and use it in GitHub Desktop.
Save rajeevkannav/d14bbea2583d6b381c1ed742b2ec024b to your computer and use it in GitHub Desktop.
Skip Total Count view information if there is no filter
module ActiveAdmin
module Views
class PaginatedCollection < ActiveAdmin::Component
protected
# modified from will_paginate
def page_entries_info(options = {})
if options[:entry_name]
entry_name = options[:entry_name]
entries_name = options[:entries_name] || entry_name.pluralize
elsif collection_is_empty?
entry_name = I18n.t "active_admin.pagination.entry", :count => 1, :default => 'entry'
entries_name = I18n.t "active_admin.pagination.entry", :count => 2, :default => 'entries'
else
key = "activerecord.models." + collection.first.class.model_name.i18n_key.to_s
entry_name = I18n.translate key, :count => 1, :default => collection.first.class.name.underscore.sub('_', ' ')
entries_name = I18n.translate key, :count => collection.size, :default => entry_name.pluralize
end
if collection.num_pages < 2
case collection_size
when 0;
I18n.t('active_admin.pagination.empty', :model => entries_name)
when 1;
I18n.t('active_admin.pagination.one', :model => entry_name)
else
; I18n.t('active_admin.pagination.one_page', :model => entries_name, :n => collection.total_count)
end
else
offset = (collection.current_page - 1) * collection.limit_value
if @display_total and params[:q]
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
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment