Mercurial > hg > soundsoftware-site
comparison app/helpers/.svn/text-base/queries_helper.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 1d32c0a0efbf |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 module QueriesHelper | |
19 | |
20 def operators_for_select(filter_type) | |
21 Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]} | |
22 end | |
23 | |
24 def column_header(column) | |
25 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, | |
26 :default_order => column.default_order) : | |
27 content_tag('th', column.caption) | |
28 end | |
29 | |
30 def column_content(column, issue) | |
31 value = column.value(issue) | |
32 | |
33 case value.class.name | |
34 when 'String' | |
35 if column.name == :subject | |
36 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) | |
37 else | |
38 h(value) | |
39 end | |
40 when 'Time' | |
41 format_time(value) | |
42 when 'Date' | |
43 format_date(value) | |
44 when 'Fixnum', 'Float' | |
45 if column.name == :done_ratio | |
46 progress_bar(value, :width => '80px') | |
47 else | |
48 value.to_s | |
49 end | |
50 when 'User' | |
51 link_to_user value | |
52 when 'Project' | |
53 link_to(h(value), :controller => 'projects', :action => 'show', :id => value) | |
54 when 'Version' | |
55 link_to(h(value), :controller => 'versions', :action => 'show', :id => value) | |
56 when 'TrueClass' | |
57 l(:general_text_Yes) | |
58 when 'FalseClass' | |
59 l(:general_text_No) | |
60 when 'Issue' | |
61 link_to_issue(value, :subject => false) | |
62 else | |
63 h(value) | |
64 end | |
65 end | |
66 | |
67 # Retrieve query from session or build a new query | |
68 def retrieve_query | |
69 if !params[:query_id].blank? | |
70 cond = "project_id IS NULL" | |
71 cond << " OR project_id = #{@project.id}" if @project | |
72 @query = Query.find(params[:query_id], :conditions => cond) | |
73 @query.project = @project | |
74 session[:query] = {:id => @query.id, :project_id => @query.project_id} | |
75 sort_clear | |
76 else | |
77 if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil) | |
78 # Give it a name, required to be valid | |
79 @query = Query.new(:name => "_") | |
80 @query.project = @project | |
81 if params[:fields] and params[:fields].is_a? Array | |
82 params[:fields].each do |field| | |
83 @query.add_filter(field, params[:operators][field], params[:values][field]) | |
84 end | |
85 else | |
86 @query.available_filters.keys.each do |field| | |
87 @query.add_short_filter(field, params[field]) if params[field] | |
88 end | |
89 end | |
90 @query.group_by = params[:group_by] | |
91 @query.column_names = 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} | |
93 else | |
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]) | |
96 @query.project = @project | |
97 end | |
98 end | |
99 end | |
100 end |