1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-12 04:03:08 +00:00

Makes the project jump box work.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/work@2159 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-12-21 08:03:24 +00:00
parent 1f75a1f957
commit 2891ba2933
3 changed files with 29 additions and 13 deletions

View File

@ -147,6 +147,34 @@ module ApplicationHelper
end
content
end
# Renders the project quick-jump box
def render_project_jump_box
# Retrieve them now to avoid a COUNT query
projects = User.current.projects.all
if projects.any?
s = '<select onchange="if (this.value != '') { window.location = this.value; }">' +
"<option selected='selected'>#{ l(:label_jump_to_a_project) }</option>" +
'<option disabled="disabled">---</option>'
ancestors = []
project_tree(projects) do |project, level|
s << content_tag('option', ('&#187; ' * level) + h(project), :value => url_for(:controller => 'projects', :action => 'show', :id => project))
end
s << '</select>'
end
end
# Yields the given block for each project with its level in the tree
def project_tree(projects, &block)
ancestors = []
projects.sort_by(&:lft).each do |project|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
ancestors.pop
end
yield project, ancestors.size
ancestors << project
end
end
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)

View File

@ -1,12 +0,0 @@
<% user_projects_by_root = User.current.projects.find(:all).group_by(&:root) %>
<select onchange="if (this.value != '') { window.location = this.value; }">
<option selected="selected"><%= l(:label_jump_to_a_project) %></option>
<option disabled="disabled">---</option>
<% user_projects_by_root.keys.sort.each do |root| %>
<%= content_tag('option', h(root.name), :value => url_for(:controller => 'projects', :action => 'show', :id => root)) %>
<% user_projects_by_root[root].sort.each do |project| %>
<% next if project == root %>
<%= content_tag('option', ('&#187; ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project)) %>
<% end %>
<% end %>
</select>

View File

@ -34,7 +34,7 @@
<%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
<%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
<% end %>
<%= render :partial => 'layouts/project_selector' if User.current.memberships.any? %>
<%= render_project_jump_box %>
</div>
<h1><%= h(@project && !@project.new_record? ? @project.name : Setting.app_title) %></h1>