406 |
406 |
end
|
407 |
407 |
end
|
408 |
408 |
|
409 |
|
def render_projects_for_jump_box(projects, selected=nil)
|
|
409 |
def render_projects_for_jump_box(projects, q, selected=nil)
|
410 |
410 |
jump = params[:jump].presence || current_menu_item
|
|
411 |
options = {}
|
|
412 |
if !q.blank?
|
|
413 |
options[:q] = q.to_s
|
|
414 |
end
|
411 |
415 |
s = ''.html_safe
|
412 |
|
project_tree(projects) do |project, level|
|
|
416 |
project_tree(projects, options) do |project, level, css|
|
413 |
417 |
padding = level * 16
|
414 |
418 |
text = content_tag('span', project.name, :style => "padding-left:#{padding}px;")
|
415 |
|
s << link_to(text, project_path(project, :jump => jump), :title => project.name, :class => (project == selected ? 'selected' : nil))
|
|
419 |
css_class = []
|
|
420 |
css_class << 'selected' if project == selected
|
|
421 |
css_class << css if css
|
|
422 |
s << link_to(text, project_path(project, :jump => jump), :title => project.name, :class => css_class.any? ? css_class.join(' ') : nil)
|
416 |
423 |
end
|
417 |
424 |
s
|
418 |
425 |
end
|
... | ... | |
431 |
438 |
all = link_to(l(:label_project_all), projects_path(:jump => current_menu_item), :class => (@project.nil? && controller.class.main_menu ? 'selected' : nil))
|
432 |
439 |
content = content_tag('div',
|
433 |
440 |
content_tag('div', q, :class => 'quick-search') +
|
434 |
|
content_tag('div', render_projects_for_jump_box(projects, @project), :class => 'drdn-items projects selection') +
|
|
441 |
content_tag('div', render_projects_for_jump_box(projects, nil, @project), :class => 'drdn-items projects selection') +
|
435 |
442 |
content_tag('div', all, :class => 'drdn-items all-projects selection'),
|
436 |
443 |
:class => 'drdn-content'
|
437 |
444 |
)
|
... | ... | |
465 |
472 |
#
|
466 |
473 |
# Wrapper for Project#project_tree
|
467 |
474 |
def project_tree(projects, options={}, &block)
|
468 |
|
Project.project_tree(projects, options, &block)
|
|
475 |
if options[:q].blank?
|
|
476 |
Project.project_tree(projects, options, &block)
|
|
477 |
else
|
|
478 |
project_tree_filtered(projects, options, options[:q], &block)
|
|
479 |
end
|
|
480 |
end
|
|
481 |
|
|
482 |
# Like project_tree, but filters the tree to projects (and ascendants) containing a string
|
|
483 |
def project_tree_filtered(projects, options={}, q, &block)
|
|
484 |
q = q.downcase
|
|
485 |
match_enum = projects.sort_by(&:lft).select do |project|
|
|
486 |
project.identifier.include?(q) || project.name.downcase.include?(q)
|
|
487 |
end.each
|
|
488 |
|
|
489 |
begin
|
|
490 |
next_match = match_enum.next
|
|
491 |
Project.project_tree(projects, options) do |project, level|
|
|
492 |
# make sure next match is not behind the current node
|
|
493 |
while next_match.lft < project.lft
|
|
494 |
next_match = match_enum.next
|
|
495 |
end
|
|
496 |
|
|
497 |
if next_match.is_or_is_descendant_of?(project)
|
|
498 |
yield project, level, next_match == project ? "match" : "matches-child"
|
|
499 |
end
|
|
500 |
end
|
|
501 |
rescue StopIteration
|
|
502 |
# no more matches
|
|
503 |
end
|
469 |
504 |
end
|
470 |
505 |
|
471 |
506 |
def principals_check_box_tags(name, principals)
|