- Notifications
You must be signed in to change notification settings - Fork127
Nested Set + Drag&Drop GUI. Very fast! Best render helper! 2000 nodes/sec. Ready for rails 4
License
the-teacher/the_sortable_tree
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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
//=requirejquery//=requirejquery-ui//=requirejquery_ujs
Add next JS only for Sortable GUI
//=requirethe_sortable_tree/jquery.ui.nestedSortable//=requirethe_sortable_tree/sortable_ui/base//withTurbolinks$ ->TheSortableTree.SortableUI.init()//withTurbolinks$(document).on"ready page:load",->TheSortableTree.SortableUI.init()
app/assets/stylesheets/application.css
*=requiretree*=requiresortable_tree*=requirenested_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:pagesdocollectiondoget:manage# required for Sortable GUI server side actionspost:rebuildendend
manage - just page, where you want render Sortable tree.
classPage <ActiveRecord::Baseacts_as_nested_setscope::userinclude ::TheSortableTree::Scopes# any code hereend
classPagesController <ApplicationControllerinclude ::TheSortableTreeController::Rebuilddefmanage@pages=Page.nested_set.select('id, title, content, parent_id').allend# any code hereend
build_server_tree(tree,options)
app/views/pages/manage.html.haml
%ol.tree= just_tree @pages
just_tree is just alias ofbuild_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 ofbuild_server_tree(tree, type: :sortable)
= select_tag :page_id, nested_options(@pages, :selected => Page.last), class: :nested_options
nested_options is just alias ofbuild_server_tree(tree, type: :nested_options)
Client side:
Required params for sortable GUI! Must be defined at root element of tree.
- max_levels - maximum depth of nesting
- rebuild_url - URL to rebuild method on server side
%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:
- id - id field of node
- title - title field of node
- type - type of tree [tree|sortable|nested_options]
- namespace - for example::admin.[] - by default
- render_module - your own Render Tree Helper
Rendering runtime params (see code of render helpers):
You can use next options, when rendering run:
- level - level number
- root - root flag [true|false]
- klass - class name
- has_children - has children flag [true|false]
- children - array of children
Try to run next view generators:
Render helpers for HTML tree generation
bundleexecrailsgthe_sortable_tree:viewstreebundleexecrailsgthe_sortable_tree:viewssortablebundleexecrailsgthe_sortable_tree:viewsnested_options
Base Render helper of gem
bundleexecrailsgthe_sortable_tree:viewshelper
Assets of gem
bundleexecrailsgthe_sortable_tree:viewsassets
- How to change HTML code of tree?
- How to create new tree HTML Builder helper?
- I need to render reversed tree
- Gem can't correctly define a Name of your Model
- ChangeLog
BANCHMARK:
tree params: 16.000 nodes, 3 levels
- Views: 7999.6ms | ActiveRecord: 79.2ms
- WebInspector full time ~ 9.64s
total: ~2000 nodes/sec
Do you want to be open source contributor? There are some ideas:
Try to create view helpers for:
- Mongoid NestedSet
- acts_as_ordered_tree
- Expand tree via AJAX
- Comments Tree gem
- gem Ancestry (???)
- I'm develop gem with test appthe_sortable_tree_test_app. You can clone it and see some testcase-pages for gem
- Sorry, but I have not tests for this gem. Gem is so simple. It's easy to test only with test app.
- You can write some tests, if your need. I will be happy certainly.
- No! I know RSpec. I can write tests. But I have not reasons to write tests here.
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 obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall beincluded 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 OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BELIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTIONOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIONWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
About
Nested Set + Drag&Drop GUI. Very fast! Best render helper! 2000 nodes/sec. Ready for rails 4