@@ -26,14 +26,12 class AdminController < ApplicationController | |||||
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def projects |
|
28 | def projects | |
29 |
@status = params[:status] |
|
29 | @status = params[:status] || 1 | |
30 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
30 | ||
31 | unless params[:name].blank? |
|
31 | scope = Project.status(@status) | |
32 | name = "%#{params[:name].strip.downcase}%" |
|
32 | scope = scope.like(params[:name]) if params[:name].present? | |
33 | c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name] |
|
33 | ||
34 | end |
|
34 | @projects = scope.all(:order => 'lft') | |
35 | @projects = Project.find :all, :order => 'lft', |
|
|||
36 | :conditions => c.conditions |
|
|||
37 |
|
35 | |||
38 | render :action => "projects", :layout => false if request.xhr? |
|
36 | render :action => "projects", :layout => false if request.xhr? | |
39 | end |
|
37 | end |
@@ -18,6 +18,6 | |||||
18 | module AdminHelper |
|
18 | module AdminHelper | |
19 | def project_status_options_for_select(selected) |
|
19 | def project_status_options_for_select(selected) | |
20 | options_for_select([[l(:label_all), ''], |
|
20 | options_for_select([[l(:label_all), ''], | |
21 | [l(:status_active), 1]], selected) |
|
21 | [l(:status_active), '1']], selected.to_s) | |
22 | end |
|
22 | end | |
23 | end |
|
23 | end |
@@ -83,8 +83,17 class Project < ActiveRecord::Base | |||||
83 |
|
83 | |||
84 | 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] } } |
|
84 | 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] } } | |
85 | named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"} |
|
85 | named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"} | |
|
86 | named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} } | |||
86 | named_scope :all_public, { :conditions => { :is_public => true } } |
|
87 | named_scope :all_public, { :conditions => { :is_public => true } } | |
87 | named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }} |
|
88 | named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }} | |
|
89 | named_scope :like, lambda {|arg| | |||
|
90 | if arg.blank? | |||
|
91 | {} | |||
|
92 | else | |||
|
93 | pattern = "%#{arg.to_s.strip.downcase}%" | |||
|
94 | {:conditions => ["LOWER(identifier) LIKE :p OR LOWER(name) LIKE :p", {:p => pattern}]} | |||
|
95 | end | |||
|
96 | } | |||
88 |
|
97 | |||
89 | def initialize(attributes = nil) |
|
98 | def initialize(attributes = nil) | |
90 | super |
|
99 | super |
@@ -54,6 +54,15 class AdminControllerTest < ActionController::TestCase | |||||
54 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
54 | assert_nil assigns(:projects).detect {|u| !u.active?} | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
|
57 | def test_projects_with_status_filter | |||
|
58 | get :projects, :status => 1 | |||
|
59 | assert_response :success | |||
|
60 | assert_template 'projects' | |||
|
61 | assert_not_nil assigns(:projects) | |||
|
62 | # active projects only | |||
|
63 | assert_nil assigns(:projects).detect {|u| !u.active?} | |||
|
64 | end | |||
|
65 | ||||
57 | def test_projects_with_name_filter |
|
66 | def test_projects_with_name_filter | |
58 | get :projects, :name => 'store', :status => '' |
|
67 | get :projects, :name => 'store', :status => '' | |
59 | assert_response :success |
|
68 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now