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"
WARNING! Not compatible with neo/activeadmin-sortable
-
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)
To implement "Add Subcategory" in the index view,
STEP 1:Create the below method in the resource file
ActiveAdmin.register ResourceModel do
...
member_action :new_child do
//Code to display Add New [Child Resource] form
//params[:id] is the parent object id
//Create the corresponding form in app/views/admin/...
end
...
end
STEP 2:Add Label to Locales en.yml
add_subcategory: "Add Subcategory [Text or html entity]"
Copyright © 2013 Francesco Disperati, Cantiere Creativo. See the file MIT-LICENSE for details.