From: Jean-Philippe Lang Date: Sat, 13 May 2017 09:20:29 +0000 (+0000) Subject: Moves project quick search to a dedicated action. X-Git-Tag: 3.4.0~128 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=23dc61685066faab63f366fc5d7f88f985431359;p=redmine.git Moves project quick search to a dedicated action. git-svn-id: http://svn.redmine.org/redmine/trunk@16550 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 99a39af3b..ec0c13119 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 29bc54157..94382a37b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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') + diff --git a/app/views/projects/autocomplete.js.erb b/app/views/projects/autocomplete.js.erb new file mode 100644 index 000000000..de6c3f579 --- /dev/null +++ b/app/views/projects/autocomplete.js.erb @@ -0,0 +1,2 @@ +<% s = @projects.any? ? render_projects_for_jump_box(@projects) : content_tag('span', l(:label_no_data)) %> +$('#project-jump .drdn-items.projects').html('<%= escape_javascript s %>'); diff --git a/app/views/projects/index.js.erb b/app/views/projects/index.js.erb deleted file mode 100644 index de6c3f579..000000000 --- a/app/views/projects/index.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -<% s = @projects.any? ? render_projects_for_jump_box(@projects) : content_tag('span', l(:label_no_data)) %> -$('#project-jump .drdn-items.projects').html('<%= escape_javascript s %>'); diff --git a/config/routes.rb b/config/routes.rb index ab1e1bcab..ae7c6c98a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index db81206fb..92d5f4a56 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -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 diff --git a/test/integration/routing/projects_test.rb b/test/integration/routing/projects_test.rb index ed68ec69d..a7e3e96e7 100644 --- a/test/integration/routing/projects_test.rb +++ b/test/integration/routing/projects_test.rb @@ -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'