##// END OF EJS Templates
Code cleanup....
Code cleanup. git-svn-id: http://svn.redmine.org/redmine/trunk@15073 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r14469:ecb1f660ac4d
r14691:e2a999743e97
Show More
queries_helper.rb
246 lines | 8.6 KiB | text/x-ruby | RubyLexer
/ app / helpers / queries_helper.rb
Jean-Philippe Lang
Added encoding comment to helpers (#9792)....
r8090 # encoding: utf-8
#
Jean-Philippe Lang
Shortens filter param names....
r5159 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r13490 # Copyright (C) 2006-2015 Jean-Philippe Lang
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/queries_helper.rb....
r6767 #
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/queries_helper.rb....
r6767 #
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jean-Philippe Lang
"queries" branch merged...
r92
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 module QueriesHelper
Jean-Philippe Lang
Fixed that Link custom fields are not displayed as links on the issue list (#16496)....
r12779 include ApplicationHelper
Jean-Philippe Lang
Build issue filters using javascript....
r9979 def filters_options_for_select(query)
Jean-Philippe Lang
Group filters in the filter select list (#13849)....
r13280 ungrouped = []
grouped = {}
query.available_filters.map do |field, field_options|
Jean-Philippe Lang
Adds issue filters on parent/subtasks (#6118)....
r13922 if [:tree, :relation].include?(field_options[:type])
Jean-Philippe Lang
Group filters in the filter select list (#13849)....
r13280 group = :label_related_issues
elsif field =~ /^(.+)\./
# association filters
group = "field_#{$1}"
elsif %w(member_of_group assigned_to_role).include?(field)
group = :field_assigned_to
elsif field_options[:type] == :date_past || field_options[:type] == :date
group = :label_date
end
if group
(grouped[group] ||= []) << [field_options[:name], field]
else
ungrouped << [field_options[:name], field]
end
end
# Don't group dates if there's only one (eg. time entries filters)
if grouped[:label_date].try(:size) == 1
ungrouped << grouped.delete(:label_date).first
end
s = options_for_select([[]] + ungrouped)
if grouped.present?
localized_grouped = grouped.map {|k,v| [l(k), v]}
s << grouped_options_for_select(localized_grouped)
Jean-Philippe Lang
Build issue filters using javascript....
r9979 end
Jean-Philippe Lang
Group filters in the filter select list (#13849)....
r13280 s
Jean-Philippe Lang
"queries" branch merged...
r92 end
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/queries_helper.rb....
r6767
Jean-Philippe Lang
Fixed that CSV Export of Spent Time ignores filters and columns selection (#13618)....
r11466 def query_filters_hidden_tags(query)
tags = ''.html_safe
query.filters.each do |field, options|
tags << hidden_field_tag("f[]", field, :id => nil)
tags << hidden_field_tag("op[#{field}]", options[:operator], :id => nil)
options[:values].each do |value|
tags << hidden_field_tag("v[#{field}][]", value, :id => nil)
end
end
tags
end
def query_columns_hidden_tags(query)
tags = ''.html_safe
query.columns.each do |column|
tags << hidden_field_tag("c[]", column.name, :id => nil)
end
tags
end
def query_hidden_tags(query)
query_filters_hidden_tags(query) + query_columns_hidden_tags(query)
end
Jean-Philippe Lang
Adds an option for displaying the issue description on the issue list (#3447)....
r10721 def available_block_columns_tags(query)
tags = ''.html_safe
query.available_block_columns.each do |column|
Jean-Philippe Lang
Removes duplicate ids (#15485)....
r12378 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column), :id => nil) + " #{column.caption}", :class => 'inline')
Jean-Philippe Lang
Adds an option for displaying the issue description on the issue list (#3447)....
r10721 end
tags
end
Jean-Philippe Lang
Adds options to display totals on the issue list (#1561)....
r14260 def available_totalable_columns_tags(query)
tags = ''.html_safe
query.available_totalable_columns.each do |column|
tags << content_tag('label', check_box_tag('t[]', column.name.to_s, query.totalable_columns.include?(column), :id => nil) + " #{column.caption}", :class => 'inline')
end
tags
end
Jean-Philippe Lang
Adds helpers for query columns selection....
r11221 def query_available_inline_columns_options(query)
(query.available_inline_columns - query.columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
end
def query_selected_inline_columns_options(query)
(query.inline_columns & query.available_inline_columns).reject(&:frozen?).collect {|column| [column.caption, column.name]}
end
Jean-Philippe Lang
Adds an helper for rendering query columns selection....
r11222 def render_query_columns_selection(query, options={})
tag_name = (options[:name] || 'c') + '[]'
render :partial => 'queries/columns', :locals => {:query => query, :tag_name => tag_name}
end
Jean-Philippe Lang
Adds options to display totals on the issue list (#1561)....
r14260 def render_query_totals(query)
return unless query.totalable_columns.present?
totals = query.totalable_columns.map do |column|
Jean-Philippe Lang
Display totals for each group on grouped queries (#1561)....
r14283 total_tag(column, query.total_for(column))
Jean-Philippe Lang
Adds options to display totals on the issue list (#1561)....
r14260 end
content_tag('p', totals.join(" ").html_safe, :class => "query-totals")
end
Jean-Philippe Lang
Display totals for each group on grouped queries (#1561)....
r14283 def total_tag(column, value)
label = content_tag('span', "#{column.caption}:")
value = content_tag('span', format_object(value), :class => 'value')
content_tag('span', label + " " + value, :class => "total-for-#{column.name.to_s.dasherize}")
end
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 def column_header(column)
Jean-Philippe Lang
Validates sort_key and sort_order params (#2378)....
r2169 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/queries_helper.rb....
r6767 :default_order => column.default_order) :
Jean-Philippe Lang
Additional escaping....
r6207 content_tag('th', h(column.caption))
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 end
Toshi MARUYAMA
remove trailing white-spaces from app/helpers/queries_helper.rb....
r6767
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 def column_content(column, issue)
Jean-Philippe Lang
Fixed that Link custom fields are not displayed as links on the issue list (#16496)....
r12779 value = column.value_object(issue)
Jean-Philippe Lang
Adds support for multiselect custom fields (#1189)....
r8601 if value.is_a?(Array)
Jean-Philippe Lang
Makes related issues available for display and filtering on the issue list (#3239, #3265)....
r10303 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
Jean-Philippe Lang
Adds support for multiselect custom fields (#1189)....
r8601 else
column_value(column, issue, value)
end
end
def column_value(column, issue, value)
Jean-Philippe Lang
Extract generic formatting options to an helper....
r12087 case column.name
when :id
link_to value, issue_path(issue)
when :subject
link_to value, issue_path(issue)
Jean-Philippe Lang
Fixed that parent column should not include issue subject (#13673)....
r13174 when :parent
value ? (value.visible? ? link_to_issue(value, :subject => false) : "##{value.id}") : ''
Jean-Philippe Lang
Extract generic formatting options to an helper....
r12087 when :description
issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
when :done_ratio
Jean-Philippe Lang
Improved responsiveness for versions and roadmap (#19097)....
r14469 progress_bar(value)
Jean-Philippe Lang
Extract generic formatting options to an helper....
r12087 when :relations
Jean-Philippe Lang
Makes related issues available for display and filtering on the issue list (#3239, #3265)....
r10303 content_tag('span',
Jean-Philippe Lang
Use IssueRelation#to_s....
r13183 value.to_s(issue) {|other| link_to_issue(other, :subject => false, :tracker => false)}.html_safe,
Jean-Philippe Lang
Makes related issues available for display and filtering on the issue list (#3239, #3265)....
r10303 :class => value.css_classes_for(issue))
Jean-Philippe Lang
Fixed: "None" category issue count is empty while grouping by category (#4308)....
r2998 else
Jean-Philippe Lang
Extract generic formatting options to an helper....
r12087 format_object(value)
Jean-Philippe Lang
Added the ability to customize columns of a saved query....
r771 end
end
Eric Davis
Refactor: move method to helper....
r3577
Jean-Philippe Lang
Fixed that float custom fields do not use CSV decimal separator (#10364)....
r11211 def csv_content(column, issue)
Jean-Philippe Lang
Fixed that Link custom fields are not displayed as links on the issue list (#16496)....
r12779 value = column.value_object(issue)
Jean-Philippe Lang
Fixed that float custom fields do not use CSV decimal separator (#10364)....
r11211 if value.is_a?(Array)
value.collect {|v| csv_value(column, issue, v)}.compact.join(', ')
else
csv_value(column, issue, value)
end
end
Jean-Philippe Lang
Time entries CSV export should include the tracker and subject of the issue (#18269)....
r13180 def csv_value(column, object, value)
Jean-Philippe Lang
Fixed that Link custom fields are not displayed as links on the issue list (#16496)....
r12779 format_object(value, false) do |value|
case value.class.name
when 'Float'
sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator))
when 'IssueRelation'
Jean-Philippe Lang
Use IssueRelation#to_s....
r13183 value.to_s(object)
Jean-Philippe Lang
Fixed CSV content for parent issue column (#13608)....
r13173 when 'Issue'
Jean-Philippe Lang
Time entries CSV export should include the tracker and subject of the issue (#18269)....
r13180 if object.is_a?(TimeEntry)
"#{value.tracker} ##{value.id}: #{value.subject}"
else
value.id
end
Jean-Philippe Lang
Fixed that Link custom fields are not displayed as links on the issue list (#16496)....
r12779 else
value
end
Jean-Philippe Lang
Fixed that float custom fields do not use CSV decimal separator (#10364)....
r11211 end
end
Jean-Philippe Lang
Refactor: #issues_to_csv and #entries_to_csv merged into QueriesHelper#query_to_csv....
r11218 def query_to_csv(items, query, options={})
Jean-Philippe Lang
Isolates csv options for a hash param (#1159)....
r14292 options ||= {}
Jean-Philippe Lang
Refactor: #issues_to_csv and #entries_to_csv merged into QueriesHelper#query_to_csv....
r11218 columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
query.available_block_columns.each do |column|
if options[column.name].present?
columns << column
end
end
Jean-Philippe Lang
Adds a class for handling CSV generation (#7037)....
r13920 Redmine::Export::CSV.generate do |csv|
Jean-Philippe Lang
Refactor: #issues_to_csv and #entries_to_csv merged into QueriesHelper#query_to_csv....
r11218 # csv header fields
Jean-Philippe Lang
Adds a class for handling CSV generation (#7037)....
r13920 csv << columns.map {|c| c.caption.to_s}
Jean-Philippe Lang
Refactor: #issues_to_csv and #entries_to_csv merged into QueriesHelper#query_to_csv....
r11218 # csv lines
items.each do |item|
Jean-Philippe Lang
Adds a class for handling CSV generation (#7037)....
r13920 csv << columns.map {|c| csv_content(c, item)}
Jean-Philippe Lang
Refactor: #issues_to_csv and #entries_to_csv merged into QueriesHelper#query_to_csv....
r11218 end
end
end
Eric Davis
Refactor: move method to helper....
r3577 # Retrieve query from session or build a new query
def retrieve_query
if !params[:query_id].blank?
cond = "project_id IS NULL"
cond << " OR project_id = #{@project.id}" if @project
Jean-Philippe Lang
Cleanup of finders with :conditions option....
r11733 @query = IssueQuery.where(cond).find(params[:query_id])
Jean-Philippe Lang
Fixed: private queries should not be accessible to other users (#8729)....
r6043 raise ::Unauthorized unless @query.visible?
Etienne Massip
Reverted removal of project assignment to query (#9108)....
r7536 @query.project = @project
Eric Davis
Refactor: move method to helper....
r3577 session[:query] = {:id => @query.id, :project_id => @query.project_id}
sort_clear
Etienne Massip
Refactor : convert queries to REST resources (also fixes #9108)....
r7529 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
# Give it a name, required to be valid
Jean-Philippe Lang
Adds STI to Query model. Issue queries are now IssueQuery instances....
r10737 @query = IssueQuery.new(:name => "_")
Etienne Massip
Refactor : convert queries to REST resources (also fixes #9108)....
r7529 @query.project = @project
Jean-Philippe Lang
Moved build_query_from_params helper to Query#build_from_params....
r10739 @query.build_from_params(params)
Jean-Philippe Lang
Adds options to display totals on the issue list (#1561)....
r14260 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}
Eric Davis
Refactor: move method to helper....
r3577 else
Etienne Massip
Refactor : convert queries to REST resources (also fixes #9108)....
r7529 # retrieve from session
Jean-Philippe Lang
Test failures with ruby1.8....
r11789 @query = nil
Jean-Philippe Lang
Adds STI to Query model. Issue queries are now IssueQuery instances....
r10737 @query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
Jean-Philippe Lang
Adds options to display totals on the issue list (#1561)....
r14260 @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])
Jean-Philippe Lang
Fixed that a cross-project custom query is not remembered inside project (#9738)....
r7993 @query.project = @project
Etienne Massip
Refactor : convert queries to REST resources (also fixes #9108)....
r7529 end
end
Etienne Massip
Reverted removal of project assignment to query (#9108)....
r7536
Jean-Philippe Lang
Adds previous/next links to issue (#2850)....
r8368 def retrieve_query_from_session
if session[:query]
Jean-Philippe Lang
Fixed previous/next links when navigating in a saved query....
r8537 if session[:query][:id]
Jean-Philippe Lang
Adds STI to Query model. Issue queries are now IssueQuery instances....
r10737 @query = IssueQuery.find_by_id(session[:query][:id])
Jean-Philippe Lang
Fixed previous/next links when navigating in a saved query....
r8537 return unless @query
else
Jean-Philippe Lang
Adds options to display totals on the issue list (#1561)....
r14260 @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])
Jean-Philippe Lang
Fixed previous/next links when navigating in a saved query....
r8537 end
Jean-Philippe Lang
Adds previous/next links to issue (#2850)....
r8368 if session[:query].has_key?(:project_id)
@query.project_id = session[:query][:project_id]
else
@query.project = @project
end
@query
end
end
Jean-Philippe Lang
"queries" branch merged...
r92 end