Class: ProjectQuery
- Inherits:
-
Query
- Object
- ActiveRecord::Base
- Query
- ProjectQuery
show all
- Defined in:
- app/models/project_query.rb
Overview
Redmine - project management software Copyright © 2006-2023 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 Attribute Summary collapse
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, #column_names=, #columns, #css_classes, #default_totalable_names, #delete_available_filter, #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_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
included
Constructor Details
#initialize(attributes = nil, *args) ⇒ ProjectQuery
Returns a new instance of ProjectQuery.
54
55
56
57
|
# File 'app/models/project_query.rb', line 54
def initialize(attributes=nil, *args)
super attributes
self.filters ||= {'status' => {:operator => "=", :values => ['1']}}
end
|
Instance Attribute Details
#admin_projects ⇒ Object
Returns the value of attribute admin_projects.
21
22
23
|
# File 'app/models/project_query.rb', line 21
def admin_projects
@admin_projects
end
|
Class Method Details
.default(project: nil, user: User.current) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/models/project_query.rb', line 42
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
|
Instance Method Details
#available_columns ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'app/models/project_query.rb', line 89
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
98
99
100
101
102
103
104
|
# File 'app/models/project_query.rb', line 98
def available_display_types
if self.admin_projects
['list']
else
['board', 'list']
end
end
|
#base_scope ⇒ Object
135
136
137
138
139
140
141
|
# File 'app/models/project_query.rb', line 135
def base_scope
if self.admin_projects
Project.where(statement)
else
Project.visible.where(statement)
end
end
|
#build_from_params(params, defaults = {}) ⇒ Object
83
84
85
86
87
|
# File 'app/models/project_query.rb', line 83
def build_from_params(params, defaults={})
query = super
query.admin_projects = params[:admin_projects]
query
end
|
#default_columns_names ⇒ Object
123
124
125
|
# File 'app/models/project_query.rb', line 123
def default_columns_names
@default_columns_names = Setting.project_list_defaults.symbolize_keys[:column_names].map(&:to_sym)
end
|
#default_display_type ⇒ Object
127
128
129
|
# File 'app/models/project_query.rb', line 127
def default_display_type
Setting.project_list_display_type
end
|
#default_sort_criteria ⇒ Object
131
132
133
|
# File 'app/models/project_query.rb', line 131
def default_sort_criteria
[[]]
end
|
#display_type ⇒ Object
106
107
108
109
110
111
112
|
# File 'app/models/project_query.rb', line 106
def display_type
if self.admin_projects
'list'
else
super
end
end
|
#initialize_available_filters ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/models/project_query.rb', line 59
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
|
#project_statuses_values ⇒ Object
#results_scope(options = {}) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'app/models/project_query.rb', line 143
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
|