Moved build_query_from_params helper to Query#build_from_params.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10966 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-12-09 15:11:00 +00:00
parent eb1829e739
commit 10998c9bae
3 changed files with 19 additions and 17 deletions

View File

@ -47,7 +47,7 @@ class QueriesController < ApplicationController
@query.user = User.current
@query.project = @project
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
build_query_from_params
@query.build_from_params(params)
end
def create
@ -55,7 +55,7 @@ class QueriesController < ApplicationController
@query.user = User.current
@query.project = params[:query_is_for_all] ? nil : @project
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
build_query_from_params
@query.build_from_params(params)
@query.column_names = nil if params[:default_columns]
if @query.save
@ -73,7 +73,7 @@ class QueriesController < ApplicationController
@query.attributes = params[:query]
@query.project = nil if params[:query_is_for_all]
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
build_query_from_params
@query.build_from_params(params)
@query.column_names = nil if params[:default_columns]
if @query.save

View File

@ -131,7 +131,7 @@ module QueriesHelper
# Give it a name, required to be valid
@query = IssueQuery.new(:name => "_")
@query.project = @project
build_query_from_params
@query.build_from_params(params)
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
else
# retrieve from session
@ -157,17 +157,4 @@ module QueriesHelper
@query
end
end
def build_query_from_params
if params[:fields] || params[:f]
@query.filters = {}
@query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
else
@query.available_filters.keys.each do |field|
@query.add_short_filter(field, params[field]) if params[field]
end
end
@query.group_by = params[:group_by] || (params[:query] && params[:query][:group_by])
@query.column_names = params[:c] || (params[:query] && params[:query][:column_names])
end
end

View File

@ -158,6 +158,21 @@ class Query < ActiveRecord::Base
@is_for_all = project.nil?
end
# Builds the query from the given params
def build_from_params(params)
if params[:fields] || params[:f]
self.filters = {}
add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
else
available_filters.keys.each do |field|
add_short_filter(field, params[field]) if params[field]
end
end
self.group_by = params[:group_by] || (params[:query] && params[:query][:group_by])
self.column_names = params[:c] || (params[:query] && params[:query][:column_names])
self
end
def validate_query_filters
filters.each_key do |field|
if values_for(field)