Class: ProjectQuery

Inherits:
Query
  • Object
show all
Defined in:
app/models/project_query.rb

Overview

Redmine - project management software Copyright (C) 2006-2020 Jean-Philippe Lang

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.

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.

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.

Constant Summary

Constants inherited from Query

Query::VISIBILITY_PRIVATE, Query::VISIBILITY_PUBLIC, Query::VISIBILITY_ROLES

Instance Method Summary collapse

Methods inherited from Query

add_available_column, #add_available_filter, #add_filter, #add_filter_error, #add_filters, #add_short_filter, #all_projects, #all_projects_values, #as_params, #assigned_to_values, #author_values, #available_block_columns, #available_filters, #available_filters_as_json, #available_inline_columns, #available_totalable_columns, #block_columns, build_from_params, #build_from_params, #column_names=, #columns, #css_classes, #default_totalable_names, #delete_available_filter, #display_type, #display_type=, #editable_by?, #fixed_version_values, #group_by_column, #group_by_sort_order, #group_by_statement, #groupable_columns, #grouped?, #has_column?, #has_custom_field_column?, #has_default_columns?, #has_filter?, #inline_columns, #is_global?, #is_private?, #is_public?, #issue_custom_fields, #issue_statuses_values, #label_for, #operator_for, operators_labels, #principals, #project_custom_fields, #project_statement, #project_statuses_values, #project_values, #queried_table_name, #result_count_by_group, #sort_clause, #sort_criteria, #sort_criteria=, #sort_criteria_key, #sort_criteria_order, #sortable_columns, #statement, #subproject_values, #time_entry_custom_fields, #total_by_group_for, #total_for, #totalable_columns, #totalable_names, #totalable_names=, #totals, #totals_by_group, #trackers, #type_for, #users, #validate_query_filters, #value_for, #values_for, visible, #visible?, #watcher_values

Methods included from Redmine::SubclassFactory

included

Constructor Details

#initialize(attributes = nil, *args) ⇒ ProjectQuery

Returns a new instance of ProjectQuery.


40
41
42
43
# File 'app/models/project_query.rb', line 40

def initialize(attributes=nil, *args)
  super attributes
  self.filters ||= { 'status' => {:operator => "=", :values => ['1']} }
end

Instance Method Details

#available_columnsObject


69
70
71
72
73
74
75
# File 'app/models/project_query.rb', line 69

def available_columns
  return @available_columns if @available_columns
  @available_columns = self.class.available_columns.dup
  @available_columns += project_custom_fields.visible.
                          map {|cf| QueryCustomFieldColumn.new(cf) }
  @available_columns
end

#available_display_typesObject


77
78
79
# File 'app/models/project_query.rb', line 77

def available_display_types
  ['board', 'list']
end

#base_scopeObject


93
94
95
# File 'app/models/project_query.rb', line 93

def base_scope
  Project.visible.where(statement)
end

#default_columns_namesObject


81
82
83
# File 'app/models/project_query.rb', line 81

def default_columns_names
  @default_columns_names = Setting.project_list_defaults.symbolize_keys[:column_names].map(&:to_sym)
end

#default_display_typeObject


85
86
87
# File 'app/models/project_query.rb', line 85

def default_display_type
  Setting.project_list_display_type
end

#default_sort_criteriaObject


89
90
91
# File 'app/models/project_query.rb', line 89

def default_sort_criteria
  [[]]
end

#initialize_available_filtersObject


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/project_query.rb', line 45

def initialize_available_filters
  add_available_filter(
    "status",
    :type => :list, :values => lambda { project_statuses_values }
  )
  add_available_filter(
    "id",
    :type => :list, :values => lambda { project_values }, :label => :field_project
  )
  add_available_filter "name", :type => :text
  add_available_filter "description", :type => :text
  add_available_filter(
    "parent_id",
    :type => :list_subprojects, :values => lambda { project_values }, :label => :field_parent
  )
  add_available_filter(
    "is_public",
    :type => :list,
    :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]]
  )
  add_available_filter "created_on", :type => :date_past
  add_custom_fields_filters(project_custom_fields)
end

#results_scope(options = {}) ⇒ Object


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/models/project_query.rb', line 97

def results_scope(options={})
  order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)

  order_option << "#{Project.table_name}.lft ASC"
  scope = base_scope.
    order(order_option).
    joins(joins_for_order_statement(order_option.join(',')))

  if has_custom_field_column?
    scope = scope.preload(:custom_values)
  end

  if has_column?(:parent_id)
    scope = scope.preload(:parent)
  end

  scope
end