Class: ProjectQuery

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

Overview

Redmine - project management software Copyright © 2006-2022 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

Class Method Summary collapse

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.



48
49
50
51
# File 'app/models/project_query.rb', line 48

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

Class Method Details

.default(project: nil, user: User.current) ⇒ Object



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

def self.default(project: nil, user: User.current)
  query = nil
  if user&.logged?
    query = find_by_id user.pref.default_project_query
  end
  query || find_by_id(Setting.default_project_query)
end

Instance Method Details

#available_columnsObject



77
78
79
80
81
82
83
84
# File 'app/models/project_query.rb', line 77

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



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

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

#base_scopeObject



102
103
104
# File 'app/models/project_query.rb', line 102

def base_scope
  Project.visible.where(statement)
end

#default_columns_namesObject



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

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

#default_display_typeObject



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

def default_display_type
  Setting.project_list_display_type
end

#default_sort_criteriaObject



98
99
100
# File 'app/models/project_query.rb', line 98

def default_sort_criteria
  [[]]
end

#initialize_available_filtersObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/project_query.rb', line 53

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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/project_query.rb', line 106

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