@@ -1,100 +1,100 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 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 QueriesHelper |
|
18 | module QueriesHelper | |
19 |
|
19 | |||
20 | def operators_for_select(filter_type) |
|
20 | def operators_for_select(filter_type) | |
21 | Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]} |
|
21 | Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]} | |
22 | end |
|
22 | end | |
23 |
|
23 | |||
24 | def column_header(column) |
|
24 | def column_header(column) | |
25 | column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, |
|
25 | column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, | |
26 |
:default_order => column.default_order) : |
|
26 | :default_order => column.default_order) : | |
27 | content_tag('th', h(column.caption)) |
|
27 | content_tag('th', h(column.caption)) | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def column_content(column, issue) |
|
30 | def column_content(column, issue) | |
31 | value = column.value(issue) |
|
31 | value = column.value(issue) | |
32 |
|
32 | |||
33 | case value.class.name |
|
33 | case value.class.name | |
34 | when 'String' |
|
34 | when 'String' | |
35 | if column.name == :subject |
|
35 | if column.name == :subject | |
36 | link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) |
|
36 | link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) | |
37 | else |
|
37 | else | |
38 | h(value) |
|
38 | h(value) | |
39 | end |
|
39 | end | |
40 | when 'Time' |
|
40 | when 'Time' | |
41 | format_time(value) |
|
41 | format_time(value) | |
42 | when 'Date' |
|
42 | when 'Date' | |
43 | format_date(value) |
|
43 | format_date(value) | |
44 | when 'Fixnum', 'Float' |
|
44 | when 'Fixnum', 'Float' | |
45 | if column.name == :done_ratio |
|
45 | if column.name == :done_ratio | |
46 | progress_bar(value, :width => '80px') |
|
46 | progress_bar(value, :width => '80px') | |
47 | else |
|
47 | else | |
48 | h(value.to_s) |
|
48 | h(value.to_s) | |
49 | end |
|
49 | end | |
50 | when 'User' |
|
50 | when 'User' | |
51 | link_to_user value |
|
51 | link_to_user value | |
52 | when 'Project' |
|
52 | when 'Project' | |
53 | link_to_project value |
|
53 | link_to_project value | |
54 | when 'Version' |
|
54 | when 'Version' | |
55 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) |
|
55 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) | |
56 | when 'TrueClass' |
|
56 | when 'TrueClass' | |
57 | l(:general_text_Yes) |
|
57 | l(:general_text_Yes) | |
58 | when 'FalseClass' |
|
58 | when 'FalseClass' | |
59 | l(:general_text_No) |
|
59 | l(:general_text_No) | |
60 | when 'Issue' |
|
60 | when 'Issue' | |
61 | link_to_issue(value, :subject => false) |
|
61 | link_to_issue(value, :subject => false) | |
62 | else |
|
62 | else | |
63 | h(value) |
|
63 | h(value) | |
64 | end |
|
64 | end | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | # Retrieve query from session or build a new query |
|
67 | # Retrieve query from session or build a new query | |
68 | def retrieve_query |
|
68 | def retrieve_query | |
69 | if !params[:query_id].blank? |
|
69 | if !params[:query_id].blank? | |
70 | cond = "project_id IS NULL" |
|
70 | cond = "project_id IS NULL" | |
71 | cond << " OR project_id = #{@project.id}" if @project |
|
71 | cond << " OR project_id = #{@project.id}" if @project | |
72 | @query = Query.find(params[:query_id], :conditions => cond) |
|
72 | @query = Query.find(params[:query_id], :conditions => cond) | |
73 | raise ::Unauthorized unless @query.visible? |
|
73 | raise ::Unauthorized unless @query.visible? | |
74 | @query.project = @project |
|
74 | @query.project = @project | |
75 | session[:query] = {:id => @query.id, :project_id => @query.project_id} |
|
75 | session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
76 | sort_clear |
|
76 | sort_clear | |
77 | else |
|
77 | else | |
78 | if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) |
|
78 | if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
79 | # Give it a name, required to be valid |
|
79 | # Give it a name, required to be valid | |
80 | @query = Query.new(:name => "_") |
|
80 | @query = Query.new(:name => "_") | |
81 | @query.project = @project |
|
81 | @query.project = @project | |
82 | if params[:fields] || params[:f] |
|
82 | if params[:fields] || params[:f] | |
83 | @query.filters = {} |
|
83 | @query.filters = {} | |
84 | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) |
|
84 | @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) | |
85 | else |
|
85 | else | |
86 | @query.available_filters.keys.each do |field| |
|
86 | @query.available_filters.keys.each do |field| | |
87 | @query.add_short_filter(field, params[field]) if params[field] |
|
87 | @query.add_short_filter(field, params[field]) if params[field] | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 | @query.group_by = params[:group_by] |
|
90 | @query.group_by = params[:group_by] | |
91 | @query.column_names = params[:c] || (params[:query] && params[:query][:column_names]) |
|
91 | @query.column_names = params[:c] || (params[:query] && params[:query][:column_names]) | |
92 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} |
|
92 | session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} | |
93 | else |
|
93 | else | |
94 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] |
|
94 | @query = Query.find_by_id(session[:query][:id]) if session[:query][:id] | |
95 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) |
|
95 | @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) | |
96 | @query.project = @project |
|
96 | @query.project = @project | |
97 | end |
|
97 | end | |
98 | end |
|
98 | end | |
99 | end |
|
99 | end | |
100 | end |
|
100 | end |
General Comments 0
You need to be logged in to leave comments.
Login now