This gem adds a tree and a list view to your ActiveAdmin resource index, both sortable via drag’n’drop.
-
Gemfile:
gem "activeadmin-sortable-tree", :github => "nebirhos/activeadmin-sortable-tree", :branch => "master"
-
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
-
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
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.