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