Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

project_query.rb 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2017 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class ProjectQuery < Query
  19. self.queried_class = Project
  20. self.view_permission = :search_project
  21. self.available_columns = []
  22. def initialize(attributes=nil, *args)
  23. super attributes
  24. self.filters ||= { 'status' => {:operator => "=", :values => ['1']} }
  25. end
  26. def initialize_available_filters
  27. add_available_filter "status",
  28. :type => :list, :values => lambda { project_statuses_values }
  29. add_available_filter("id",
  30. :type => :list, :values => lambda { project_values }, :label => :field_project
  31. )
  32. add_available_filter "name", :type => :text
  33. add_available_filter "description", :type => :text
  34. add_available_filter("parent_id",
  35. :type => :list_subprojects, :values => lambda { project_values }, :label => :field_parent
  36. )
  37. add_available_filter "is_public",
  38. :type => :list,
  39. :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]]
  40. add_available_filter "created_on", :type => :date_past
  41. end
  42. def available_columns
  43. []
  44. end
  45. def base_scope
  46. Project.visible.where(statement)
  47. end
  48. def results_scope(options={})
  49. order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
  50. order_option << "#{Project.table_name}.id ASC"
  51. scope = base_scope.
  52. order(order_option).
  53. joins(joins_for_order_statement(order_option.join(',')))
  54. if has_custom_field_column?
  55. scope = scope.preload(:custom_values)
  56. end
  57. if has_column?(:parent_id)
  58. scope = scope.preload(:parent)
  59. end
  60. scope
  61. end
  62. end