All Projects → zorab47 → Active_admin Sortable_tree

zorab47 / Active_admin Sortable_tree

Licence: mit
Show ActiveAdmin index as a nested tree with drag'n'drop

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Active admin Sortable tree

active admin-subnav
Enhanced sub-navigation for nested ActiveAdmin resources
Stars: ✭ 20 (-86.93%)
Mutual labels:  activeadmin
Activeadmin trumbowyg
Trumbowyg Editor for ActiveAdmin
Stars: ✭ 29 (-81.05%)
Mutual labels:  activeadmin
Activeadmin quill editor
Quill Rich Text Editor for ActiveAdmin
Stars: ✭ 76 (-50.33%)
Mutual labels:  activeadmin
activeadmin-ajax filter
AJAX filters for ActiveAdmin
Stars: ✭ 86 (-43.79%)
Mutual labels:  activeadmin
Activeadmin addons
Extends ActiveAdmin to enable a set of great optional UX improving add-ons
Stars: ✭ 574 (+275.16%)
Mutual labels:  activeadmin
Activeadmin blaze theme
ActiveAdmin theme based on Blaze CSS toolkit
Stars: ✭ 35 (-77.12%)
Mutual labels:  activeadmin
Demo.activeadmin.info
A store application to use in tutorials for Active Admin
Stars: ✭ 253 (+65.36%)
Mutual labels:  activeadmin
Active bootstrap skin
Bootstrap skin for Active Admin 🚀 🚀 🚀
Stars: ✭ 133 (-13.07%)
Mutual labels:  activeadmin
Arbre
An Object Oriented DOM Tree in Ruby
Stars: ✭ 610 (+298.69%)
Mutual labels:  activeadmin
Activeadmin dynamic fields
ActiveAdmin plugin to add dynamic behaviors to fields
Stars: ✭ 73 (-52.29%)
Mutual labels:  activeadmin
active admin datetimepicker
📆 active_admin_datetimepicker gem
Stars: ✭ 68 (-55.56%)
Mutual labels:  activeadmin
activeadmin active resource
Active Admin + Active Resource: to use a REST API in place of a local database as data source
Stars: ✭ 20 (-86.93%)
Mutual labels:  activeadmin
Rademade admin
Best rails admin panel!
Stars: ✭ 40 (-73.86%)
Mutual labels:  activeadmin
activeadmin-latlng
Active Admin plugin for setting up latitude and longitude
Stars: ✭ 34 (-77.78%)
Mutual labels:  activeadmin
Formadmin
Modern and responsive theme for Active Admin used by Formaweb.
Stars: ✭ 79 (-48.37%)
Mutual labels:  activeadmin
active admin role
Role based authorization with CanCanCan for Active Admin
Stars: ✭ 53 (-65.36%)
Mutual labels:  activeadmin
Activeadmin froala editor
Froala WYSIWYG editor for ActiveAdmin
Stars: ✭ 30 (-80.39%)
Mutual labels:  activeadmin
Activeadmin Themes
Awesome themes for ActiveAdmin.
Stars: ✭ 141 (-7.84%)
Mutual labels:  activeadmin
Activeadmin
The administration framework for Ruby on Rails applications.
Stars: ✭ 9,096 (+5845.1%)
Mutual labels:  activeadmin
Activeadmin settings cached
UI interface for rails-settings-cached in active admin
Stars: ✭ 51 (-66.67%)
Mutual labels:  activeadmin

ActiveAdmin::SortableTree

Gem Version Build Status

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

ActiveAdmin::SortableTree Example

Installation

  1. Add SortableTree to your Gemfile; then bundle install

    gem "active_admin-sortable_tree", "~> 2.0.0"
    
  2. Add a require to your JavaScript manifest app/assets/javascripts/active_admin.js

    //= require active_admin/sortable
    
  3. Add an import in your stylesheet manifest app/assets/stylesheets/active_admin.scss

    @import "active_admin/sortable";
    

Usage (Tree)

Admin:

# app/admin/page.rb
ActiveAdmin.register Page do
  sortable tree: true

  index :as => :sortable do
    label :title # item content
    actions
  end
end

Model: ActiveAdmin::SortableTree 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,
           sorting_attribute: :position,
           parent_method: :parent,
           children_method: :children,
           roots_method: :roots,
           roots_collection: proc { current_user.pages.roots }
  # …
end

The option roots_collection provides full control on how to find the root nodes of your sortable tree and is evaluated within the context of the controller. Please note that roots_collection will override what is specified in roots_method.

Usage (List)

Admin:

# app/admin/page.rb
ActiveAdmin.register Page do
  sortable

  index :as => :sortable do
    label :title # item content
    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

Note: If you are using the acts_as_list gem to manage a :position field (not required, but allows for other nice programmatic manipulation of ordered model lists), you must ensure a zero-based index for your list using the top_of_list option:

class Page < ActiveRecord::Base
  # Make this list act like a zero-indexed array to avoid off-by-one errors in your sorting
  acts_as_list top_of_list: 0
end

Usage (generic ActiveAdmin index)

Currently supports only IndexAsBlock, more to come!

Admin:

# 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)

Customization

Full options list with defaults

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,
           roots_collection: nil,       # proc to specifiy retrieval of roots
           sortable: true,              # Disable sorting (use only 'tree' functionality)
           collapsible: false,          # show +/- buttons to collapse children
           start_collapsed: false,      # when collapsible, start with all roots collapsed
end

Actions

In IndexAsSortable you can add custom actions (with or without the defaults):

index :as => :sortable do
  actions defaults: false do |page|
    link_to "Custom action", my_custom_path(page)
  end
end

Ajax Callback Config

It exposes three Ajax Events: ajaxDone, ajaxFail and ajaxAlways, which correspond to jQuery ajax callbacks: done, fail and always.

To subscribe Ajax callback:

ActiveAdminSortableEvent.add('ajaxDone', function (){
  // do what you want
})

Upgrading to SortableTree 2.0 from 1.0

Upgrading from SortableTree 1.x requires manually specifying assets in your app/assets/javascripts/active_admin.js and app/assets/stylesheets/active_admin.scss files.

Dependencies

ActiveAdmin::SortableTree 2.0 supports ActiveAdmin 1.0.0+. For previous versions of ActiveAdmin use older SortableTree versions from the 1.x branch.

Note: If you experience issues with drag and drop capability, you may need to specify the version for your ActiveAdmin installation. It is reported working using v0.6.6, or if you are using v1.0.0.pre, it is reported working on this commit b3a9f4b or later.

# Gemfile
gem 'activeadmin', github: 'activeadmin', ref: 'b3a9f4b'

Suppressing warnings from Active Admin

As of Active Admin 1.1.0, config.register_stylesheet and config.register_javascript have been deprecated. ActiveAdmin::SortableTree uses these interfaces to register required assets automatically. Because of this, you may see a deprecation warning:

DEPRECATION WARNING: Active Admin: The `register_javascript` config is deprecated and will be removed
in v2. Import your "active_admin/sortable.js" javascript in the active_admin.js.
 (called from <main> at config/environment.rb:5)

You could opt out of it by setting config.aa_sortable_tree.register_assets to false:

# config/application.rb
config.aa_sortable_tree.register_assets = false

Semantic Versioning

ActiveAdmin::SortableTree follows semantic versioning.

Alternatives

Copyright

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].