Project

General

Profile

Feature #32944 » 0001-project-jump-box-usability-enhancements.patch

Jens Krämer, 2020-07-01 11:21

View differences:

app/helpers/application_helper.rb
499 499
    end
500 500
  end
501 501

  
502
  def render_projects_for_jump_box(projects, selected=nil)
503
    jump_box = Redmine::ProjectJumpBox.new User.current
504
    query = params[:q] if request.format.js?
505
    bookmarked = jump_box.bookmarked_projects(query)
506
    recents = jump_box.recently_used_projects(query)
507
    projects = projects - (recents + bookmarked)
508
    projects_label = (bookmarked.any? || recents.any?) ? :label_optgroup_others : :label_project_plural
502
  def render_projects_for_jump_box(projects, selected: nil, query: nil)
503
    if query.blank?
504
      jump_box = Redmine::ProjectJumpBox.new User.current
505
      bookmarked = jump_box.bookmarked_projects
506
      recents = jump_box.recently_used_projects
507
      projects_label = :label_project_all
508
    else
509
      projects_label = :label_result_plural
510
    end
509 511
    jump = params[:jump].presence || current_menu_item
510 512
    s = (+'').html_safe
511 513
    build_project_link = ->(project, level = 0){
......
551 553
    content =
552 554
      content_tag('div',
553 555
                  content_tag('div', q, :class => 'quick-search') +
554
                    content_tag('div', render_projects_for_jump_box(projects, @project),
556
                    content_tag('div', render_projects_for_jump_box(projects, selected: @project),
555 557
                                :class => 'drdn-items projects selection') +
556 558
                    content_tag('div', all, :class => 'drdn-items all-projects selection'),
557 559
                  :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/3)