]> source.dussan.org Git - redmine.git/commitdiff
Refactor: Move method to Query model
authorEric Davis <edavis@littlestreamsoftware.com>
Mon, 19 Apr 2010 15:08:28 +0000 (15:08 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Mon, 19 Apr 2010 15:08:28 +0000 (15:08 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3684 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/queries_controller.rb
app/models/query.rb

index 599060e6909e1105dd310d947bbb4f436a89f25b..0b798636c71c82012feaa96cc0c646673f4a48f7 100644 (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?
index 1ecf8dcea195f2a0353bca379ca3030343f97fa7..20f6ea67153cc7fca16ddf972101cd2c026fad3a 100644 (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]