]> source.dussan.org Git - redmine.git/commitdiff
Option to search open issues only (#10734).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Jan 2015 10:09:34 +0000 (10:09 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Jan 2015 10:09:34 +0000 (10:09 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13858 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/search_controller.rb
app/models/issue.rb
app/views/search/index.html.erb
config/locales/en.yml
config/locales/fr.yml
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
test/functional/search_controller_test.rb

index e140878a9082dd891f9efcac7ad1b25d9d48a371..9bdfb0f5da6eb7748916ce7e6a94abe6fa4fdc6a 100644 (file)
@@ -24,6 +24,7 @@ class SearchController < ApplicationController
     @all_words = params[:all_words] ? params[:all_words].present? : true
     @titles_only = params[:titles_only] ? params[:titles_only].present? : false
     @search_attachments = params[:attachments].presence || '0'
+    @open_issues = params[:open_issues] ? params[:open_issues].present? : false
 
     # quick jump to an issue
     if (m = @question.match(/^#?(\d+)$/)) && (issue = Issue.visible.find_by_id(m[1].to_i))
@@ -56,7 +57,7 @@ class SearchController < ApplicationController
 
     fetcher = Redmine::Search::Fetcher.new(
       @question, User.current, @scope, projects_to_search,
-      :all_words => @all_words, :titles_only => @titles_only, :attachments => @search_attachments,
+      :all_words => @all_words, :titles_only => @titles_only, :attachments => @search_attachments, :open_issues => @open_issues,
       :cache => params[:page].present?
     )
 
index e7a444d7d752df2cc2261c7ba15b987445aedf47..0f6312f2cb9647cda671dfcb6f0366219b2d3f83 100644 (file)
@@ -47,7 +47,8 @@ class Issue < ActiveRecord::Base
   acts_as_customizable
   acts_as_watchable
   acts_as_searchable :columns => ['subject', "#{table_name}.description"],
-                     :preload => [:project, :status, :tracker]
+                     :preload => [:project, :status, :tracker],
+                     :scope => lambda {|options| options[:open_issues] ? self.open : self.all}
 
   acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
                 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
index aaf08d3698f5c82877081db004802309dedaeb0a..935abf5a2a5f148354cbd24edacaa407d88aee87 100644 (file)
@@ -20,6 +20,7 @@
 <fieldset class="collapsible collapsed">
   <legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
   <div id="options-content" style="display:none;">
+    <p><label><%= check_box_tag 'open_issues', 1, @open_issues %> <%= l(:label_search_open_issues_only) %></label></p>
     <p>
       <label><%= radio_button_tag 'attachments', '0', @search_attachments == '0' %> <%= l(:label_search_attachments_no) %></label>
       <label><%= radio_button_tag 'attachments', '1', @search_attachments == '1' %> <%= l(:label_search_attachments_yes) %></label>
index c7d13cc0f3679469fb49d93f84456d95dc33e8b8..86d9b50b073da499c6228438ddd62c7a59dc4c8c 100644 (file)
@@ -930,6 +930,7 @@ en:
   label_search_attachments_yes: Search attachment filenames and descriptions
   label_search_attachments_no: Do not search attachments
   label_search_attachments_only: Search attachments only
+  label_search_open_issues_only: Open issues only
 
   button_login: Login
   button_submit: Submit
index 26857d9c842e63e15442f5eb1f37b804b7d28a6e..1c5fbf8896fb86fc0e216d66b8cd887c6c0d4b55 100644 (file)
@@ -950,6 +950,7 @@ fr:
   label_search_attachments_yes: Rechercher les noms et descriptions de fichiers
   label_search_attachments_no: Ne pas rechercher les fichiers
   label_search_attachments_only: Rechercher les fichiers uniquement
+  label_search_open_issues_only: Demandes ouvertes uniquement
 
   button_login: Connexion
   button_submit: Soumettre
index 2ffe79e0af66c017a373248615366e7edd77f0c5..86d954d598623d0da054b61fe3bdbdcf77cbf802 100644 (file)
@@ -89,7 +89,7 @@ module Redmine
 
             unless options[:attachments] == 'only'
               r = fetch_ranks_and_ids(
-                search_scope(user, projects).
+                search_scope(user, projects, options).
                 where(search_tokens_condition(columns, tokens, options[:all_words])),
                 options[:limit]
               )
@@ -109,7 +109,7 @@ module Redmine
                   visibility = clauses.join(' OR ')
   
                   r |= fetch_ranks_and_ids(
-                    search_scope(user, projects).
+                    search_scope(user, projects, options).
                     joins(:custom_values).
                     where(visibility).
                     where(search_tokens_condition(["#{CustomValue.table_name}.value"], tokens, options[:all_words])),
@@ -121,7 +121,7 @@ module Redmine
 
               if !options[:titles_only] && searchable_options[:search_journals]
                 r |= fetch_ranks_and_ids(
-                  search_scope(user, projects).
+                  search_scope(user, projects, options).
                   joins(:journals).
                   where("#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes)})", false).
                   where(search_tokens_condition(["#{Journal.table_name}.notes"], tokens, options[:all_words])),
@@ -133,7 +133,7 @@ module Redmine
 
             if searchable_options[:search_attachments] && (options[:titles_only] ? options[:attachments] == 'only' : options[:attachments] != '0')
               r |= fetch_ranks_and_ids(
-                search_scope(user, projects).
+                search_scope(user, projects, options).
                 joins(:attachments).
                 where(search_tokens_condition(["#{Attachment.table_name}.filename", "#{Attachment.table_name}.description"], tokens, options[:all_words])),
                 options[:limit]
@@ -180,7 +180,7 @@ module Redmine
           private :fetch_ranks_and_ids
 
           # Returns the search scope for user and projects
-          def search_scope(user, projects)
+          def search_scope(user, projects, options={})
             if projects.is_a?(Array) && projects.empty?
               # no results
               return none
@@ -188,7 +188,7 @@ module Redmine
 
             scope = (searchable_options[:scope] || self)
             if scope.is_a? Proc
-              scope = scope.call
+              scope = scope.call(options)
             end
 
             if respond_to?(:visible) && !searchable_options.has_key?(:permission)
index d57cc0757b79161bb625363b42a30198c249aa29..924c049b9c5da779edac932cb29edfbca5f750e1 100644 (file)
@@ -209,6 +209,15 @@ class SearchControllerTest < ActionController::TestCase
     assert_equal 2, results.size
   end
 
+  def test_search_open_issues
+    Issue.generate! :subject => 'search_open'
+    Issue.generate! :subject => 'search_open', :status_id => 5
+
+    get :index, :id => 1, :q => 'search_open', :open_issues => '1'
+    results = assigns(:results)
+    assert_equal 1, results.size
+  end
+
   def test_search_all_words
     # 'all words' is on by default
     get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'