Refactor: Move method to Query model

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3684 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-04-19 15:08:28 +00:00
parent 0004b52646
commit bf33b57aa4
2 changed files with 9 additions and 6 deletions

View File

@ -27,9 +27,7 @@ class QueriesController < ApplicationController
@query.is_public = false unless User.current.allowed_to?(:manage_public_queries, @project) || User.current.admin?
@query.column_names = nil if params[:default_columns]
params[:fields].each do |field|
@query.add_filter(field, params[:operators][field], params[:values][field])
end if params[:fields]
@query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
@query.group_by ||= params[:group_by]
if request.post? && params[:confirm] && @query.save
@ -43,9 +41,7 @@ class QueriesController < ApplicationController
def edit
if request.post?
@query.filters = {}
params[:fields].each do |field|
@query.add_filter(field, params[:operators][field], params[:values][field])
end if params[:fields]
@query.add_filters(params[:fields], params[:operators], params[:values]) if params[:fields]
@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?

View File

@ -243,6 +243,13 @@ class Query < ActiveRecord::Base
parms = expression.scan(/^(o|c|!\*|!|\*)?(.*)$/).first
add_filter field, (parms[0] || "="), [parms[1] || ""]
end
# Add multiple filters using +add_filter+
def add_filters(fields, operators, values)
fields.each do |field|
add_filter(field, operators[field], values[field])
end
end
def has_filter?(field)
filters and filters[field]