Speeds up WikiHelper#wiki_page_options_for_select.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5080 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-03-10 19:44:32 +00:00
parent ef189164bf
commit 28feb58754
1 changed files with 10 additions and 7 deletions

View File

@ -18,14 +18,17 @@
module WikiHelper module WikiHelper
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0) def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
pages = pages.group_by(&:parent) unless pages.is_a?(Hash)
s = '' s = ''
pages.select {|p| p.parent == parent}.each do |page| if pages.has_key?(parent)
attrs = "value='#{page.id}'" pages[parent].each do |page|
attrs << " selected='selected'" if selected == page attrs = "value='#{page.id}'"
indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : nil attrs << " selected='selected'" if selected == page
indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : nil
s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
wiki_page_options_for_select(pages, selected, page, level + 1) s << "<option #{attrs}>#{indent}#{h page.pretty_title}</option>\n" +
wiki_page_options_for_select(pages, selected, page, level + 1)
end
end end
s s
end end