Project

General

Profile

RE: Hierarchy in project jump box » backport-r198610-to-4_1.diff

Go MAEDA, 2020-07-25 06:51

View differences:

app/helpers/application_helper.rb (作業コピー)
470 470
    end
471 471
  end
472 472

  
473
  def render_projects_for_jump_box(projects, selected=nil)
474
    jump_box = Redmine::ProjectJumpBox.new User.current
475
    query = params[:q] if request.format.js?
476
    bookmarked = jump_box.bookmarked_projects(query)
477
    recents = jump_box.recently_used_projects(query)
478
    projects = projects - (recents + bookmarked)
479
    projects_label = (bookmarked.any? || recents.any?) ? :label_optgroup_others : :label_project_plural
473
  def render_projects_for_jump_box(projects, selected: nil, query: nil)
474
    if query.blank?
475
      jump_box = Redmine::ProjectJumpBox.new User.current
476
      bookmarked = jump_box.bookmarked_projects
477
      recents = jump_box.recently_used_projects
478
      projects_label = :label_project_all
479
    else
480
      projects_label = :label_result_plural
481
    end
480 482
    jump = params[:jump].presence || current_menu_item
481 483
    s = (+'').html_safe
482 484
    build_project_link = ->(project, level = 0){
......
522 524
    content =
523 525
      content_tag('div',
524 526
                  content_tag('div', q, :class => 'quick-search') +
525
                    content_tag('div', render_projects_for_jump_box(projects, @project),
527
                    content_tag('div', render_projects_for_jump_box(projects, selected: @project),
526 528
                                :class => 'drdn-items projects selection') +
527 529
                    content_tag('div', all, :class => 'drdn-items all-projects selection'),
528 530
                  :class => 'drdn-content'
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, query: params[:q])
5 5
  elsif params[:q].present?
6 6
    s = content_tag('span', l(:label_no_data))
7 7
  end
app/views/projects/bookmark.js.erb (作業コピー)
1
$('#project-jump div.drdn-items.projects').html('<%= j render_projects_for_jump_box(projects_for_jump_box(User.current), @project) %>');
1
$('#project-jump div.drdn-items.projects').html('<%= j render_projects_for_jump_box(projects_for_jump_box(User.current), selected: @project) %>');
2 2
$('.contextual a.icon.bookmark').replaceWith('<%= j bookmark_link @project %>');
lib/redmine/project_jump_box.rb (作業コピー)
28 28
      @user.pref.recently_used_projects
29 29
    end
30 30

  
31
    def recently_used_projects(query = nil)
31
    def recently_used_projects
32 32
      project_ids = recently_used_project_ids
33
      projects = Project.where(id: project_ids)
34
      if query
35
        projects = projects.like(query)
36
      end
37
      projects.
33
      Project.where(id: project_ids).
38 34
        index_by(&:id).
39 35
        values_at(*project_ids). # sort according to stored order
40 36
        compact
41 37
    end
42 38

  
43
    def bookmarked_projects(query = nil)
44
      projects = Project.where(id: bookmarked_project_ids).visible
45
      if query
46
        projects = projects.like(query)
47
      end
48
      projects.to_a
39
    def bookmarked_projects
40
      Project.where(id: bookmarked_project_ids).visible.to_a
49 41
    end
50 42

  
51 43
    def project_used(project)
test/unit/lib/redmine/project_jump_box_test.rb (作業コピー)
28 28
    @onlinestore = Project.find 'onlinestore'
29 29
  end
30 30

  
31
  def test_should_filter_bookmarked_projects
31
  def test_should_find_bookmarked_projects
32 32
    pjb = Redmine::ProjectJumpBox.new @user
33 33
    pjb.bookmark_project @ecookbook
34

  
35 34
    assert_equal 1, pjb.bookmarked_projects.size
36
    assert_equal 0, pjb.bookmarked_projects('online').size
37
    assert_equal 1, pjb.bookmarked_projects('ecook').size
38 35
  end
39 36

  
40 37
  def test_should_not_include_bookmark_in_recently_used_list
......
47 44
    assert_equal 0, pjb.recently_used_projects.size
48 45
  end
49 46

  
50
  def test_should_filter_recently_used_projects
47
  def test_should_find_recently_used_projects
51 48
    pjb = Redmine::ProjectJumpBox.new @user
52 49
    pjb.project_used @ecookbook
53

  
54 50
    assert_equal 1, pjb.recently_used_projects.size
55
    assert_equal 0, pjb.recently_used_projects('online').size
56
    assert_equal 1, pjb.recently_used_projects('ecook').size
57 51
  end
58 52

  
59 53
  def test_should_limit_recently_used_projects
......
64 58
    @user.pref.recently_used_projects = 1
65 59

  
66 60
    assert_equal 1, pjb.recently_used_projects.size
67
    assert_equal 1, pjb.recently_used_projects('online').size
68
    assert_equal 0, pjb.recently_used_projects('ecook').size
69 61
  end
70 62

  
71 63
  def test_should_record_recently_used_projects_order
    (1-1/1)