mirror of
https://github.com/redmine/redmine.git
synced 2025-11-15 17:56:03 +01:00
Always preserve the tree structure in the project jump box (#32944).
Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@19861 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -499,13 +499,15 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_projects_for_jump_box(projects, selected=nil)
|
def render_projects_for_jump_box(projects, selected: nil, query: nil)
|
||||||
|
if query.blank?
|
||||||
jump_box = Redmine::ProjectJumpBox.new User.current
|
jump_box = Redmine::ProjectJumpBox.new User.current
|
||||||
query = params[:q] if request.format.js?
|
bookmarked = jump_box.bookmarked_projects
|
||||||
bookmarked = jump_box.bookmarked_projects(query)
|
recents = jump_box.recently_used_projects
|
||||||
recents = jump_box.recently_used_projects(query)
|
projects_label = :label_project_all
|
||||||
projects = projects - (recents + bookmarked)
|
else
|
||||||
projects_label = (bookmarked.any? || recents.any?) ? :label_optgroup_others : :label_project_plural
|
projects_label = :label_result_plural
|
||||||
|
end
|
||||||
jump = params[:jump].presence || current_menu_item
|
jump = params[:jump].presence || current_menu_item
|
||||||
s = (+'').html_safe
|
s = (+'').html_safe
|
||||||
build_project_link = ->(project, level = 0){
|
build_project_link = ->(project, level = 0){
|
||||||
@@ -551,7 +553,7 @@ module ApplicationHelper
|
|||||||
content =
|
content =
|
||||||
content_tag('div',
|
content_tag('div',
|
||||||
content_tag('div', q, :class => 'quick-search') +
|
content_tag('div', q, :class => 'quick-search') +
|
||||||
content_tag('div', render_projects_for_jump_box(projects, @project),
|
content_tag('div', render_projects_for_jump_box(projects, selected: @project),
|
||||||
:class => 'drdn-items projects selection') +
|
:class => 'drdn-items projects selection') +
|
||||||
content_tag('div', all, :class => 'drdn-items all-projects selection'),
|
content_tag('div', all, :class => 'drdn-items all-projects selection'),
|
||||||
:class => 'drdn-content')
|
:class => 'drdn-content')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<%
|
<%
|
||||||
s = ''
|
s = ''
|
||||||
if @projects.any?
|
if @projects.any?
|
||||||
s = render_projects_for_jump_box(@projects)
|
s = render_projects_for_jump_box(@projects, query: params[:q])
|
||||||
elsif params[:q].present?
|
elsif params[:q].present?
|
||||||
s = content_tag('span', l(:label_no_data))
|
s = content_tag('span', l(:label_no_data))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
$('#project-jump div.drdn-items.projects').html('<%= j render_projects_for_jump_box(projects_for_jump_box(User.current), @project) %>');
|
$('#project-jump div.drdn-items.projects').html('<%= j render_projects_for_jump_box(projects_for_jump_box(User.current), selected: @project) %>');
|
||||||
$('.contextual a.icon.bookmark').replaceWith('<%= j bookmark_link @project %>');
|
$('.contextual a.icon.bookmark').replaceWith('<%= j bookmark_link @project %>');
|
||||||
|
|||||||
@@ -28,24 +28,16 @@ module Redmine
|
|||||||
@user.pref.recently_used_projects
|
@user.pref.recently_used_projects
|
||||||
end
|
end
|
||||||
|
|
||||||
def recently_used_projects(query = nil)
|
def recently_used_projects
|
||||||
project_ids = recently_used_project_ids
|
project_ids = recently_used_project_ids
|
||||||
projects = Project.where(id: project_ids)
|
Project.where(id: project_ids).
|
||||||
if query
|
|
||||||
projects = projects.like(query)
|
|
||||||
end
|
|
||||||
projects.
|
|
||||||
index_by(&:id).
|
index_by(&:id).
|
||||||
values_at(*project_ids). # sort according to stored order
|
values_at(*project_ids). # sort according to stored order
|
||||||
compact
|
compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def bookmarked_projects(query = nil)
|
def bookmarked_projects
|
||||||
projects = Project.where(id: bookmarked_project_ids).visible
|
Project.where(id: bookmarked_project_ids).visible.to_a
|
||||||
if query
|
|
||||||
projects = projects.like(query)
|
|
||||||
end
|
|
||||||
projects.to_a
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_used(project)
|
def project_used(project)
|
||||||
|
|||||||
@@ -28,13 +28,10 @@ class Redmine::ProjectJumpBoxTest < ActiveSupport::TestCase
|
|||||||
@onlinestore = Project.find 'onlinestore'
|
@onlinestore = Project.find 'onlinestore'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_filter_bookmarked_projects
|
def test_should_find_bookmarked_projects
|
||||||
pjb = Redmine::ProjectJumpBox.new @user
|
pjb = Redmine::ProjectJumpBox.new @user
|
||||||
pjb.bookmark_project @ecookbook
|
pjb.bookmark_project @ecookbook
|
||||||
|
|
||||||
assert_equal 1, pjb.bookmarked_projects.size
|
assert_equal 1, pjb.bookmarked_projects.size
|
||||||
assert_equal 0, pjb.bookmarked_projects('online').size
|
|
||||||
assert_equal 1, pjb.bookmarked_projects('ecook').size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_not_include_bookmark_in_recently_used_list
|
def test_should_not_include_bookmark_in_recently_used_list
|
||||||
@@ -47,13 +44,10 @@ class Redmine::ProjectJumpBoxTest < ActiveSupport::TestCase
|
|||||||
assert_equal 0, pjb.recently_used_projects.size
|
assert_equal 0, pjb.recently_used_projects.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_filter_recently_used_projects
|
def test_should_find_recently_used_projects
|
||||||
pjb = Redmine::ProjectJumpBox.new @user
|
pjb = Redmine::ProjectJumpBox.new @user
|
||||||
pjb.project_used @ecookbook
|
pjb.project_used @ecookbook
|
||||||
|
|
||||||
assert_equal 1, pjb.recently_used_projects.size
|
assert_equal 1, pjb.recently_used_projects.size
|
||||||
assert_equal 0, pjb.recently_used_projects('online').size
|
|
||||||
assert_equal 1, pjb.recently_used_projects('ecook').size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_limit_recently_used_projects
|
def test_should_limit_recently_used_projects
|
||||||
@@ -64,8 +58,6 @@ class Redmine::ProjectJumpBoxTest < ActiveSupport::TestCase
|
|||||||
@user.pref.recently_used_projects = 1
|
@user.pref.recently_used_projects = 1
|
||||||
|
|
||||||
assert_equal 1, pjb.recently_used_projects.size
|
assert_equal 1, pjb.recently_used_projects.size
|
||||||
assert_equal 1, pjb.recently_used_projects('online').size
|
|
||||||
assert_equal 0, pjb.recently_used_projects('ecook').size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_record_recently_used_projects_order
|
def test_should_record_recently_used_projects_order
|
||||||
|
|||||||
Reference in New Issue
Block a user