From 10971361fae0b81af2e8e37fdf4d0066d2417ae2 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 9 Mar 2025 23:20:50 +0000 Subject: [PATCH] Allow query class to select layout for QueriesController (#42352). Patch by Holger Just (user:hjust). git-svn-id: https://svn.redmine.org/redmine/trunk@23529 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/queries_controller.rb | 18 ++++++++++++++---- app/models/project_query.rb | 4 ++++ app/models/query.rb | 2 ++ app/models/user_query.rb | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index 53ce029b9..09dc683a8 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -19,6 +19,8 @@ class QueriesController < ApplicationController menu_item :issues + layout :query_layout + before_action :find_query, :only => [:edit, :update, :destroy] before_action :find_optional_project, :only => [:new, :create] @@ -52,7 +54,6 @@ class QueriesController < ApplicationController @query.user = User.current @query.project = @project @query.build_from_params(params) - render :layout => 'admin' if params[:admin_projects] end def create @@ -70,7 +71,6 @@ class QueriesController < ApplicationController end def edit - render :layout => 'admin' if params[:admin_projects] end def update @@ -109,11 +109,13 @@ class QueriesController < ApplicationController end def current_menu_item - @query ? @query.queried_class.to_s.underscore.pluralize.to_sym : nil + return unless @query + return if query_layout == 'admin' + @query.queried_class.to_s.underscore.pluralize.to_sym end def current_menu(project) - super if params[:admin_projects].nil? + super unless query_layout == 'admin' end private @@ -182,6 +184,14 @@ class QueriesController < ApplicationController redirect_to users_path(options) end + def query_layout + @query&.layout || 'base' + end + + def menu_items + {self.controller_name.to_sym => {:actions => {}, :default => current_menu_item}} + end + # Returns the Query subclass, IssueQuery by default # for compatibility with previous behaviour def query_class diff --git a/app/models/project_query.rb b/app/models/project_query.rb index 726721bd8..a43c1bc10 100644 --- a/app/models/project_query.rb +++ b/app/models/project_query.rb @@ -174,4 +174,8 @@ class ProjectQuery < Query scope end + + def layout + admin_projects ? 'admin' : super + end end diff --git a/app/models/query.rb b/app/models/query.rb index 445261893..29a46f272 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -355,6 +355,8 @@ class Query < ApplicationRecord # Permission required to view the queries, set on subclasses. class_attribute :view_permission + class_attribute :layout, default: 'base' + # Scope of queries that are global or on the given project scope :global_or_on_project, (lambda do |project| where(:project_id => (project.nil? ? nil : [nil, project.id])) diff --git a/app/models/user_query.rb b/app/models/user_query.rb index e805af2b5..2d605b902 100644 --- a/app/models/user_query.rb +++ b/app/models/user_query.rb @@ -17,6 +17,7 @@ # along with this program; if not, write to the Free Software class UserQuery < Query + self.layout = 'admin' self.queried_class = Principal # must be Principal (not User) for custom field filters to work self.available_columns = [