summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-09 15:11:00 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-09 15:11:00 +0000
commit10998c9bae314057b5c2adf97418618f68efb3d7 (patch)
tree8775fd8b26e49d6da20255a9ef080fc2c1c730a9 /app
parenteb1829e739bd50bd036c46415c014ff70e1de824 (diff)
downloadredmine-10998c9bae314057b5c2adf97418618f68efb3d7.tar.gz
redmine-10998c9bae314057b5c2adf97418618f68efb3d7.zip
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
Diffstat (limited to 'app')
-rw-r--r--app/controllers/queries_controller.rb6
-rw-r--r--app/helpers/queries_helper.rb15
-rw-r--r--app/models/query.rb15
3 files changed, 19 insertions, 17 deletions
diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb
index 1ecb62b68..16bc9f963 100644
--- a/app/controllers/queries_controller.rb
+++ b/app/controllers/queries_controller.rb
@@ -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
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 13f65fb61..9b0943aa7 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -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
diff --git a/app/models/query.rb b/app/models/query.rb
index c91cae8b1..81eeb9f3b 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -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)