@@ -26,14 +26,12 class AdminController < ApplicationController | |||
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def projects |
|
29 |
@status = params[:status] |
|
|
30 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
|
31 | unless params[:name].blank? | |
|
32 | name = "%#{params[:name].strip.downcase}%" | |
|
33 | c << ["LOWER(identifier) LIKE ? OR LOWER(name) LIKE ?", name, name] | |
|
34 | end | |
|
35 | @projects = Project.find :all, :order => 'lft', | |
|
36 | :conditions => c.conditions | |
|
29 | @status = params[:status] || 1 | |
|
30 | ||
|
31 | scope = Project.status(@status) | |
|
32 | scope = scope.like(params[:name]) if params[:name].present? | |
|
33 | ||
|
34 | @projects = scope.all(:order => 'lft') | |
|
37 | 35 | |
|
38 | 36 | render :action => "projects", :layout => false if request.xhr? |
|
39 | 37 | end |
@@ -18,6 +18,6 | |||
|
18 | 18 | module AdminHelper |
|
19 | 19 | def project_status_options_for_select(selected) |
|
20 | 20 | options_for_select([[l(:label_all), ''], |
|
21 | [l(:status_active), 1]], selected) | |
|
21 | [l(:status_active), '1']], selected.to_s) | |
|
22 | 22 | end |
|
23 | 23 | end |
@@ -83,8 +83,17 class Project < ActiveRecord::Base | |||
|
83 | 83 | |
|
84 | 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 | 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 | 87 | named_scope :all_public, { :conditions => { :is_public => true } } |
|
87 | 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 | 98 | def initialize(attributes = nil) |
|
90 | 99 | super |
@@ -54,6 +54,15 class AdminControllerTest < ActionController::TestCase | |||
|
54 | 54 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
55 | 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 | 66 | def test_projects_with_name_filter |
|
58 | 67 | get :projects, :name => 'store', :status => '' |
|
59 | 68 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now