Sha256: f71a2d33d4648fd808631ee25e9e56cc47ccaa807a6b8413be98c2daa9db300c

Contents?: true

Size: 1.93 KB

Versions: 25

Compression:

Stored size: 1.93 KB

Contents

module ActiveAdmin
  module Views

     # # Index as a Grid
     #
     # Sometimes you want to display the index screen for a set of resources as a grid
     # (possibly a grid of thumbnail images). To do so, use the :grid option for the
     # index block.
     #
     # ```ruby
     # index as: :grid do |product|
     #   link_to image_tag(product.image_path), admin_product_path(product)
     # end
     # ```
     #
     # The block is rendered within a cell in the grid once for each resource in the
     # collection. The resource is passed into the block for you to use in the view.
     #
     # You can customize the number of columns that are rendered using the columns
     # option:
     #
     # ```ruby
     # index as: :grid, columns: 5 do |product|
     #   link_to image_tag(product.image_path), admin_product_path(product)
     # end
     # ```
     #
     class IndexAsGrid < ActiveAdmin::Component

      def build(page_presenter, collection)
        @page_presenter = page_presenter
        @collection = collection
        add_class "index"
        build_table
      end

      def number_of_columns
        @page_presenter[:columns] || default_number_of_columns
      end

      def self.index_name
        "grid"
      end

      protected

      def build_table
        resource_selection_toggle_panel if active_admin_config.batch_actions.any?
        table class: "index_grid" do
          collection.in_groups_of(number_of_columns).each do |group|
            build_row(group)
          end
        end
      end

      def build_row(group)
        tr do
          group.each do |item|
            item ? build_item(item) : build_empty_cell
          end
        end
      end

      def build_item(item)
        td for: item do
          instance_exec(item, &@page_presenter.block)
        end
      end

      def build_empty_cell
        td '&nbsp;'.html_safe
      end

      def default_number_of_columns
        3
      end

    end
  end
end

Version data entries

25 entries across 25 versions & 5 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/index_as_grid.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.17.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.16.pre lib/active_admin/views/index_as_grid.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/index_as_grid.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/index_as_grid.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/views/index_as_grid.rb
activeadmin-1.0.0.pre2 lib/active_admin/views/index_as_grid.rb
activeadmin-1.0.0.pre1 lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.7.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.6.pre lib/active_admin/views/index_as_grid.rb
yousty-activeadmin-1.0.5.pre lib/active_admin/views/index_as_grid.rb