Adds named scopes for projects index.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8082 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f52410be19
commit
ff0f141126
|
@ -26,14 +26,12 @@ class AdminController < ApplicationController
|
|||
end
|
||||
|
||||
def projects
|
||||
@status = params[:status] ? params[:status].to_i : 1
|
||||
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||
unless params[:name].blank?
|
||||
name = "%#{params[:name].strip.downcase}%"
|
||||
c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name]
|
||||
end
|
||||
@projects = Project.find :all, :order => 'lft',
|
||||
:conditions => c.conditions
|
||||
@status = params[:status] || 1
|
||||
|
||||
scope = Project.status(@status)
|
||||
scope = scope.like(params[:name]) if params[:name].present?
|
||||
|
||||
@projects = scope.all(:order => 'lft')
|
||||
|
||||
render :action => "projects", :layout => false if request.xhr?
|
||||
end
|
||||
|
|
|
@ -18,6 +18,6 @@
|
|||
module AdminHelper
|
||||
def project_status_options_for_select(selected)
|
||||
options_for_select([[l(:label_all), ''],
|
||||
[l(:status_active), 1]], selected)
|
||||
[l(:status_active), '1']], selected.to_s)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -83,8 +83,17 @@ class Project < ActiveRecord::Base
|
|||
|
||||
named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
|
||||
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
||||
named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
|
||||
named_scope :all_public, { :conditions => { :is_public => true } }
|
||||
named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
|
||||
named_scope :like, lambda {|arg|
|
||||
if arg.blank?
|
||||
{}
|
||||
else
|
||||
pattern = "%#{arg.to_s.strip.downcase}%"
|
||||
{:conditions => ["LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p", {:p => pattern}]}
|
||||
end
|
||||
}
|
||||
|
||||
def initialize(attributes = nil)
|
||||
super
|
||||
|
|
|
@ -54,6 +54,15 @@ class AdminControllerTest < ActionController::TestCase
|
|||
assert_nil assigns(:projects).detect {|u| !u.active?}
|
||||
end
|
||||
|
||||
def test_projects_with_status_filter
|
||||
get :projects, :status => 1
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue