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