##// END OF EJS Templates
bug in search_filter...
Jean-Philippe Lang -
r6:a573da3b985d
parent child
Show More
@@ -1,90 +1,91
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module SearchFilterHelper
18 module SearchFilterHelper
19
19
20 def search_filter_criteria(name, options = {})
20 def search_filter_criteria(name, options = {})
21 @search_filter ||= {}
21 @search_filter ||= {}
22 @search_filter[name] ||= {}
22 @search_filter[name] ||= {}
23 @search_filter[name][:options] = []
23 @search_filter[name][:options] = []
24 @search_filter[name][:conditions] = {}
24 @search_filter[name][:conditions] = {}
25 yield.each { |c|
25 yield.each { |c|
26 @search_filter[name][:options] << [c[0], c[1].to_s]
26 @search_filter[name][:options] << [c[0], c[1].to_s]
27 @search_filter[name][:conditions].store(c[1].to_s, c[2])
27 @search_filter[name][:conditions].store(c[1].to_s, c[2])
28 }
28 }
29 end
29 end
30
30
31 def search_filter_update
31 def search_filter_update
32 @search_filter.each_key {|field| session[:search_filter][field] = params[field] }
32 @search_filter.each_key {|field| session[:search_filter][field] = params[field] }
33 end
33 end
34
34
35 def search_filter_clause
35 def search_filter_clause
36 session[:search_filter] ||= {}
36 clause = ["1=1"]
37 clause = ["1=1"]
37 @search_filter.each { |k, v|
38 @search_filter.each { |k, v|
38 filter_value = session[:search_filter][k] || v[:options][0][1]
39 filter_value = session[:search_filter][k] || v[:options][0][1]
39 if v[:conditions][filter_value]
40 if v[:conditions][filter_value]
40 clause[0] = clause[0] + " AND " + v[:conditions][filter_value].first
41 clause[0] = clause[0] + " AND " + v[:conditions][filter_value].first
41 clause += v[:conditions][filter_value][1..-1]
42 clause += v[:conditions][filter_value][1..-1]
42 end
43 end
43 }
44 }
44 clause
45 clause
45 end
46 end
46
47
47 def search_filter_tag(criteria, options = {})
48 def search_filter_tag(criteria, options = {})
48 options[:name] = criteria
49 options[:name] = criteria
49 content_tag("select",
50 content_tag("select",
50 options_for_select(@search_filter[criteria][:options], session[:search_filter][criteria]),
51 options_for_select(@search_filter[criteria][:options], session[:search_filter][criteria]),
51 options
52 options
52 )
53 )
53 end
54 end
54
55
55 def search_filter_init_list_issues
56 def search_filter_init_list_issues
56 search_filter_criteria('status_id') {
57 search_filter_criteria('status_id') {
57 [ [_('[Open]'), "O", ["issue_statuses.is_closed=?", false]],
58 [ [_('[Open]'), "O", ["issue_statuses.is_closed=?", false]],
58 [_('[All]'), "A", nil]
59 [_('[All]'), "A", nil]
59 ] + IssueStatus.find(:all).collect {|s| [s.name, s.id, ["issues.status_id=?", s.id]] }
60 ] + IssueStatus.find(:all).collect {|s| [s.name, s.id, ["issues.status_id=?", s.id]] }
60 }
61 }
61
62
62 search_filter_criteria('tracker_id') {
63 search_filter_criteria('tracker_id') {
63 [ [_('[All]'), "A", nil]
64 [ [_('[All]'), "A", nil]
64 ] + Tracker.find(:all).collect {|s| [s.name, s.id, ["issues.tracker_id=?", s.id]] }
65 ] + Tracker.find(:all).collect {|s| [s.name, s.id, ["issues.tracker_id=?", s.id]] }
65 }
66 }
66
67
67 search_filter_criteria('priority_id') {
68 search_filter_criteria('priority_id') {
68 [ [_('[All]'), "A", nil]
69 [ [_('[All]'), "A", nil]
69 ] + Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect {|s| [s.name, s.id, ["issues.priority_id=?", s.id]] }
70 ] + Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect {|s| [s.name, s.id, ["issues.priority_id=?", s.id]] }
70 }
71 }
71
72
72 search_filter_criteria('category_id') {
73 search_filter_criteria('category_id') {
73 [ [_('[All]'), "A", nil],
74 [ [_('[All]'), "A", nil],
74 [_('[None]'), "N", ["issues.category_id is null"]]
75 [_('[None]'), "N", ["issues.category_id is null"]]
75 ] + @project.issue_categories.find(:all).collect {|s| [s.name, s.id, ["issues.category_id=?", s.id]] }
76 ] + @project.issue_categories.find(:all).collect {|s| [s.name, s.id, ["issues.category_id=?", s.id]] }
76 }
77 }
77
78
78 search_filter_criteria('assigned_to_id') {
79 search_filter_criteria('assigned_to_id') {
79 [ [_('[All]'), "A", nil],
80 [ [_('[All]'), "A", nil],
80 [_('[None]'), "N", ["issues.assigned_to_id is null"]]
81 [_('[None]'), "N", ["issues.assigned_to_id is null"]]
81 ] + @project.users.collect {|s| [s.display_name, s.id, ["issues.assigned_to_id=?", s.id]] }
82 ] + @project.users.collect {|s| [s.display_name, s.id, ["issues.assigned_to_id=?", s.id]] }
82 }
83 }
83
84
84 search_filter_criteria('subproject_id') {
85 search_filter_criteria('subproject_id') {
85 [ [_('[None]'), "N", ["issues.project_id=?", @project.id]],
86 [ [_('[None]'), "N", ["issues.project_id=?", @project.id]],
86 [_('[All]'), "A", ["(issues.project_id=? or projects.parent_id=?)", @project.id, @project.id]]
87 [_('[All]'), "A", ["(issues.project_id=? or projects.parent_id=?)", @project.id, @project.id]]
87 ]
88 ]
88 }
89 }
89 end
90 end
90 end No newline at end of file
91 end
General Comments 0
You need to be logged in to leave comments. Login now