##// END OF EJS Templates
Merged r13556 (#13673)....
Jean-Philippe Lang -
r13246:fa4b6f294b16
parent child
Show More

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

@@ -1,200 +1,202
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 when :parent
101 value ? (value.visible? ? link_to_issue(value, :subject => false) : "##{value.id}") : ''
100 102 when :description
101 103 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
102 104 when :done_ratio
103 105 progress_bar(value, :width => '80px')
104 106 when :relations
105 107 other = value.other_issue(issue)
106 108 content_tag('span',
107 109 (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
108 110 :class => value.css_classes_for(issue))
109 111 else
110 112 format_object(value)
111 113 end
112 114 end
113 115
114 116 def csv_content(column, issue)
115 117 value = column.value_object(issue)
116 118 if value.is_a?(Array)
117 119 value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
118 120 else
119 121 csv_value(column, issue, value)
120 122 end
121 123 end
122 124
123 125 def csv_value(column, issue, value)
124 126 format_object(value, false) do |value|
125 127 case value.class.name
126 128 when 'Float'
127 129 sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
128 130 when 'IssueRelation'
129 131 other = value.other_issue(issue)
130 132 l(value.label_for(issue)) + " ##{other.id}"
131 133 when 'Issue'
132 134 value.id
133 135 else
134 136 value
135 137 end
136 138 end
137 139 end
138 140
139 141 def query_to_csv(items, query, options={})
140 142 encoding = l(:general_csv_encoding)
141 143 columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
142 144 query.available_block_columns.each do |column|
143 145 if options[column.name].present?
144 146 columns << column
145 147 end
146 148 end
147 149
148 150 export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
149 151 # csv header fields
150 152 csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
151 153 # csv lines
152 154 items.each do |item|
153 155 csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, item), encoding) }
154 156 end
155 157 end
156 158 export
157 159 end
158 160
159 161 # Retrieve query from session or build a new query
160 162 def retrieve_query
161 163 if !params[:query_id].blank?
162 164 cond = "project_id IS NULL"
163 165 cond << " OR project_id = #{@project.id}" if @project
164 166 @query = IssueQuery.where(cond).find(params[:query_id])
165 167 raise ::Unauthorized unless @query.visible?
166 168 @query.project = @project
167 169 session[:query] = {:id => @query.id, :project_id => @query.project_id}
168 170 sort_clear
169 171 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
170 172 # Give it a name, required to be valid
171 173 @query = IssueQuery.new(:name => "_")
172 174 @query.project = @project
173 175 @query.build_from_params(params)
174 176 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
175 177 else
176 178 # retrieve from session
177 179 @query = nil
178 180 @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
179 181 @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
180 182 @query.project = @project
181 183 end
182 184 end
183 185
184 186 def retrieve_query_from_session
185 187 if session[:query]
186 188 if session[:query][:id]
187 189 @query = IssueQuery.find_by_id(session[:query][:id])
188 190 return unless @query
189 191 else
190 192 @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
191 193 end
192 194 if session[:query].has_key?(:project_id)
193 195 @query.project_id = session[:query][:project_id]
194 196 else
195 197 @query.project = @project
196 198 end
197 199 @query
198 200 end
199 201 end
200 202 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