Patch #30071 » 0001-show-ascendant-parent-projects-when-filtering-projec.patch
| app/controllers/projects_controller.rb | ||
|---|---|---|
|
respond_to do |format|
|
||
|
format.js {
|
||
|
if params[:q].present?
|
||
|
@projects = Project.visible.like(params[:q]).to_a
|
||
|
@projects = Project.visible.to_a
|
||
|
else
|
||
|
@projects = User.current.projects.to_a
|
||
|
end
|
||
| app/helpers/application_helper.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def render_projects_for_jump_box(projects, selected=nil)
|
||
|
def render_projects_for_jump_box(projects, q, selected=nil)
|
||
|
jump = params[:jump].presence || current_menu_item
|
||
|
options = {}
|
||
|
if !q.blank?
|
||
|
options[:q] = q.to_s
|
||
|
end
|
||
|
s = ''.html_safe
|
||
|
project_tree(projects) do |project, level|
|
||
|
project_tree(projects, options) do |project, level, css|
|
||
|
padding = level * 16
|
||
|
text = content_tag('span', project.name, :style => "padding-left:#{padding}px;")
|
||
|
s << link_to(text, project_path(project, :jump => jump), :title => project.name, :class => (project == selected ? 'selected' : nil))
|
||
|
css_class = []
|
||
|
css_class << 'selected' if project == selected
|
||
|
css_class << css if css
|
||
|
s << link_to(text, project_path(project, :jump => jump), :title => project.name, :class => css_class.any? ? css_class.join(' ') : nil)
|
||
|
end
|
||
|
s
|
||
|
end
|
||
| ... | ... | |
|
all = link_to(l(:label_project_all), projects_path(:jump => current_menu_item), :class => (@project.nil? && controller.class.main_menu ? 'selected' : nil))
|
||
|
content = content_tag('div',
|
||
|
content_tag('div', q, :class => 'quick-search') +
|
||
|
content_tag('div', render_projects_for_jump_box(projects, @project), :class => 'drdn-items projects selection') +
|
||
|
content_tag('div', render_projects_for_jump_box(projects, nil, @project), :class => 'drdn-items projects selection') +
|
||
|
content_tag('div', all, :class => 'drdn-items all-projects selection'),
|
||
|
:class => 'drdn-content'
|
||
|
)
|
||
| ... | ... | |
|
#
|
||
|
# Wrapper for Project#project_tree
|
||
|
def project_tree(projects, options={}, &block)
|
||
|
Project.project_tree(projects, options, &block)
|
||
|
if options[:q].blank?
|
||
|
Project.project_tree(projects, options, &block)
|
||
|
else
|
||
|
project_tree_filtered(projects, options, options[:q], &block)
|
||
|
end
|
||
|
end
|
||
|
# Like project_tree, but filters the tree to projects (and ascendants) containing a string
|
||
|
def project_tree_filtered(projects, options={}, q, &block)
|
||
|
q = q.downcase
|
||
|
match_enum = projects.sort_by(&:lft).select do |project|
|
||
|
project.identifier.include?(q) || project.name.downcase.include?(q)
|
||
|
end.each
|
||
|
begin
|
||
|
next_match = match_enum.next
|
||
|
Project.project_tree(projects, options) do |project, level|
|
||
|
# make sure next match is not behind the current node
|
||
|
while next_match.lft < project.lft
|
||
|
next_match = match_enum.next
|
||
|
end
|
||
|
|
||
|
if next_match.is_or_is_descendant_of?(project)
|
||
|
yield project, level, next_match == project ? "match" : "matches-child"
|
||
|
end
|
||
|
end
|
||
|
rescue StopIteration
|
||
|
# no more matches
|
||
|
end
|
||
|
end
|
||
|
def principals_check_box_tags(name, principals)
|
||
| app/views/projects/autocomplete.js.erb | ||
|---|---|---|
|
<%
|
||
|
s = ''
|
||
|
if @projects.any?
|
||
|
s = render_projects_for_jump_box(@projects)
|
||
|
s = render_projects_for_jump_box(@projects, params[:q])
|
||
|
elsif params[:q].present?
|
||
|
s = content_tag('span', l(:label_no_data))
|
||
|
end
|
||
| public/stylesheets/application.css | ||
|---|---|---|
|
.drdn-items.selection>*.selected:before {
|
||
|
content:"\2713 ";
|
||
|
}
|
||
|
.drdn-items.selection>*.matches-child {
|
||
|
font-weight: lighter;
|
||
|
}
|
||
|
.drdn-items.selection:empty {
|
||
|
border: none;
|
||
|
}
|
||