You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

queries_helper.rb 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2011 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. module QueriesHelper
  18. def operators_for_select(filter_type)
  19. Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]}
  20. end
  21. def column_header(column)
  22. column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
  23. :default_order => column.default_order) :
  24. content_tag('th', h(column.caption))
  25. end
  26. def column_content(column, issue)
  27. value = column.value(issue)
  28. case value.class.name
  29. when 'String'
  30. if column.name == :subject
  31. link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
  32. else
  33. h(value)
  34. end
  35. when 'Time'
  36. format_time(value)
  37. when 'Date'
  38. format_date(value)
  39. when 'Fixnum', 'Float'
  40. if column.name == :done_ratio
  41. progress_bar(value, :width => '80px')
  42. else
  43. h(value.to_s)
  44. end
  45. when 'User'
  46. link_to_user value
  47. when 'Project'
  48. link_to_project value
  49. when 'Version'
  50. link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
  51. when 'TrueClass'
  52. l(:general_text_Yes)
  53. when 'FalseClass'
  54. l(:general_text_No)
  55. when 'Issue'
  56. link_to_issue(value, :subject => false)
  57. else
  58. h(value)
  59. end
  60. end
  61. # Retrieve query from session or build a new query
  62. def retrieve_query
  63. if !params[:query_id].blank?
  64. cond = "project_id IS NULL"
  65. cond << " OR project_id = #{@project.id}" if @project
  66. @query = Query.find(params[:query_id], :conditions => cond)
  67. raise ::Unauthorized unless @query.visible?
  68. @query.project = @project
  69. session[:query] = {:id => @query.id, :project_id => @query.project_id}
  70. sort_clear
  71. else
  72. if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
  73. # Give it a name, required to be valid
  74. @query = Query.new(:name => "_")
  75. @query.project = @project
  76. if params[:fields] || params[:f]
  77. @query.filters = {}
  78. @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
  79. else
  80. @query.available_filters.keys.each do |field|
  81. @query.add_short_filter(field, params[field]) if params[field]
  82. end
  83. end
  84. @query.group_by = params[:group_by]
  85. @query.column_names = params[:c] || (params[:query] && params[:query][:column_names])
  86. session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
  87. else
  88. @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
  89. @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
  90. @query.project = @project
  91. end
  92. end
  93. end
  94. end