Project

General

Profile

Patch #30071 » 0001-show-ascendant-parent-projects-when-filtering-projec.patch

Anders Thomsen, 2018-12-01 17:20

View differences:

app/controllers/projects_controller.rb
66 66
    respond_to do |format|
67 67
      format.js {
68 68
        if params[:q].present?
69
          @projects = Project.visible.like(params[:q]).to_a
69
          @projects = Project.visible.to_a
70 70
        else
71 71
          @projects = User.current.projects.to_a
72 72
        end
app/helpers/application_helper.rb
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)
app/views/projects/autocomplete.js.erb
1 1
<%
2 2
  s = ''
3 3
  if @projects.any?
4
    s = render_projects_for_jump_box(@projects)
4
    s = render_projects_for_jump_box(@projects, params[:q])
5 5
  elsif params[:q].present?
6 6
    s = content_tag('span', l(:label_no_data))
7 7
  end
public/stylesheets/application.css
200 200
.drdn-items.selection>*.selected:before {
201 201
  content:"\2713 ";
202 202
}
203

  
204
.drdn-items.selection>*.matches-child {
205
  font-weight: lighter;
206
}
207

  
203 208
.drdn-items.selection:empty {
204 209
  border: none;
205 210
}
(3-3/4)