]> source.dussan.org Git - redmine.git/commitdiff
Adds the ability to search for a project name or identifier on the administration...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 24 Oct 2008 17:12:39 +0000 (17:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 24 Oct 2008 17:12:39 +0000 (17:12 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@1947 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/admin_controller.rb
app/helpers/admin_helper.rb
app/views/admin/projects.rhtml
test/functional/admin_controller_test.rb

index a6df49dcdaf79200cc838647dfb345982e7d1e61..777c31d70e81d225e44cc9cbf1c73dd9e41b63fd 100644 (file)
@@ -29,16 +29,20 @@ class AdminController < ApplicationController
     sort_init 'name', 'asc'
     sort_update
     
-    @status = params[:status] ? params[:status].to_i : 0
-    conditions = nil
-    conditions = ["status=?", @status] unless @status == 0
+    @status = params[:status] ? params[:status].to_i : 1
+    c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
     
-    @project_count = Project.count(:conditions => conditions)
+    unless params[:name].blank?
+      name = "%#{params[:name].strip.downcase}%"
+      c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
+    end
+    
+    @project_count = Project.count(:conditions => c.conditions)
     @project_pages = Paginator.new self, @project_count,
                                                                per_page_option,
                                                                params['page']                                                          
     @projects = Project.find :all, :order => sort_clause,
-                        :conditions => conditions,
+                        :conditions => c.conditions,
                                                :limit  =>  @project_pages.items_per_page,
                                                :offset =>  @project_pages.current.offset
 
index 1b41d8374de719c87fee98223602fe9096ab4da5..8f81f66ba79309baba1ed9d940ea65a4975355ce 100644 (file)
@@ -17,7 +17,7 @@
 
 module AdminHelper
   def project_status_options_for_select(selected)
-    options_for_select([[l(:label_all), "*"], 
+    options_for_select([[l(:label_all), ''], 
                         [l(:status_active), 1]], selected)
   end
 end
index c428456226c2338cf015d816fe9a39cc17b2ecdb..6c7a21fb5678941d60c8ad38685028030691adf0 100644 (file)
@@ -4,11 +4,13 @@
 
 <h2><%=l(:label_project_plural)%></h2>
 
-<% form_tag() do %>
+<% form_tag({}, :method => :get) do %>
 <fieldset><legend><%= l(:label_filter_plural) %></legend>
 <label><%= l(:field_status) %> :</label>
 <%= select_tag 'status', project_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;"  %>
-<%= submit_tag l(:button_apply), :class => "small" %>
+<label><%= l(:label_project) %>:</label>
+<%= text_field_tag 'name', params[:name], :size => 30 %>
+<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
 </fieldset>
 <% end %>
 &nbsp;
index 05205b39935071048a225f854606c0c825c95369..7c26260828bb4bc7cbda2e840b3088e5e1cbb2b5 100644 (file)
@@ -45,6 +45,25 @@ class AdminControllerTest < Test::Unit::TestCase
                :attributes => { :class => /nodata/ }
   end
   
+  def test_projects
+    get :projects
+    assert_response :success
+    assert_template 'projects'
+    assert_not_nil assigns(:projects)
+    # active projects only
+    assert_nil assigns(:projects).detect {|u| !u.active?}
+  end
+  
+  def test_projects_with_name_filter
+    get :projects, :name => 'store', :status => ''
+    assert_response :success
+    assert_template 'projects'
+    projects = assigns(:projects)
+    assert_not_nil projects
+    assert_equal 1, projects.size
+    assert_equal 'OnlineStore', projects.first.name
+  end
+  
   def test_load_default_configuration_data
     delete_configuration_data
     post :default_configuration, :lang => 'fr'