def wrap_with_batch_action_form(&block) if active_admin_config.batch_actions.any? batch_action_form(&block) else block.call end end def any_table_tools? active_admin_config.batch_actions.any? || active_admin_config.scopes.any? || active_admin_config.page_presenters[:index].try(:size).try(:>, 1) end # 1. removes `select` and `order` to prevent invalid SQL # 2. correctly handles the Hash returned when `group by` is used def collection_size(c = collection) return c.count if c.is_a?(Array) c = c.except :select, :order c.group_values.present? ? c.count.count : c.count end # Returns the actual class for renderering the main content on the index # page. To set this, use the :as option in the page_presenter block. def find_index_renderer_class(klass) klass.is_a?(Class) ? klass : ::ActiveAdmin::Views.const_get("IndexAs" + klass.to_s.camelcase) end def blank_slate_link if page_presenter.options.has_key?(:blank_slate_link) blank_slate_link = page_presenter.options[:blank_slate_link] instance_exec(&blank_slate_link) if blank_slate_link.is_a?(Proc) else link_to(I18n.t("active_admin.blank_slate.link"), new_resource_path) end end div id: "main_content" do wrap_with_batch_action_form do div class: "table_tools" do if active_admin_config.batch_actions.any? insert_tag view_factory.batch_action_selector, active_admin_config.batch_actions end if active_admin_config.scopes.any? scope_options = { scope_count: page_presenter.fetch(:scope_count, true) } scopes_renderer active_admin_config.scopes, scope_options end indexes = active_admin_config.page_presenters[:index] if indexes.kind_of?(Hash) && indexes.length > 1 index_classes = [] active_admin_config.page_presenters[:index].each do |type, page_presenter| index_classes << find_index_renderer_class(page_presenter[:as]) end index_list_renderer index_classes end end if any_table_tools? if collection_size(collection) != 0 renderer_class = find_index_renderer_class(page_presenter[:as]) paginator = page_presenter.fetch(:paginator, true) download_links = page_presenter.fetch(:download_links, active_admin_config.namespace.download_links) pagination_total = page_presenter.fetch(:pagination_total, true) per_page = page_presenter.fetch(:per_page, active_admin_config.per_page) 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, per_page: per_page, pagination_total: pagination_total) do div class: 'index_content' do insert_tag(renderer_class, page_presenter, collection) end end else if params[:q] || params[:scope] empty_results_content = I18n.t("active_admin.pagination.empty", model: active_admin_config.plural_resource_label) insert_tag(ActiveAdmin::Views::BlankSlate, empty_results_content) else blank_slate_content = I18n.t("active_admin.blank_slate.content", resource_name: active_admin_config.plural_resource_label) if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class) blank_slate_content = [blank_slate_content, blank_slate_link].compact.join(" ") end insert_tag(ActiveAdmin::Views::BlankSlate, blank_slate_content) end end end end