# frozen_string_literal: true def wrap_with_batch_action_form(&block) if active_admin_config.batch_actions.any? insert_tag(ActiveAdmin::BatchActions::BatchActionForm, &block) batch_actions_to_display.each do |batch_action| if batch_action.partial.present? render(batch_action.partial) end end else block.call end end def build_collection if collection_empty?(collection) if params[:q] || params[:scope] render("active_admin/resource/index_empty_results") else render("active_admin/resource/index_blank_slate") end else render_index end end def build_table_tools div class: "index-data-table-toolbar" do render "batch_actions_dropdown" build_scopes build_index_list end if any_table_tools? 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 def build_scopes if active_admin_config.scopes.any? scope_options = { scope_count: page_presenter.fetch(:scope_count, true) } insert_tag(ActiveAdmin::Views::Scopes, active_admin_config.scopes, scope_options) end end def build_index_list 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 insert_tag(ActiveAdmin::Views::IndexList, index_classes) end 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) if klass.is_a?(Class) klass else ::ActiveAdmin::Views.const_get("IndexAs" + klass.to_s.camelcase) end end def render_index 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 insert_tag(renderer_class, page_presenter, collection) end end div class: "main-content-container" do wrap_with_batch_action_form do build_table_tools build_collection end end