Skip to content

Commit

Permalink
v2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
the-teacher committed Sep 28, 2016
1 parent 79547e6 commit b2f3110
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions app/helpers/the_sortable_tree_helper.rb
Expand Up @@ -32,7 +32,7 @@ def build_tree_html context, render_module, options = {}
###############################################
# Shortcuts
###############################################

def just_tree tree, options = {}
build_server_tree(tree, { :type => :tree }.merge!(options))
end
Expand Down Expand Up @@ -69,7 +69,7 @@ def build_server_tree(tree, options= {})
:namespace => [], # :admin

# BOOST! hash
:boost => {}
:boost => {}
}.merge!(options)

# Basic vars
Expand Down Expand Up @@ -110,9 +110,12 @@ def build_server_tree(tree, options= {})

# define roots, if it's need
if roots.nil? && !tree.empty?
# Looks like the new algo really does what we need (28 sept. 2016)
# Thanks to: https://github.com/patrick-nits
#
ids = tree.map(&:id)
opt_ids = opts[:boost].keys.map(&:to_i)
candidate_ids = (ids+opt_ids).uniq - (ids&opt_ids) #xor
candidate_ids = (ids + opt_ids).uniq - (ids & opt_ids) # xor
roots = candidate_ids.map {|c| opts[:boost][c.to_s]}.compact.flatten
end

Expand All @@ -129,7 +132,7 @@ def build_server_tree(tree, options= {})
children = opts[:boost][node.id.to_s]

# Boost OFF
# children = tree.select{ |_node| _node.parent_id == node.id }
# children = tree.select{ |_node| _node.parent_id == node.id }

opts.merge!({ :has_children => children.blank? })

Expand All @@ -145,4 +148,4 @@ def build_server_tree(tree, options= {})

raw result
end
end
end
3 changes: 3 additions & 0 deletions gem_version.rb
@@ -0,0 +1,3 @@
module TheSortableTree
VERSION = "2.6.0"
end
2 changes: 1 addition & 1 deletion lib/the_sortable_tree.rb
Expand Up @@ -13,7 +13,7 @@ def self.included(base)
scope :nested_set, lambda { order('lft ASC') }
scope :reversed_nested_set, lambda { order('lft DESC') }
else
puts "[TheSortableTree] ERROR: required Rails 3 or Rails 4"
puts "[TheSortableTree] ERROR: required Rails >= version 3"
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/the_sortable_tree/version.rb
@@ -1,3 +1 @@
module TheSortableTree
VERSION = "2.5.0"
end
require_relative '../../gem_version'

0 comments on commit b2f3110

Please sign in to comment.