##// END OF EJS Templates
Fixed CSV content for parent issue column (#13608)....
Jean-Philippe Lang -
r13173:db63f5a925f4
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,198 +1,200
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module QueriesHelper
21 21 include ApplicationHelper
22 22
23 23 def filters_options_for_select(query)
24 24 options_for_select(filters_options(query))
25 25 end
26 26
27 27 def filters_options(query)
28 28 options = [[]]
29 29 options += query.available_filters.map do |field, field_options|
30 30 [field_options[:name], field]
31 31 end
32 32 end
33 33
34 34 def query_filters_hidden_tags(query)
35 35 tags = ''.html_safe
36 36 query.filters.each do |field, options|
37 37 tags << hidden_field_tag("f[]", field, :id => nil)
38 38 tags << hidden_field_tag("op[#{field}]", options[:operator], :id => nil)
39 39 options[:values].each do |value|
40 40 tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
41 41 end
42 42 end
43 43 tags
44 44 end
45 45
46 46 def query_columns_hidden_tags(query)
47 47 tags = ''.html_safe
48 48 query.columns.each do |column|
49 49 tags << hidden_field_tag("c[]", column.name, :id => nil)
50 50 end
51 51 tags
52 52 end
53 53
54 54 def query_hidden_tags(query)
55 55 query_filters_hidden_tags(query) + query_columns_hidden_tags(query)
56 56 end
57 57
58 58 def available_block_columns_tags(query)
59 59 tags = ''.html_safe
60 60 query.available_block_columns.each do |column|
61 61 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column), :id => nil) + " #{column.caption}", :class => 'inline')
62 62 end
63 63 tags
64 64 end
65 65
66 66 def query_available_inline_columns_options(query)
67 67 (query.available_inline_columns - query.columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
68 68 end
69 69
70 70 def query_selected_inline_columns_options(query)
71 71 (query.inline_columns & query.available_inline_columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
72 72 end
73 73
74 74 def render_query_columns_selection(query, options={})
75 75 tag_name = (options[:name] || 'c') + '[]'
76 76 render :partial => 'queries/columns', :locals => {:query => query, :tag_name => tag_name}
77 77 end
78 78
79 79 def column_header(column)
80 80 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
81 81 :default_order => column.default_order) :
82 82 content_tag('th', h(column.caption))
83 83 end
84 84
85 85 def column_content(column, issue)
86 86 value = column.value_object(issue)
87 87 if value.is_a?(Array)
88 88 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
89 89 else
90 90 column_value(column, issue, value)
91 91 end
92 92 end
93 93
94 94 def column_value(column, issue, value)
95 95 case column.name
96 96 when :id
97 97 link_to value, issue_path(issue)
98 98 when :subject
99 99 link_to value, issue_path(issue)
100 100 when :description
101 101 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
102 102 when :done_ratio
103 103 progress_bar(value, :width => '80px')
104 104 when :relations
105 105 other = value.other_issue(issue)
106 106 content_tag('span',
107 107 (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
108 108 :class => value.css_classes_for(issue))
109 109 else
110 110 format_object(value)
111 111 end
112 112 end
113 113
114 114 def csv_content(column, issue)
115 115 value = column.value_object(issue)
116 116 if value.is_a?(Array)
117 117 value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
118 118 else
119 119 csv_value(column, issue, value)
120 120 end
121 121 end
122 122
123 123 def csv_value(column, issue, value)
124 124 format_object(value, false) do |value|
125 125 case value.class.name
126 126 when 'Float'
127 127 sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
128 128 when 'IssueRelation'
129 129 other = value.other_issue(issue)
130 130 l(value.label_for(issue)) + " ##{other.id}"
131 when 'Issue'
132 value.id
131 133 else
132 134 value
133 135 end
134 136 end
135 137 end
136 138
137 139 def query_to_csv(items, query, options={})
138 140 encoding = l(:general_csv_encoding)
139 141 columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
140 142 query.available_block_columns.each do |column|
141 143 if options[column.name].present?
142 144 columns << column
143 145 end
144 146 end
145 147
146 148 export = CSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
147 149 # csv header fields
148 150 csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
149 151 # csv lines
150 152 items.each do |item|
151 153 csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, item), encoding) }
152 154 end
153 155 end
154 156 export
155 157 end
156 158
157 159 # Retrieve query from session or build a new query
158 160 def retrieve_query
159 161 if !params[:query_id].blank?
160 162 cond = "project_id IS NULL"
161 163 cond << " OR project_id = #{@project.id}" if @project
162 164 @query = IssueQuery.where(cond).find(params[:query_id])
163 165 raise ::Unauthorized unless @query.visible?
164 166 @query.project = @project
165 167 session[:query] = {:id => @query.id, :project_id => @query.project_id}
166 168 sort_clear
167 169 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
168 170 # Give it a name, required to be valid
169 171 @query = IssueQuery.new(:name => "_")
170 172 @query.project = @project
171 173 @query.build_from_params(params)
172 174 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
173 175 else
174 176 # retrieve from session
175 177 @query = nil
176 178 @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
177 179 @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
178 180 @query.project = @project
179 181 end
180 182 end
181 183
182 184 def retrieve_query_from_session
183 185 if session[:query]
184 186 if session[:query][:id]
185 187 @query = IssueQuery.find_by_id(session[:query][:id])
186 188 return unless @query
187 189 else
188 190 @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
189 191 end
190 192 if session[:query].has_key?(:project_id)
191 193 @query.project_id = session[:query][:project_id]
192 194 else
193 195 @query.project = @project
194 196 end
195 197 @query
196 198 end
197 199 end
198 200 end
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now