Sha256: 833cc59fcda12c84021ad2b89fdfdefb8981e3f418f71336a1f3c2dee3cce306

Contents?: true

Size: 1.91 KB

Versions: 82

Compression:

Stored size: 1.91 KB

Contents

module ActiveAdmin
  module Views
    class TreeTableFor < ActiveAdmin::Views::TableFor

      Column = ActiveAdmin::Views::TableFor::Column

      def column(*args, &block)
        options = default_options.merge(args.extract_options!)
        title = args[0]
        data  = args[1] || args[0]

        col = Column.new(title, data, @resource_class, options, &block)
        @columns << col

        # Build our header item
        within @header_row do
          build_table_header(col)
        end

        # Add a table cell for each item
        populate_columns(@tbody, @collection, col)
      end

    protected

      def populate_columns(tbody, collection, col)
        i = 0
        collection.each do |item|

          # find the <tr/>
          tr_elem = tbody.children[i]
          within tr_elem do
            build_table_cell(col, item)
            i += 1
          end

          unless item.children.blank?
            # find the tbody
            tr_elem    = tbody.children[i]
            td_elem    = tr_elem.children[0]
            table_elem = td_elem.children[0]
            tbody_elem = table_elem.children[0]

            populate_columns(tbody_elem, item.children, col)
            i += 1
          end
        end
      end

      def build_table_body
        @tbody = build_tbody(@collection)
      end

      def build_tbody(collection)
        tbody do
          # Build enough rows for our collection (and the sub trees)
          collection.each do |node|
            tr(:class => cycle('odd', 'even'), :id => dom_id(node))
            build_subtree(node.children)
          end
        end
      end

      def build_subtree(collection)
        if collection.blank?
          return
        end

        tr do
          td(:class => "subtree", :colspan => "42") do
            table(:class => "subtree") do
              build_tbody(collection)
            end
          end
        end
      end

    end
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.177 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.176 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.170 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.168 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.165 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.162 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.161 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.160 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.157 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.156 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.155 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.154 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.153 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.152 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.149 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.146 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.144 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.141 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.136 lib/lalala/views/tree_table_for.rb
lalala-4.0.0.dev.135 lib/lalala/views/tree_table_for.rb