##// END OF EJS Templates
Add params to Redmine::Search::Fetcher#initialize optional parameter (#23153)....
Jean-Philippe Lang -
r15201:48a79bc0938c
parent child
Show More
@@ -1,99 +1,99
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class SearchController < ApplicationController
19 19 before_filter :find_optional_project
20 20 accept_api_auth :index
21 21
22 22 def index
23 23 @question = params[:q] || ""
24 24 @question.strip!
25 25 @all_words = params[:all_words] ? params[:all_words].present? : true
26 26 @titles_only = params[:titles_only] ? params[:titles_only].present? : false
27 27 @search_attachments = params[:attachments].presence || '0'
28 28 @open_issues = params[:open_issues] ? params[:open_issues].present? : false
29 29
30 30 case params[:format]
31 31 when 'xml', 'json'
32 32 @offset, @limit = api_offset_and_limit
33 33 else
34 34 @offset = nil
35 35 @limit = Setting.search_results_per_page.to_i
36 36 @limit = 10 if @limit == 0
37 37 end
38 38
39 39 # quick jump to an issue
40 40 if (m = @question.match(/^#?(\d+)$/)) && (issue = Issue.visible.find_by_id(m[1].to_i))
41 41 redirect_to issue_path(issue)
42 42 return
43 43 end
44 44
45 45 projects_to_search =
46 46 case params[:scope]
47 47 when 'all'
48 48 nil
49 49 when 'my_projects'
50 50 User.current.projects
51 51 when 'subprojects'
52 52 @project ? (@project.self_and_descendants.active.to_a) : nil
53 53 else
54 54 @project
55 55 end
56 56
57 57 @object_types = Redmine::Search.available_search_types.dup
58 58 if projects_to_search.is_a? Project
59 59 # don't search projects
60 60 @object_types.delete('projects')
61 61 # only show what the user is allowed to view
62 62 @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, projects_to_search)}
63 63 end
64 64
65 65 @scope = @object_types.select {|t| params[t]}
66 66 @scope = @object_types if @scope.empty?
67 67
68 68 fetcher = Redmine::Search::Fetcher.new(
69 69 @question, User.current, @scope, projects_to_search,
70 70 :all_words => @all_words, :titles_only => @titles_only, :attachments => @search_attachments, :open_issues => @open_issues,
71 :cache => params[:page].present?
71 :cache => params[:page].present?, :params => params
72 72 )
73 73
74 74 if fetcher.tokens.present?
75 75 @result_count = fetcher.result_count
76 76 @result_count_by_type = fetcher.result_count_by_type
77 77 @tokens = fetcher.tokens
78 78
79 79 @result_pages = Paginator.new @result_count, @limit, params['page']
80 80 @offset ||= @result_pages.offset
81 81 @results = fetcher.results(@offset, @result_pages.per_page)
82 82 else
83 83 @question = ""
84 84 end
85 85 respond_to do |format|
86 86 format.html { render :layout => false if request.xhr? }
87 87 format.api { @results ||= []; render :layout => false }
88 88 end
89 89 end
90 90
91 91 private
92 92 def find_optional_project
93 93 return true unless params[:id]
94 94 @project = Project.find(params[:id])
95 95 check_project_privacy
96 96 rescue ActiveRecord::RecordNotFound
97 97 render_404
98 98 end
99 99 end
General Comments 0
You need to be logged in to leave comments. Login now