##// END OF EJS Templates
Merged r15202 (#22108)....
Jean-Philippe Lang -
r14844:d09b08046343
parent child
Show More

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

@@ -1,246 +1,276
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2015 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 ungrouped = []
25 25 grouped = {}
26 26 query.available_filters.map do |field, field_options|
27 27 if [:tree, :relation].include?(field_options[:type])
28 28 group = :label_related_issues
29 29 elsif field =~ /^(.+)\./
30 30 # association filters
31 31 group = "field_#{$1}"
32 32 elsif %w(member_of_group assigned_to_role).include?(field)
33 33 group = :field_assigned_to
34 34 elsif field_options[:type] == :date_past || field_options[:type] == :date
35 35 group = :label_date
36 36 end
37 37 if group
38 38 (grouped[group] ||= []) << [field_options[:name], field]
39 39 else
40 40 ungrouped << [field_options[:name], field]
41 41 end
42 42 end
43 43 # Don't group dates if there's only one (eg. time entries filters)
44 44 if grouped[:label_date].try(:size) == 1
45 45 ungrouped << grouped.delete(:label_date).first
46 46 end
47 47 s = options_for_select([[]] + ungrouped)
48 48 if grouped.present?
49 49 localized_grouped = grouped.map {|k,v| [l(k), v]}
50 50 s << grouped_options_for_select(localized_grouped)
51 51 end
52 52 s
53 53 end
54 54
55 55 def query_filters_hidden_tags(query)
56 56 tags = ''.html_safe
57 57 query.filters.each do |field, options|
58 58 tags << hidden_field_tag("f[]", field, :id => nil)
59 59 tags << hidden_field_tag("op[#{field}]", options[:operator], :id => nil)
60 60 options[:values].each do |value|
61 61 tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
62 62 end
63 63 end
64 64 tags
65 65 end
66 66
67 67 def query_columns_hidden_tags(query)
68 68 tags = ''.html_safe
69 69 query.columns.each do |column|
70 70 tags << hidden_field_tag("c[]", column.name, :id => nil)
71 71 end
72 72 tags
73 73 end
74 74
75 75 def query_hidden_tags(query)
76 76 query_filters_hidden_tags(query) + query_columns_hidden_tags(query)
77 77 end
78 78
79 79 def available_block_columns_tags(query)
80 80 tags = ''.html_safe
81 81 query.available_block_columns.each do |column|
82 82 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column), :id => nil) + " #{column.caption}", :class => 'inline')
83 83 end
84 84 tags
85 85 end
86 86
87 87 def available_totalable_columns_tags(query)
88 88 tags = ''.html_safe
89 89 query.available_totalable_columns.each do |column|
90 90 tags << content_tag('label', check_box_tag('t[]', column.name.to_s, query.totalable_columns.include?(column), :id => nil) + " #{column.caption}", :class => 'inline')
91 91 end
92 92 tags
93 93 end
94 94
95 95 def query_available_inline_columns_options(query)
96 96 (query.available_inline_columns - query.columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
97 97 end
98 98
99 99 def query_selected_inline_columns_options(query)
100 100 (query.inline_columns & query.available_inline_columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
101 101 end
102 102
103 103 def render_query_columns_selection(query, options={})
104 104 tag_name = (options[:name] || 'c') + '[]'
105 105 render :partial => 'queries/columns', :locals => {:query => query, :tag_name => tag_name}
106 106 end
107 107
108 108 def render_query_totals(query)
109 109 return unless query.totalable_columns.present?
110 110 totals = query.totalable_columns.map do |column|
111 111 total_tag(column, query.total_for(column))
112 112 end
113 113 content_tag('p', totals.join(" ").html_safe, :class => "query-totals")
114 114 end
115 115
116 116 def total_tag(column, value)
117 117 label = content_tag('span', "#{column.caption}:")
118 118 value = content_tag('span', format_object(value), :class => 'value')
119 119 content_tag('span', label + " " + value, :class => "total-for-#{column.name.to_s.dasherize}")
120 120 end
121 121
122 122 def column_header(column)
123 123 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
124 124 :default_order => column.default_order) :
125 125 content_tag('th', h(column.caption))
126 126 end
127 127
128 128 def column_content(column, issue)
129 129 value = column.value_object(issue)
130 130 if value.is_a?(Array)
131 131 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
132 132 else
133 133 column_value(column, issue, value)
134 134 end
135 135 end
136 136
137 137 def column_value(column, issue, value)
138 138 case column.name
139 139 when :id
140 140 link_to value, issue_path(issue)
141 141 when :subject
142 142 link_to value, issue_path(issue)
143 143 when :parent
144 144 value ? (value.visible? ? link_to_issue(value, :subject => false) : "##{value.id}") : ''
145 145 when :description
146 146 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
147 147 when :done_ratio
148 148 progress_bar(value)
149 149 when :relations
150 150 content_tag('span',
151 151 value.to_s(issue) {|other| link_to_issue(other, :subject => false, :tracker => false)}.html_safe,
152 152 :class => value.css_classes_for(issue))
153 153 else
154 154 format_object(value)
155 155 end
156 156 end
157 157
158 158 def csv_content(column, issue)
159 159 value = column.value_object(issue)
160 160 if value.is_a?(Array)
161 161 value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
162 162 else
163 163 csv_value(column, issue, value)
164 164 end
165 165 end
166 166
167 167 def csv_value(column, object, value)
168 168 format_object(value, false) do |value|
169 169 case value.class.name
170 170 when 'Float'
171 171 sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
172 172 when 'IssueRelation'
173 173 value.to_s(object)
174 174 when 'Issue'
175 175 if object.is_a?(TimeEntry)
176 176 "#{value.tracker} ##{value.id}: #{value.subject}"
177 177 else
178 178 value.id
179 179 end
180 180 else
181 181 value
182 182 end
183 183 end
184 184 end
185 185
186 186 def query_to_csv(items, query, options={})
187 187 options ||= {}
188 188 columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
189 189 query.available_block_columns.each do |column|
190 190 if options[column.name].present?
191 191 columns << column
192 192 end
193 193 end
194 194
195 195 Redmine::Export::CSV.generate do |csv|
196 196 # csv header fields
197 197 csv << columns.map {|c| c.caption.to_s}
198 198 # csv lines
199 199 items.each do |item|
200 200 csv << columns.map {|c| csv_content(c, item)}
201 201 end
202 202 end
203 203 end
204 204
205 205 # Retrieve query from session or build a new query
206 206 def retrieve_query
207 207 if !params[:query_id].blank?
208 208 cond = "project_id IS NULL"
209 209 cond << " OR project_id = #{@project.id}" if @project
210 210 @query = IssueQuery.where(cond).find(params[:query_id])
211 211 raise ::Unauthorized unless @query.visible?
212 212 @query.project = @project
213 213 session[:query] = {:id => @query.id, :project_id => @query.project_id}
214 214 sort_clear
215 215 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
216 216 # Give it a name, required to be valid
217 217 @query = IssueQuery.new(:name => "_")
218 218 @query.project = @project
219 219 @query.build_from_params(params)
220 220 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names, :totalable_names => @query.totalable_names}
221 221 else
222 222 # retrieve from session
223 223 @query = nil
224 224 @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
225 225 @query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names], :totalable_names => session[:query][:totalable_names])
226 226 @query.project = @project
227 227 end
228 228 end
229 229
230 230 def retrieve_query_from_session
231 231 if session[:query]
232 232 if session[:query][:id]
233 233 @query = IssueQuery.find_by_id(session[:query][:id])
234 234 return unless @query
235 235 else
236 236 @query = IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names], :totalable_names => session[:query][:totalable_names])
237 237 end
238 238 if session[:query].has_key?(:project_id)
239 239 @query.project_id = session[:query][:project_id]
240 240 else
241 241 @query.project = @project
242 242 end
243 243 @query
244 244 end
245 245 end
246
247 # Returns the query definition as hidden field tags
248 def query_as_hidden_field_tags(query)
249 tags = hidden_field_tag("set_filter", "1", :id => nil)
250
251 if query.filters.present?
252 query.filters.each do |field, filter|
253 tags << hidden_field_tag("f[]", field, :id => nil)
254 tags << hidden_field_tag("op[#{field}]", filter[:operator], :id => nil)
255 filter[:values].each do |value|
256 tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
257 end
258 end
259 end
260 if query.column_names.present?
261 query.column_names.each do |name|
262 tags << hidden_field_tag("c[]", name, :id => nil)
263 end
264 end
265 if query.totalable_names.present?
266 query.totalable_names.each do |name|
267 tags << hidden_field_tag("t[]", name, :id => nil)
268 end
269 end
270 if query.group_by.present?
271 tags << hidden_field_tag("group_by", query.group_by, :id => nil)
272 end
273
274 tags
275 end
246 276 end
@@ -1,119 +1,121
1 1 <div class="contextual">
2 2 <% if !@query.new_record? && @query.editable_by?(User.current) %>
3 3 <%= link_to l(:button_edit), edit_query_path(@query), :class => 'icon icon-edit' %>
4 4 <%= delete_link query_path(@query) %>
5 5 <% end %>
6 6 </div>
7 7
8 8 <h2><%= @query.new_record? ? l(:label_issue_plural) : @query.name %></h2>
9 9 <% html_title(@query.new_record? ? l(:label_issue_plural) : @query.name) %>
10 10
11 11 <%= form_tag({ :controller => 'issues', :action => 'index', :project_id => @project },
12 12 :method => :get, :id => 'query_form') do %>
13 13 <div id="query_form_with_buttons" class="hide-when-print">
14 14 <%= hidden_field_tag 'set_filter', '1' %>
15 15 <div id="query_form_content">
16 16 <fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>">
17 17 <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
18 18 <div style="<%= @query.new_record? ? "" : "display: none;" %>">
19 19 <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
20 20 </div>
21 21 </fieldset>
22 22 <fieldset class="collapsible collapsed">
23 23 <legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
24 24 <div style="display: none;">
25 25 <table>
26 26 <tr>
27 27 <td><%= l(:field_column_names) %></td>
28 28 <td><%= render_query_columns_selection(@query) %></td>
29 29 </tr>
30 30 <tr>
31 31 <td><label for='group_by'><%= l(:field_group_by) %></label></td>
32 32 <td><%= select_tag('group_by',
33 33 options_for_select(
34 34 [[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]},
35 35 @query.group_by)
36 36 ) %></td>
37 37 </tr>
38 38 <tr>
39 39 <td><%= l(:button_show) %></td>
40 40 <td><%= available_block_columns_tags(@query) %></td>
41 41 </tr>
42 42 <tr>
43 43 <td><%= l(:label_total_plural) %></td>
44 44 <td><%= available_totalable_columns_tags(@query) %></td>
45 45 </tr>
46 46 </table>
47 47 </div>
48 48 </fieldset>
49 49 </div>
50 50 <p class="buttons">
51 51 <%= link_to_function l(:button_apply), '$("#query_form").submit()', :class => 'icon icon-checked' %>
52 52 <%= link_to l(:button_clear), { :set_filter => 1, :project_id => @project }, :class => 'icon icon-reload' %>
53 53 <% if @query.new_record? && User.current.allowed_to?(:save_queries, @project, :global => true) %>
54 54 <%= link_to_function l(:button_save),
55 55 "$('#query_form').attr('action', '#{ @project ? new_project_query_path(@project) : new_query_path }').submit()",
56 56 :class => 'icon icon-save' %>
57 57 <% end %>
58 58 </p>
59 59 </div>
60 60 <% end %>
61 61
62 62 <%= error_messages_for 'query' %>
63 63 <% if @query.valid? %>
64 64 <% if @issues.empty? %>
65 65 <p class="nodata"><%= l(:label_no_data) %></p>
66 66 <% else %>
67 67 <%= render_query_totals(@query) %>
68 68 <%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query} %>
69 69 <span class="pagination"><%= pagination_links_full @issue_pages, @issue_count %></span>
70 70 <% end %>
71 71
72 72 <% other_formats_links do |f| %>
73 73 <%= f.link_to 'Atom', :url => params.merge(:key => User.current.rss_key) %>
74 74 <%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '350px'); return false;" %>
75 75 <%= f.link_to 'PDF', :url => params %>
76 76 <% end %>
77 77
78 78 <div id="csv-export-options" style="display:none;">
79 <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
80 <%= form_tag(params.merge({:format => 'csv',:page=>nil}), :method => :get, :id => 'csv-export-form') do %>
79 <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
80 <%= form_tag(_project_issues_path(@project, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
81 <%= query_as_hidden_field_tags(@query) %>
82 <%= hidden_field_tag 'sort', params[:sort], :id => nil %>
81 83 <p>
82 84 <label><%= radio_button_tag 'csv[columns]', '', true %> <%= l(:description_selected_columns) %></label><br />
83 85 <label><%= radio_button_tag 'csv[columns]', 'all' %> <%= l(:description_all_columns) %></label>
84 86 </p>
85 87 <p>
86 88 <label><%= check_box_tag 'csv[description]', '1', @query.has_column?(:description) %> <%= l(:field_description) %></label>
87 89 </p>
88 90 <% if @issue_count > Setting.issues_export_limit.to_i %>
89 91 <p class="icon icon-warning">
90 92 <%= l(:setting_issues_export_limit) %>: <%= Setting.issues_export_limit.to_i %>
91 93 </p>
92 94 <% end %>
93 95 <p class="buttons">
94 96 <%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %>
95 97 <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
96 98 </p>
97 99 <% end %>
98 100 </div>
99 101
100 102 <% end %>
101 103 <%= call_hook(:view_issues_index_bottom, { :issues => @issues, :project => @project, :query => @query }) %>
102 104
103 105 <% content_for :sidebar do %>
104 106 <%= render :partial => 'issues/sidebar' %>
105 107 <% end %>
106 108
107 109 <% content_for :header_tags do %>
108 110 <%= auto_discovery_link_tag(:atom,
109 111 {:query_id => @query, :format => 'atom',
110 112 :page => nil, :key => User.current.rss_key},
111 113 :title => l(:label_issue_plural)) %>
112 114 <%= auto_discovery_link_tag(:atom,
113 115 {:controller => 'journals', :action => 'index',
114 116 :query_id => @query, :format => 'atom',
115 117 :page => nil, :key => User.current.rss_key},
116 118 :title => l(:label_changes_details)) %>
117 119 <% end %>
118 120
119 121 <%= context_menu issues_context_menu_path %>
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