Contextual quick search (#3263).
Eg. when viewing issues, the quick search will search issues only. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2943 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
739e11702a
commit
07aa3c55bd
|
@ -26,6 +26,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_filter :user_setup, :check_if_login_required, :set_localization
|
before_filter :user_setup, :check_if_login_required, :set_localization
|
||||||
filter_parameter_logging :password
|
filter_parameter_logging :password
|
||||||
|
|
||||||
|
include Redmine::Search::Controller
|
||||||
include Redmine::MenuManager::MenuController
|
include Redmine::MenuManager::MenuController
|
||||||
helper Redmine::MenuManager::MenuHelper
|
helper Redmine::MenuManager::MenuHelper
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class BoardsController < ApplicationController
|
class BoardsController < ApplicationController
|
||||||
|
default_search_scope :messages
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
helper :messages
|
helper :messages
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class DocumentsController < ApplicationController
|
class DocumentsController < ApplicationController
|
||||||
|
default_search_scope :documents
|
||||||
before_filter :find_project, :only => [:index, :new]
|
before_filter :find_project, :only => [:index, :new]
|
||||||
before_filter :find_document, :except => [:index, :new]
|
before_filter :find_document, :except => [:index, :new]
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class IssuesController < ApplicationController
|
class IssuesController < ApplicationController
|
||||||
menu_item :new_issue, :only => :new
|
menu_item :new_issue, :only => :new
|
||||||
|
default_search_scope :issues
|
||||||
|
|
||||||
before_filter :find_issue, :only => [:show, :edit, :reply]
|
before_filter :find_issue, :only => [:show, :edit, :reply]
|
||||||
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
|
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class MessagesController < ApplicationController
|
class MessagesController < ApplicationController
|
||||||
menu_item :boards
|
menu_item :boards
|
||||||
|
default_search_scope :messages
|
||||||
before_filter :find_board, :only => [:new, :preview]
|
before_filter :find_board, :only => [:new, :preview]
|
||||||
before_filter :find_message, :except => [:new, :preview]
|
before_filter :find_message, :except => [:new, :preview]
|
||||||
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
before_filter :authorize, :except => [:preview, :edit, :destroy]
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class NewsController < ApplicationController
|
class NewsController < ApplicationController
|
||||||
|
default_search_scope :news
|
||||||
before_filter :find_news, :except => [:new, :index, :preview]
|
before_filter :find_news, :except => [:new, :index, :preview]
|
||||||
before_filter :find_project, :only => [:new, :preview]
|
before_filter :find_project, :only => [:new, :preview]
|
||||||
before_filter :authorize, :except => [:index, :preview]
|
before_filter :authorize, :except => [:index, :preview]
|
||||||
|
|
|
@ -24,6 +24,8 @@ class InvalidRevisionParam < Exception; end
|
||||||
|
|
||||||
class RepositoriesController < ApplicationController
|
class RepositoriesController < ApplicationController
|
||||||
menu_item :repository
|
menu_item :repository
|
||||||
|
default_search_scope :changesets
|
||||||
|
|
||||||
before_filter :find_repository, :except => :edit
|
before_filter :find_repository, :except => :edit
|
||||||
before_filter :find_project, :only => :edit
|
before_filter :find_project, :only => :edit
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
require 'diff'
|
require 'diff'
|
||||||
|
|
||||||
class WikiController < ApplicationController
|
class WikiController < ApplicationController
|
||||||
|
default_search_scope :wiki_pages
|
||||||
before_filter :find_wiki, :authorize
|
before_filter :find_wiki, :authorize
|
||||||
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
|
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<div id="quick-search">
|
<div id="quick-search">
|
||||||
<% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
|
<% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
|
||||||
|
<%= hidden_field_tag(controller.default_search_scope, 1, :id => nil) if controller.default_search_scope %>
|
||||||
<%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
|
<%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
|
||||||
<%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
|
<%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
module Redmine
|
||||||
|
module Search
|
||||||
|
module Controller
|
||||||
|
def self.included(base)
|
||||||
|
base.extend(ClassMethods)
|
||||||
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
@@default_search_scopes = Hash.new {|hash, key| hash[key] = {:default => nil, :actions => {}}}
|
||||||
|
mattr_accessor :default_search_scopes
|
||||||
|
|
||||||
|
# Set the default search scope for a controller or specific actions
|
||||||
|
# Examples:
|
||||||
|
# * search_scope :issues # => sets the search scope to :issues for the whole controller
|
||||||
|
# * search_scope :issues, :only => :index
|
||||||
|
# * search_scope :issues, :only => [:index, :show]
|
||||||
|
def default_search_scope(id, options = {})
|
||||||
|
if actions = options[:only]
|
||||||
|
actions = [] << actions unless actions.is_a?(Array)
|
||||||
|
actions.each {|a| default_search_scopes[controller_name.to_sym][:actions][a.to_sym] = id.to_s}
|
||||||
|
else
|
||||||
|
default_search_scopes[controller_name.to_sym][:default] = id.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_search_scopes
|
||||||
|
self.class.default_search_scopes
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the default search scope according to the current action
|
||||||
|
def default_search_scope
|
||||||
|
@default_search_scope ||= default_search_scopes[controller_name.to_sym][:actions][action_name.to_sym] ||
|
||||||
|
default_search_scopes[controller_name.to_sym][:default]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1093,4 +1093,11 @@ class IssuesControllerTest < ActionController::TestCase
|
||||||
assert_equal 2, TimeEntry.find(1).issue_id
|
assert_equal 2, TimeEntry.find(1).issue_id
|
||||||
assert_equal 2, TimeEntry.find(2).issue_id
|
assert_equal 2, TimeEntry.find(2).issue_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_default_search_scope
|
||||||
|
get :index
|
||||||
|
assert_tag :div, :attributes => {:id => 'quick-search'},
|
||||||
|
:child => {:tag => 'form',
|
||||||
|
:child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue