Skip to content

cantierecreativo/activeadmin-sortable-tree

Repository files navigation

ActiveAdmin Sortable Tree

This gem adds a tree and a list view to your ActiveAdmin resource index, both sortable via drag’n’drop.

Installation

  • Gemfile:

    gem "activeadmin-sortable-tree", :github => "nebirhos/activeadmin-sortable-tree", :branch => "master"
    

Usage (Tree)

  • Admin (eg. app/admin/page.rb):

    ActiveAdmin.register Page do
      sortable tree: true
    
      index :as => :sortable do
        label :title # item content
        default_actions
      end
    end
    
  • Model: activeadmin-sortable-tree is agnostic to the tree implementation. All you have to do is expose a sorting attribute and a few tree methods (:parent, :children and :roots). Let’s say you use Ancestry:

    class Page < ActiveRecord::Base
      attr_accessible :title, :body, :position
      has_ancestry :orphan_strategy => :rootify
    end
    

    You can configure these methods if you need:

    ActiveAdmin.register Page do
      sortable tree: true,
               max_levels: 0, # infinite indent levels
               protect_root: false, # allow root items to be dragged
               sorting_attribute: :position,
               parent_method: :parent,
               children_method: :children,
               roots_method: :roots
      ...
    end

Usage (List)

  • Admin (eg. app/admin/page.rb):

    ActiveAdmin.register Page do
      sortable
    
      index :as => :sortable do
        label :title # item content
        default_actions
      end
    end
    
  • Model: Sortable list assumes you have a :position field in your resource. Of course it’s configurable:

    ActiveAdmin.register Page do
      sortable tree: false, # default
               sorting_attribute: :my_position_field
      ...
    end

Usage (generic ActiveAdmin index)

Currently supports only IndexAsBlock, more to come!

  • Admin (eg. app/admin/page.rb):

    ActiveAdmin.register Page do
      sortable
    
      index :as => :block do |page|
        # item content
      end
    end
    
  • Model: Same as list view (see above)

Copyright © 2013 Francesco Disperati, Cantiere Creativo. See the file MIT-LICENSE for details.

About

Lost old gem recovered from Heroku

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published