summaryrefslogtreecommitdiffstats
path: root/app/controllers/queries_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/queries_controller.rb')
-rw-r--r--app/controllers/queries_controller.rb34
1 files changed, 22 insertions, 12 deletions
diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb
index 53ce029b9..24f37eda2 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
@@ -63,14 +64,13 @@ class QueriesController < ApplicationController
if @query.save
flash[:notice] = l(:notice_successful_create)
- redirect_to_items(:query_id => @query, :admin_projects => params[:admin_projects])
+ redirect_to_items(:query_id => @query)
else
render :action => 'new', :layout => !request.xhr?
end
end
def edit
- render :layout => 'admin' if params[:admin_projects]
end
def update
@@ -78,7 +78,7 @@ class QueriesController < ApplicationController
if @query.save
flash[:notice] = l(:notice_successful_update)
- redirect_to_items(:query_id => @query, :admin_projects => params[:admin_projects])
+ redirect_to_items(:query_id => @query)
else
render :action => 'edit'
end
@@ -109,18 +109,20 @@ 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
def find_query
@query = Query.find(params[:id])
- @query.admin_projects = params[:admin_projects] if @query.is_a?(ProjectQuery)
@project = @query.project
render_403 unless @query.editable_by?(User.current)
rescue ActiveRecord::RecordNotFound
@@ -171,17 +173,25 @@ class QueriesController < ApplicationController
end
def redirect_to_project_query(options)
- if params[:admin_projects]
- redirect_to admin_projects_path(options)
- else
- redirect_to projects_path(options)
- end
+ redirect_to projects_path(options)
+ end
+
+ def redirect_to_project_admin_query(options)
+ redirect_to admin_projects_path(options)
end
def redirect_to_user_query(options)
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