summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMarius Balteanu <marius.balteanu@zitec.com>2021-11-15 21:58:39 +0000
committerMarius Balteanu <marius.balteanu@zitec.com>2021-11-15 21:58:39 +0000
commit70f8ca64dd9337e40b551e0ab876273a742a7551 (patch)
tree3a2c84965bcdf63d8c75aadd39612fb743e012a2 /app
parent9def0fa3d06cebf49e306d9eadfcc97745087a9e (diff)
downloadredmine-70f8ca64dd9337e40b551e0ab876273a742a7551.tar.gz
redmine-70f8ca64dd9337e40b551e0ab876273a742a7551.zip
You can configure default project queries in the following places (#35795):
* App-level: Administration > Projects > Default query (Projects list defaults section) * User-level: My account > Default project query git-svn-id: http://svn.redmine.org/redmine/trunk@21281 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects_controller.rb16
-rw-r--r--app/helpers/settings_helper.rb4
-rw-r--r--app/helpers/users_helper.rb12
-rw-r--r--app/models/issue_query.rb1
-rw-r--r--app/models/project_query.rb8
-rw-r--r--app/models/query.rb1
-rw-r--r--app/models/user_preference.rb4
-rw-r--r--app/views/settings/_projects.html.erb5
-rw-r--r--app/views/users/_preferences.html.erb1
9 files changed, 51 insertions, 1 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 36f0261f9..6ec522dd5 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -51,6 +51,7 @@ class ProjectsController < ApplicationController
return
end
+ retrieve_default_query
retrieve_project_query
scope = project_scope
@@ -323,4 +324,19 @@ class ProjectsController < ApplicationController
def retrieve_project_query
retrieve_query(ProjectQuery, false, :defaults => @default_columns_names)
end
+
+ def retrieve_default_query
+ return if params[:query_id].present?
+ return if api_request?
+ return if params[:set_filter] && (params.key?(:op) || params.key?(:f))
+
+ if params[:without_default].present?
+ params[:set_filter] = 1
+ return
+ end
+
+ if default_query = ProjectQuery.default
+ params[:query_id] = default_query.id
+ end
+ end
end
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index c3b8e7a25..a6563a4fb 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -170,6 +170,10 @@ module SettingsHelper
[[l(:label_none), '']] + IssueQuery.only_public.where(project_id: nil).pluck(:name, :id)
end
+ def default_global_project_query_options
+ [[l(:label_none), '']] + ProjectQuery.only_public.pluck(:name, :id)
+ end
+
def cross_project_subtasks_options
options = [
[:label_disabled, ''],
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 5c1c964f0..f8ff66a81 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -41,6 +41,18 @@ module UsersHelper
grouped_options_for_select(grouped, user.pref.default_issue_query)
end
+ def default_project_query_options(user)
+ global_queries = ProjectQuery
+ global_public_queries = global_queries.only_public
+ global_user_queries = global_queries.where(user_id: user.id).where.not(id: global_public_queries.ids)
+ label = user == User.current ? 'label_my_queries' : 'label_default_queries.for_this_user'
+ grouped = {
+ l('label_default_queries.for_all_users') => global_public_queries.pluck(:name, :id),
+ l(".#{label}") => global_user_queries.pluck(:name, :id),
+ }
+ grouped_options_for_select(grouped, user.pref.default_project_query)
+ end
+
def textarea_font_options
[[l(:label_font_default), '']] + UserPreference::TEXTAREA_FONT_OPTIONS.map {|o| [l("label_font_#{o}"), o]}
end
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index efd0ad0f1..1ba3c5a2c 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -75,7 +75,6 @@ class IssueQuery < Query
has_many :projects, foreign_key: 'default_issue_query_id', dependent: :nullify, inverse_of: 'default_issue_query'
after_update { projects.clear unless visibility == VISIBILITY_PUBLIC }
- scope :only_public, ->{ where(visibility: VISIBILITY_PUBLIC) }
scope :for_all_projects, ->{ where(project_id: nil) }
def self.default(project: nil, user: User.current)
diff --git a/app/models/project_query.rb b/app/models/project_query.rb
index a99dce5e2..df70dc2bc 100644
--- a/app/models/project_query.rb
+++ b/app/models/project_query.rb
@@ -37,6 +37,14 @@ class ProjectQuery < Query
QueryColumn.new(:created_on, :sortable => "#{Project.table_name}.created_on", :default_order => 'desc')
]
+ 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
+
def initialize(attributes=nil, *args)
super attributes
self.filters ||= {'status' => {:operator => "=", :values => ['1']}}
diff --git a/app/models/query.rb b/app/models/query.rb
index 7d30e5d59..8d5f55061 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -339,6 +339,7 @@ class Query < ActiveRecord::Base
end)
scope :sorted, lambda {order(:name, :id)}
+ scope :only_public, ->{ where(visibility: VISIBILITY_PUBLIC) }
# to be implemented in subclasses that have a way to determine a default
# query for the given options
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 1675fb0ae..e5c1a390c 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -38,6 +38,7 @@ class UserPreference < ActiveRecord::Base
'recently_used_projects',
'history_default_tab',
'default_issue_query',
+ 'default_project_query',
'toolbar_language_options')
TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional']
@@ -120,6 +121,9 @@ class UserPreference < ActiveRecord::Base
def default_issue_query; self[:default_issue_query] end
def default_issue_query=(value); self[:default_issue_query]=value; end
+ def default_project_query; self[:default_project_query] end
+ def default_project_query=(value); self[:default_project_query]=value; end
+
# Returns the names of groups that are displayed on user's page
# Example:
# preferences.my_page_groups
diff --git a/app/views/settings/_projects.html.erb b/app/views/settings/_projects.html.erb
index d6c51a7f1..018a6c4cb 100644
--- a/app/views/settings/_projects.html.erb
+++ b/app/views/settings/_projects.html.erb
@@ -28,6 +28,11 @@
</p>
<%= render_query_columns_selection(query,
:name => 'settings[project_list_defaults][column_names]') %>
+
+ <p>
+ <label><%= l(:label_default_query) %></label>
+ <%= setting_select :default_project_query, default_global_project_query_options, label: false %>
+ </p>
</fieldset>
diff --git a/app/views/users/_preferences.html.erb b/app/views/users/_preferences.html.erb
index 8074cb569..acc646913 100644
--- a/app/views/users/_preferences.html.erb
+++ b/app/views/users/_preferences.html.erb
@@ -8,4 +8,5 @@
<p><%= pref_fields.select :history_default_tab, history_default_tab_options %></p>
<p><%= pref_fields.text_area :toolbar_language_options, :rows => 4 %></p>
<p><%= pref_fields.select :default_issue_query, default_issue_query_options(@user), include_blank: l(:label_none) %></p>
+<p><%= pref_fields.select :default_project_query, default_project_query_options(@user), include_blank: l(:label_none) %></p>
<% end %>