summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects_controller.rb4
-rw-r--r--app/models/query.rb69
-rw-r--r--app/views/custom_fields/_form.rhtml1
-rw-r--r--app/views/queries/_filters.rhtml6
-rw-r--r--db/migrate/038_add_custom_field_is_filter.rb9
-rw-r--r--lang/de.yml1
-rw-r--r--lang/en.yml1
-rw-r--r--lang/es.yml1
-rw-r--r--lang/fr.yml1
-rw-r--r--lang/it.yml1
-rw-r--r--lang/ja.yml1
-rw-r--r--lang/zh.yml1
12 files changed, 75 insertions, 21 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index c3170bf5e..a3e805a9c 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -259,10 +259,10 @@ class ProjectsController < ApplicationController
end
if @query.valid?
- @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
+ @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement)
@issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
@issues = Issue.find :all, :order => sort_clause,
- :include => [ :assigned_to, :status, :tracker, :project, :priority ],
+ :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ],
:conditions => @query.statement,
:limit => @issue_pages.items_per_page,
:offset => @issue_pages.current.offset
diff --git a/app/models/query.rb b/app/models/query.rb
index fcfad6839..e26e6a68e 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -48,6 +48,7 @@ class Query < ActiveRecord::Base
:list_one_or_more => [ "*", "=" ],
:date => [ "<t+", ">t+", "t+", "t", ">t-", "<t-", "t-" ],
:date_past => [ ">t-", "<t-", "t-", "t" ],
+ :string => [ "=", "~", "!", "!~" ],
:text => [ "~", "!~" ] }
cattr_reader :operators_by_filter_type
@@ -60,7 +61,7 @@ class Query < ActiveRecord::Base
def validate
filters.each_key do |field|
- errors.add field.gsub(/\_id$/, ""), :activerecord_error_blank unless
+ errors.add label_for(field), :activerecord_error_blank unless
# filter requires one or more values
(values_for(field) and !values_for(field).first.empty?) or
# filter doesn't require any value
@@ -87,6 +88,21 @@ class Query < ActiveRecord::Base
unless @project.children.empty?
@available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.children.collect{|s| [s.name, s.id.to_s] } }
end
+ @project.all_custom_fields.select(&:is_filter?).each do |field|
+ case field.field_format
+ when "string", "int"
+ options = { :type => :string, :order => 20 }
+ when "text"
+ options = { :type => :text, :order => 20 }
+ when "list"
+ options = { :type => :list_optional, :values => field.possible_values, :order => 20}
+ when "date"
+ options = { :type => :date, :order => 20 }
+ when "bool"
+ options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
+ end
+ @available_filters["cf_#{field.id}"] = options.merge({ :name => field.name })
+ end
# remove category filter if no category defined
@available_filters.delete "category_id" if @available_filters["category_id"][:values].empty?
end
@@ -126,6 +142,11 @@ class Query < ActiveRecord::Base
has_filter?(field) ? filters[field][:values] : nil
end
+ def label_for(field)
+ label = @available_filters[field][:name] if @available_filters.has_key?(field)
+ label ||= field.gsub(/\_id$/, "")
+ end
+
def statement
sql = "1=1"
if has_filter?("subproject_id")
@@ -142,40 +163,56 @@ class Query < ActiveRecord::Base
filters.each_key do |field|
next if field == "subproject_id"
v = values_for field
- next unless v and !v.empty?
+ next unless v and !v.empty?
+
sql = sql + " AND " unless sql.empty?
+ sql << "("
+
+ if field =~ /^cf_(\d+)$/
+ # custom field
+ db_table = CustomValue.table_name
+ db_field = "value"
+ sql << "#{db_table}.custom_field_id = #{$1} AND "
+ else
+ # regular field
+ db_table = Issue.table_name
+ db_field = field
+ end
+
case operator_for field
when "="
- sql = sql + "#{Issue.table_name}.#{field} IN (" + v.each(&:to_i).join(",") + ")"
+ sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
when "!"
- sql = sql + "#{Issue.table_name}.#{field} NOT IN (" + v.each(&:to_i).join(",") + ")"
+ sql = sql + "#{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"
when "!*"
- sql = sql + "#{Issue.table_name}.#{field} IS NULL"
+ sql = sql + "#{db_table}.#{db_field} IS NULL"
when "*"
- sql = sql + "#{Issue.table_name}.#{field} IS NOT NULL"
+ sql = sql + "#{db_table}.#{db_field} IS NOT NULL"
when "o"
sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
when "c"
sql = sql + "#{IssueStatus.table_name}.is_closed=#{connection.quoted_true}" if field == "status_id"
when ">t-"
- sql = sql + "#{Issue.table_name}.#{field} >= '%s'" % connection.quoted_date(Date.today - v.first.to_i)
+ sql = sql + "#{db_table}.#{db_field} >= '%s'" % connection.quoted_date(Date.today - v.first.to_i)
when "<t-"
- sql = sql + "#{Issue.table_name}.#{field} <= '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{db_table}.#{db_field} BETWEEN '#{connection.quoted_date(Date.new(0))}' AND '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
when "t-"
- sql = sql + "#{Issue.table_name}.#{field} = '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{db_table}.#{db_field} = '" + (Date.today - v.first.to_i).strftime("%Y-%m-%d") + "'"
when ">t+"
- sql = sql + "#{Issue.table_name}.#{field} >= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{db_table}.#{db_field} >= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
when "<t+"
- sql = sql + "#{Issue.table_name}.#{field} <= '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{db_table}.#{db_field} BETWEEN '#{connection.quoted_date(Date.new(0))}' AND '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
when "t+"
- sql = sql + "#{Issue.table_name}.#{field} = '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
+ sql = sql + "#{db_table}.#{db_field} = '" + (Date.today + v.first.to_i).strftime("%Y-%m-%d") + "'"
when "t"
- sql = sql + "#{Issue.table_name}.#{field} = '%s'" % connection.quoted_date(Date.today)
+ sql = sql + "#{db_table}.#{db_field} = '%s'" % connection.quoted_date(Date.today)
when "~"
- sql = sql + "#{Issue.table_name}.#{field} LIKE '%#{connection.quote_string(v.first)}%'"
+ sql = sql + "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(v.first)}%'"
when "!~"
- sql = sql + "#{Issue.table_name}.#{field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
+ sql = sql + "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(v.first)}%'"
end
+ sql << ")"
+
end if filters and valid?
sql
end
diff --git a/app/views/custom_fields/_form.rhtml b/app/views/custom_fields/_form.rhtml
index 427276445..32269e3f0 100644
--- a/app/views/custom_fields/_form.rhtml
+++ b/app/views/custom_fields/_form.rhtml
@@ -84,6 +84,7 @@ when "IssueCustomField" %>
&nbsp;
<p><%= f.check_box :is_required %></p>
<p><%= f.check_box :is_for_all %></p>
+ <p><%= f.check_box :is_filter %></p>
<% when "UserCustomField" %>
<p><%= f.check_box :is_required %></p>
diff --git a/app/views/queries/_filters.rhtml b/app/views/queries/_filters.rhtml
index 0314e30b5..de45f92a7 100644
--- a/app/views/queries/_filters.rhtml
+++ b/app/views/queries/_filters.rhtml
@@ -66,7 +66,7 @@ function toggle_multi_select(field) {
<tr <%= 'style="display:none;"' unless query.has_filter?(field) %> id="tr_<%= field %>">
<td valign="top" style="width:200px;">
<%= check_box_tag 'fields[]', field, query.has_filter?(field), :onclick => "toggle_filter('#{field}');", :id => "cb_#{field}" %>
- <label for="cb_<%= field %>"><%= l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) %></label>
+ <label for="cb_<%= field %>"><%= filter[1][:name] || l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) %></label>
</td>
<td valign="top" style="width:150px;">
<%= select_tag "operators[#{field}]", options_for_select(operators_for_select(options[:type]), query.operator_for(field)), :id => "operators_#{field}", :onchange => "toggle_operator('#{field}');", :class => "select-small", :style => "vertical-align: top;" %>
@@ -81,7 +81,7 @@ function toggle_multi_select(field) {
<%= link_to_function image_tag('expand.png'), "toggle_multi_select('#{field}');" %>
<% when :date, :date_past %>
<%= text_field_tag "values[#{field}][]", query.values_for(field), :id => "values_#{field}", :size => 3, :class => "select-small" %> <%= l(:label_day_plural) %>
- <% when :text %>
+ <% when :string, :text %>
<%= text_field_tag "values[#{field}][]", query.values_for(field), :id => "values_#{field}", :size => 30, :class => "select-small" %>
<% end %>
</div>
@@ -93,7 +93,7 @@ function toggle_multi_select(field) {
</td>
<td align="right" valign="top">
<%= l(:label_filter_add) %>:
-<%= select_tag 'add_filter_select', options_for_select([["",""]] + query.available_filters.sort{|a,b| a[1][:order]<=>b[1][:order]}.collect{|field| [l(("field_"+field[0].to_s.gsub(/\_id$/, "")).to_sym), field[0]] unless query.has_filter?(field[0])}.compact), :onchange => "add_filter();", :class => "select-small" %>
+<%= select_tag 'add_filter_select', options_for_select([["",""]] + query.available_filters.sort{|a,b| a[1][:order]<=>b[1][:order]}.collect{|field| [ field[1][:name] || l(("field_"+field[0].to_s.gsub(/\_id$/, "")).to_sym), field[0]] unless query.has_filter?(field[0])}.compact), :onchange => "add_filter();", :class => "select-small" %>
</td>
</tr>
</table>
diff --git a/db/migrate/038_add_custom_field_is_filter.rb b/db/migrate/038_add_custom_field_is_filter.rb
new file mode 100644
index 000000000..519ee0bd5
--- /dev/null
+++ b/db/migrate/038_add_custom_field_is_filter.rb
@@ -0,0 +1,9 @@
+class AddCustomFieldIsFilter < ActiveRecord::Migration
+ def self.up
+ add_column :custom_fields, :is_filter, :boolean, :null => false, :default => false
+ end
+
+ def self.down
+ remove_column :custom_fields, :is_filter
+ end
+end
diff --git a/lang/de.yml b/lang/de.yml
index 254dec4d7..95ae4a635 100644
--- a/lang/de.yml
+++ b/lang/de.yml
@@ -147,6 +147,7 @@ field_hours: Stunden
field_activity: Aktivität
field_spent_on: Datum
field_identifier: Identifier
+field_is_filter: Used as a filter
setting_app_title: Applikation Titel
setting_app_subtitle: Applikation Untertitel
diff --git a/lang/en.yml b/lang/en.yml
index 3193e9c3d..0e66a1faf 100644
--- a/lang/en.yml
+++ b/lang/en.yml
@@ -147,6 +147,7 @@ field_hours: Hours
field_activity: Activity
field_spent_on: Date
field_identifier: Identifier
+field_is_filter: Used as a filter
setting_app_title: Application title
setting_app_subtitle: Application subtitle
diff --git a/lang/es.yml b/lang/es.yml
index 393d473cf..a245d05fb 100644
--- a/lang/es.yml
+++ b/lang/es.yml
@@ -147,6 +147,7 @@ field_hours: Hours
field_activity: Activity
field_spent_on: Fecha
field_identifier: Identifier
+field_is_filter: Used as a filter
setting_app_title: Título del aplicación
setting_app_subtitle: Subtítulo del aplicación
diff --git a/lang/fr.yml b/lang/fr.yml
index 584c35dde..5cc05ef64 100644
--- a/lang/fr.yml
+++ b/lang/fr.yml
@@ -147,6 +147,7 @@ field_hours: Heures
field_activity: Activité
field_spent_on: Date
field_identifier: Identifiant
+field_is_filter: Utilisé comme filtre
setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application
diff --git a/lang/it.yml b/lang/it.yml
index a7379115e..6beb963ed 100644
--- a/lang/it.yml
+++ b/lang/it.yml
@@ -147,6 +147,7 @@ field_hours: Hours
field_activity: Activity
field_spent_on: Data
field_identifier: Identifier
+field_is_filter: Used as a filter
setting_app_title: Titolo applicazione
setting_app_subtitle: Sottotitolo applicazione
diff --git a/lang/ja.yml b/lang/ja.yml
index 5a4762240..8bcf77fe3 100644
--- a/lang/ja.yml
+++ b/lang/ja.yml
@@ -148,6 +148,7 @@ field_hours: 時間
field_activity: 活動
field_spent_on: 日付
field_identifier: 識別子
+field_is_filter: Used as a filter
setting_app_title: アプリケーションのタイトル
setting_app_subtitle: アプリケーションのサブタイトル
diff --git a/lang/zh.yml b/lang/zh.yml
index eede38687..be1c91f8a 100644
--- a/lang/zh.yml
+++ b/lang/zh.yml
@@ -150,6 +150,7 @@ field_hours: Hours
field_activity: 活动
field_spent_on: 日期
field_identifier: Identifier
+field_is_filter: Used as a filter
setting_app_title: 应用程序标题
setting_app_subtitle: 应用程序子标题