GitLab steht Mittwoch, den 23. September, zwischen 10:00 und 12:00 Uhr aufgrund von Wartungsarbeiten nicht zur Verfügung.

Commit 9c9ba3cf authored by jplang's avatar jplang

Moves project quick search to a dedicated action.

git-svn-id: https://svn.redmine.org/redmine/trunk@16550 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 5bbc0d0a
......@@ -20,8 +20,8 @@ class ProjectsController < ApplicationController
menu_item :settings, :only => :settings
menu_item :projects, :only => [:index, :new, :copy, :create]
before_action :find_project, :except => [ :index, :list, :new, :create, :copy ]
before_action :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
before_action :find_project, :except => [ :index, :autocomplete, :list, :new, :create, :copy ]
before_action :authorize, :except => [ :index, :autocomplete, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
before_action :authorize_global, :only => [:new, :create]
before_action :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
accept_rss_auth :index
......@@ -50,13 +50,6 @@ class ProjectsController < ApplicationController
end
@projects = scope.to_a
}
format.js {
if params[:q].present?
@projects = Project.visible.like(params[:q]).to_a
else
@projects = User.current.projects.to_a
end
}
format.api {
@offset, @limit = api_offset_and_limit
@project_count = scope.count
......@@ -69,6 +62,18 @@ class ProjectsController < ApplicationController
end
end
def autocomplete
respond_to do |format|
format.js {
if params[:q].present?
@projects = Project.visible.like(params[:q]).to_a
else
@projects = User.current.projects.to_a
end
}
end
end
def new
@issue_custom_fields = IssueCustomField.sorted.to_a
@trackers = Tracker.sorted.to_a
......
......@@ -370,7 +370,7 @@ module ApplicationHelper
projects = projects_for_jump_box(User.current)
text = @project.try(:name) || l(:label_jump_to_a_project)
trigger = content_tag('span', text, :class => 'drdn-trigger')
q = text_field_tag('q', '', :id => 'projects-quick-search', :class => 'autocomplete', :data => {:automcomplete_url => projects_path(:format => 'js')}, :autocomplete => 'off')
q = text_field_tag('q', '', :id => 'projects-quick-search', :class => 'autocomplete', :data => {:automcomplete_url => autocomplete_projects_path(:format => 'js')}, :autocomplete => 'off')
all = link_to(l(:label_project_all), projects_path(:jump => current_menu_item), :class => (@project.nil? && controller.class.main_menu ? 'selected' : nil))
content = content_tag('div',
content_tag('div', q, :class => 'quick-search') +
......
......@@ -101,6 +101,10 @@ Rails.application.routes.draw do
delete 'issues/:object_id/watchers/:user_id' => 'watchers#destroy', :object_type => 'issue'
resources :projects do
collection do
get 'autocomplete'
end
member do
get 'settings(/:tab)', :action => 'settings', :as => 'settings'
post 'modules'
......
......@@ -52,8 +52,8 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_select 'feed>entry', :count => Project.visible(User.current).count
end
def test_index_js
xhr :get, :index, :format => 'js', :q => 'coo'
def test_autocomplete_js
xhr :get, :autocomplete, :format => 'js', :q => 'coo'
assert_response :success
assert_equal 'text/javascript', response.content_type
end
......
......@@ -24,6 +24,8 @@ class RoutingProjectsTest < Redmine::RoutingTest
should_route 'GET /projects/new' => 'projects#new'
should_route 'POST /projects' => 'projects#create'
should_route 'GET /projects/autocomplete.js' => 'projects#autocomplete', :format => 'js'
should_route 'GET /projects/foo' => 'projects#show', :id => 'foo'
should_route 'PUT /projects/foo' => 'projects#update', :id => 'foo'
should_route 'DELETE /projects/foo' => 'projects#destroy', :id => 'foo'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment