tested with rails 4.1.0rc2 + haml 4
Nested Set + Drag&Drop GUI. Very fast! Best render helper! 2000 nodes/sec. Ready for rails 4 (RubyGems)
Awesome nested set, Nested set, Ruby, Rails, Nested set view helper, Sortable nested set, Drag&Drop GUI for nested set, View helper for nested set, render tree
Gemfile (Rails 3, Rails 4)
gem 'awesome_nested_set' # or any similar gem (gem 'nested_set')
gem "the_sortable_tree", "~> 2.5.0"
Console
bundle
app/assets/javascripts/application.js
Sortable GUI require JQuery libs
//= require jquery
//= require jquery-ui
//= require jquery_ujs
Add next JS only for Sortable GUI
//= require the_sortable_tree/jquery.ui.nestedSortable
//= require the_sortable_tree/sortable_ui/base
// with Turbolinks
$ ->
TheSortableTree.SortableUI.init()
// with Turbolinks
$(document).on "ready page:load", ->
TheSortableTree.SortableUI.init()
app/assets/stylesheets/application.css
*= require tree
*= require sortable_tree
*= require nested_options
*= the_sortable_tree/sortable_ui/base
ol.the-sortable-tree.the-sortable-tree--list(data={ max_levels: 5, rebuild_url: rebuild_hubs_url })
= sortable_tree @hubs
resources :pages do
collection do
get :manage
# required for Sortable GUI server side actions
post :rebuild
end
end
manage - just page, where you want render Sortable tree.
class Page < ActiveRecord::Base
acts_as_nested_set scope: :user
include ::TheSortableTree::Scopes
# any code here
end
class PagesController < ApplicationController
include ::TheSortableTreeController::Rebuild
def manage
@pages = Page.nested_set.select('id, title, content, parent_id').all
end
# any code here
end
build_server_tree(tree, options)
app/views/pages/manage.html.haml
%ol.tree= just_tree @pages
just_tree is just alias of build_server_tree(tree, type: :tree)
%ol.sortable_tree{ data: { max_levels: 5, rebuild_url: rebuild_pages_url } }
= sortable_tree @pages
sortable_tree is just alias of build_server_tree(tree, type: :sortable)
= select_tag :page_id, nested_options(@pages, :selected => Page.last), class: :nested_options
nested_options is just alias of build_server_tree(tree, type: :nested_options)
Client side:
Required params for sortable GUI! Must be defined at root element of tree.
%ol.sortable_tree{ data: { max_levels: 3, rebuild_url: rebuild_pages_url } }
Server side:
define
build_server_tree(pages, {:option_1 => :value_1, :option_2 => :value_2})
use
options[:NAME]
Options list:
Rendering runtime params (see code of render helpers):
You can use next options, when rendering run:
Try to run next view generators:
Render helpers for HTML tree generation
bundle exec rails g the_sortable_tree:views tree
bundle exec rails g the_sortable_tree:views sortable
bundle exec rails g the_sortable_tree:views nested_options
Base Render helper of gem
bundle exec rails g the_sortable_tree:views helper
Assets of gem
bundle exec rails g the_sortable_tree:views assets
BANCHMARK:
tree params: 16.000 nodes, 3 levels
total: ~ 2000 nodes/sec
Do you want to be open source contributor? There are some ideas:
Try to create view helpers for:
this line fot testing with submodules
Copyright 2009-2013 Ilya N. Zykin (the-teacher), Mikhail Dieterle (Mik-die), Matthew Clark
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.