Class: ProjectQuery
- Inherits:
-
Query
- Object
- ActiveRecord::Base
- ApplicationRecord
- Query
- ProjectQuery
- Defined in:
- app/models/project_query.rb
Overview
Redmine - project management software Copyright © 2006- 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.
Direct Known Subclasses
Constant Summary
Constants inherited from Query
Query::VISIBILITY_PRIVATE, Query::VISIBILITY_PUBLIC, Query::VISIBILITY_ROLES
Class Method Summary collapse
- .default(project: nil, user: User.current) ⇒ Object
-
.visible ⇒ Object
Inheriting ProjectAdminQuery from ProjectQuery introduces the problem that ProjectQuery.visible also yields ProjectAdminQueries, as well.
Instance Method Summary collapse
- #available_columns ⇒ Object
- #available_display_types ⇒ Object
- #base_scope ⇒ Object
- #default_columns_names ⇒ Object
- #default_display_type ⇒ Object
- #default_sort_criteria ⇒ Object
-
#initialize(attributes = nil, *args) ⇒ ProjectQuery
constructor
A new instance of ProjectQuery.
- #initialize_available_filters ⇒ Object
-
#result_count ⇒ Object
Returns the project count.
- #results_scope(options = {}) ⇒ Object
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?, #watcher_values
Methods included from Redmine::SubclassFactory
Methods inherited from ApplicationRecord
Constructor Details
#initialize(attributes = nil, *args) ⇒ ProjectQuery
Returns a new instance of ProjectQuery.
61 62 63 64 |
# File 'app/models/project_query.rb', line 61 def initialize(attributes=nil, *args) super(attributes) self.filters ||= {'status' => {:operator => "=", :values => ['1']}} end |
Class Method Details
.default(project: nil, user: User.current) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/project_query.rb', line 49 def self.default(project: nil, user: User.current) if user&.logged? && (query_id = user.pref.default_project_query).present? query = find_by(id: query_id) return query if query&.visible? end if (query_id = Setting.default_project_query).present? query = find_by(id: query_id) return query if query&.visibility == VISIBILITY_PUBLIC end nil end |
.visible ⇒ Object
Inheriting ProjectAdminQuery from ProjectQuery introduces the problem that ProjectQuery.visible also yields ProjectAdminQueries, as well. We fix that by adding a condition on the actual class name.
32 33 34 |
# File 'app/models/project_query.rb', line 32 def self.visible(*) super.where type: name end |
Instance Method Details
#available_columns ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'app/models/project_query.rb', line 91 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_types ⇒ Object
100 101 102 |
# File 'app/models/project_query.rb', line 100 def available_display_types ['board', 'list'] end |
#base_scope ⇒ Object
116 117 118 |
# File 'app/models/project_query.rb', line 116 def base_scope Project.visible.where(statement) end |
#default_columns_names ⇒ Object
104 105 106 |
# File 'app/models/project_query.rb', line 104 def default_columns_names @default_columns_names = Setting.project_list_defaults.symbolize_keys[:column_names].map(&:to_sym) end |
#default_display_type ⇒ Object
108 109 110 |
# File 'app/models/project_query.rb', line 108 def default_display_type Setting.project_list_display_type end |
#default_sort_criteria ⇒ Object
112 113 114 |
# File 'app/models/project_query.rb', line 112 def default_sort_criteria [[]] end |
#initialize_available_filters ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/project_query.rb', line 66 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_available_filter "updated_on", :type => :date_past add_custom_fields_filters(project_custom_fields) end |
#result_count ⇒ Object
Returns the project count
121 122 123 124 125 |
# File 'app/models/project_query.rb', line 121 def result_count base_scope.count rescue ::ActiveRecord::StatementInvalid => e raise StatementInvalid, e. end |
#results_scope(options = {}) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/models/project_query.rb', line 127 def results_scope(={}) order_option = [group_by_sort_order, ([: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(','))). limit([:limit]). offset([:offset]) if has_custom_field_column? scope = scope.preload(:custom_values) end if has_column?(:parent_id) scope = scope.preload(:parent) end if has_column?(:last_activity_date) Project.load_last_activity_date(scope) end scope end |