Project

General

Profile

Actions

Defect #18018

closed

Project Sorting by Name broken (for large project lists) in v2.x

Added by @ go2null about 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Projects
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Wont fix
Affected version:

Description

Apparently, this is due to the removal, in v2.5, of the patched awesome_nested_set plugin from the Redmine lib/plugins directory.
http://www.redmine.org/projects/redmine/repository/show/tags/2.4.6/lib/plugins
http://www.redmine.org/projects/redmine/repository/show/tags/2.5.0/lib/plugins
http://www.redmine.org/projects/redmine/repository/show/branches/2.4-stable/lib/plugins
http://www.redmine.org/projects/redmine/repository/show/branches/2.5-stable/lib/plugins

The patched awesome_nested_set is still available in trunk.
http://www.redmine.org/projects/redmine/repository/show/trunk/lib/plugins

Note that this either only affects large project lists (my Redmine has several hundreds) or old Redmine instances that were upgraded from pre-V2.5 and the Project.rebuild_tree"! method fix was not applied.

Workaround (#6836#note-12) per Ken Zalewski still works.

 set_left_and_rights = lambda do |node|
   # set left
   node[left_column_name] = indices[scope.call(node)] += 1
   # find
-  where(["#{quoted_parent_column_full_name} = ? #{scope.call(node)}", node]).order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each{|n| set_left_and_rights.call(n) }
+  where(["#{quoted_parent_column_full_name} = ? #{scope.call(node)}", node]).order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, name").each{|n| set_left_and_rights.call(n) }
   # set right
   node[right_column_name] = indices[scope.call(node)] += 1
   node.save!(:validate => validate_nodes)
 end

 # Find root node(s)
-  root_nodes = where("#{quoted_parent_column_full_name} IS NULL").order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, id").each do |root_node|
+  root_nodes = where("#{quoted_parent_column_full_name} IS NULL").order("#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, name").each do |root_node|
   # setup index for this scope
   indices[scope.call(root_node)] ||= 0
   set_left_and_rights.call(root_node)
 end

Related issues are:
  • Feature #6836 Sort project list by Name instead of identifier
  • Defect #12431 Project.rebuild! sorts root projects by id instead of name
  • Defect #11508 Projects not ordered alphabetically after renaming project
Actions

Also available in: Atom PDF