Skip to content

Commit

Permalink
Merge pull request #2747 from vladimir-tikhonov/master
Browse files Browse the repository at this point in the history
Speed up page reordering
  • Loading branch information
parndt committed Nov 8, 2014
2 parents e549c12 + 461f1d7 commit c086f4f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/lib/refinery/crud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def update_positions
if @current_#{singular_name}.respond_to?(:move_to_root)
if previous.present?
@current_#{singular_name}.move_to_right_of(#{class_name}.find_by_id(previous))
else
elsif !@current_#{singular_name}.root?
@current_#{singular_name}.move_to_root
end
else
Expand All @@ -313,10 +313,14 @@ def update_positions
def update_child_positions(_node, #{singular_name})
list = _node['children']['0']
child_positions_changed = false
list.sort_by {|k, v| k.to_i}.map { |item| item[1] }.each_with_index do |child, index|
child_id = child['id'].split(/#{singular_name}\_?/).reject(&:empty?).first
child_#{singular_name} = #{class_name}.where(:id => child_id).first
child_#{singular_name}.move_to_child_of(#{singular_name})
child_positions_changed ||= #{singular_name}.children[index] != child_#{singular_name}
if child_positions_changed
child_#{singular_name}.move_to_child_of(#{singular_name})
end
if child['children'].present?
update_child_positions(child, child_#{singular_name})
Expand Down

0 comments on commit c086f4f

Please sign in to comment.