comparison app/helpers/queries_helper.rb @ 1339:c03a6c3c4db9 luisf

Merge
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 20 Jun 2013 14:34:42 +0100
parents 3e4c3460b6ca
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
1079:413d1d9c3efa 1339:c03a6c3c4db9
1 # encoding: utf-8 1 # encoding: utf-8
2 # 2 #
3 # Redmine - project management software 3 # Redmine - project management software
4 # Copyright (C) 2006-2011 Jean-Philippe Lang 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
5 # 5 #
6 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2 8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version. 9 # of the License, or (at your option) any later version.
16 # You should have received a copy of the GNU General Public License 16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software 17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 module QueriesHelper 20 module QueriesHelper
21 def filters_options_for_select(query)
22 options_for_select(filters_options(query))
23 end
21 24
22 def operators_for_select(filter_type) 25 def filters_options(query)
23 Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]} 26 options = [[]]
27 sorted_options = query.available_filters.sort do |a, b|
28 ord = 0
29 if !(a[1][:order] == 20 && b[1][:order] == 20)
30 ord = a[1][:order] <=> b[1][:order]
31 else
32 cn = (CustomField::CUSTOM_FIELDS_NAMES.index(a[1][:field].class.name) <=>
33 CustomField::CUSTOM_FIELDS_NAMES.index(b[1][:field].class.name))
34 if cn != 0
35 ord = cn
36 else
37 f = (a[1][:field] <=> b[1][:field])
38 if f != 0
39 ord = f
40 else
41 # assigned_to or author
42 ord = (a[0] <=> b[0])
43 end
44 end
45 end
46 ord
47 end
48 options += sorted_options.map do |field, field_options|
49 [field_options[:name], field]
50 end
51 end
52
53 def available_block_columns_tags(query)
54 tags = ''.html_safe
55 query.available_block_columns.each do |column|
56 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
57 end
58 tags
24 end 59 end
25 60
26 def column_header(column) 61 def column_header(column)
27 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption, 62 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
28 :default_order => column.default_order) : 63 :default_order => column.default_order) :
29 content_tag('th', h(column.caption)) 64 content_tag('th', h(column.caption))
30 end 65 end
31 66
32 def column_content(column, issue) 67 def column_content(column, issue)
33 value = column.value(issue) 68 value = column.value(issue)
34 69 if value.is_a?(Array)
70 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
71 else
72 column_value(column, issue, value)
73 end
74 end
75
76 def column_value(column, issue, value)
35 case value.class.name 77 case value.class.name
36 when 'String' 78 when 'String'
37 if column.name == :subject 79 if column.name == :subject
38 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue) 80 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
81 elsif column.name == :description
82 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
39 else 83 else
40 h(value) 84 h(value)
41 end 85 end
42 when 'Time' 86 when 'Time'
43 format_time(value) 87 format_time(value)
44 when 'Date' 88 when 'Date'
45 format_date(value) 89 format_date(value)
46 when 'Fixnum', 'Float' 90 when 'Fixnum'
47 if column.name == :done_ratio 91 if column.name == :done_ratio
48 progress_bar(value, :width => '80px') 92 progress_bar(value, :width => '80px')
49 else 93 else
50 h(value.to_s) 94 value.to_s
51 end 95 end
96 when 'Float'
97 sprintf "%.2f", value
52 when 'User' 98 when 'User'
53 link_to_user value 99 link_to_user value
54 when 'Project' 100 when 'Project'
55 link_to_project value 101 link_to_project value
56 when 'Version' 102 when 'Version'
59 l(:general_text_Yes) 105 l(:general_text_Yes)
60 when 'FalseClass' 106 when 'FalseClass'
61 l(:general_text_No) 107 l(:general_text_No)
62 when 'Issue' 108 when 'Issue'
63 link_to_issue(value, :subject => false) 109 link_to_issue(value, :subject => false)
110 when 'IssueRelation'
111 other = value.other_issue(issue)
112 content_tag('span',
113 (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
114 :class => value.css_classes_for(issue))
64 else 115 else
65 h(value) 116 h(value)
66 end 117 end
67 end 118 end
68 119
88 @query ||= Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names]) 139 @query ||= Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
89 @query.project = @project 140 @query.project = @project
90 end 141 end
91 end 142 end
92 143
144 def retrieve_query_from_session
145 if session[:query]
146 if session[:query][:id]
147 @query = Query.find_by_id(session[:query][:id])
148 return unless @query
149 else
150 @query = Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
151 end
152 if session[:query].has_key?(:project_id)
153 @query.project_id = session[:query][:project_id]
154 else
155 @query.project = @project
156 end
157 @query
158 end
159 end
160
93 def build_query_from_params 161 def build_query_from_params
94 if params[:fields] || params[:f] 162 if params[:fields] || params[:f]
95 @query.filters = {} 163 @query.filters = {}
96 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v]) 164 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
97 else 165 else