Adds "between" operator for numeric filters (#6180).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6217 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
4a4a71349a
commit
932d4cdfea
|
@ -101,6 +101,7 @@ class Query < ActiveRecord::Base
|
|||
"*" => :label_all,
|
||||
">=" => :label_greater_or_equal,
|
||||
"<=" => :label_less_or_equal,
|
||||
"><" => :label_between,
|
||||
"<t+" => :label_in_less_than,
|
||||
">t+" => :label_in_more_than,
|
||||
"t+" => :label_in,
|
||||
|
@ -122,7 +123,7 @@ class Query < ActiveRecord::Base
|
|||
:date_past => [ ">t-", "<t-", "t-", "t", "w" ],
|
||||
:string => [ "=", "~", "!", "!~" ],
|
||||
:text => [ "~", "!~" ],
|
||||
:integer => [ "=", ">=", "<=", "!*", "*" ] }
|
||||
:integer => [ "=", ">=", "<=", "><", "!*", "*" ] }
|
||||
|
||||
cattr_reader :operators_by_filter_type
|
||||
|
||||
|
@ -306,6 +307,10 @@ class Query < ActiveRecord::Base
|
|||
def values_for(field)
|
||||
has_filter?(field) ? filters[field][:values] : nil
|
||||
end
|
||||
|
||||
def value_for(field, index=0)
|
||||
(values_for(field) || [])[index]
|
||||
end
|
||||
|
||||
def label_for(field)
|
||||
label = available_filters[field][:name] if available_filters.has_key?(field)
|
||||
|
@ -627,6 +632,12 @@ class Query < ActiveRecord::Base
|
|||
else
|
||||
sql = "#{db_table}.#{db_field} <= #{value.first.to_i}"
|
||||
end
|
||||
when "><"
|
||||
if is_custom_filter
|
||||
sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) BETWEEN #{value[0].to_i} AND #{value[1].to_i}"
|
||||
else
|
||||
sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_i} AND #{value[1].to_i}"
|
||||
end
|
||||
when "o"
|
||||
sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
|
||||
when "c"
|
||||
|
@ -654,6 +665,8 @@ class Query < ActiveRecord::Base
|
|||
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||
when "!~"
|
||||
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
|
||||
else
|
||||
raise "Unknown query operator #{operator}"
|
||||
end
|
||||
|
||||
return sql
|
||||
|
|
|
@ -22,13 +22,13 @@ function toggle_filter(field) {
|
|||
if (check_box.checked) {
|
||||
Element.show("operators_" + field);
|
||||
Form.Element.enable("operators_" + field);
|
||||
Form.Element.enable("values_" + field);
|
||||
$$(".values_" + field).each(function(el){ Form.Element.enable(el)});
|
||||
toggle_operator(field);
|
||||
} else {
|
||||
Element.hide("operators_" + field);
|
||||
Element.hide("div_values_" + field);
|
||||
Form.Element.disable("operators_" + field);
|
||||
Form.Element.disable("values_" + field);
|
||||
$$(".values_" + field).each(function(el){ Form.Element.disable(el)});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,18 @@ function toggle_operator(field) {
|
|||
case "o":
|
||||
case "c":
|
||||
Element.hide("div_values_" + field);
|
||||
var v = $$(".values_" + field);
|
||||
if (v.length > 1) {v[1].hide(); Form.Element.disable(v[1])}
|
||||
break;
|
||||
case "><":
|
||||
Element.show("div_values_" + field);
|
||||
var v = $$(".values_" + field);
|
||||
if (v.length > 1) {v[1].show(); Form.Element.enable(v[1])}
|
||||
break;
|
||||
default:
|
||||
Element.show("div_values_" + field);
|
||||
var v = $$(".values_" + field);
|
||||
if (v.length > 1) {v[1].hide(); Form.Element.disable(v[1])}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -86,22 +95,22 @@ Event.observe(document,"dom:loaded", apply_filters_observer);
|
|||
<%= check_box_tag 'f[]', field, query.has_filter?(field), :onclick => "toggle_filter('#{field}');", :id => "cb_#{field}" %>
|
||||
<label for="cb_<%= field %>"><%= filter[1][:name] || l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) %></label>
|
||||
</td>
|
||||
<td style="width:150px;">
|
||||
<td style="width:170px;">
|
||||
<%= select_tag "op[#{field}]", options_for_select(operators_for_select(options[:type]), query.operator_for(field)), :id => "operators_#{field}", :onchange => "toggle_operator('#{field}');", :style => "vertical-align: top;" %>
|
||||
</td>
|
||||
<td>
|
||||
<div id="div_values_<%= field %>" style="display:none;">
|
||||
<% case options[:type]
|
||||
when :list, :list_optional, :list_status, :list_subprojects %>
|
||||
<%= select_tag "v[#{field}][]", options_for_select(options[:values], query.values_for(field)), :id => "values_#{field}", :multiple => (query.values_for(field) && query.values_for(field).length > 1) %>
|
||||
<%= select_tag "v[#{field}][]", options_for_select(options[:values], query.values_for(field)), :class => "values_#{field}", :multiple => (query.values_for(field) && query.values_for(field).length > 1) %>
|
||||
<%= link_to_function image_tag('bullet_toggle_plus.png'), "toggle_multi_select('#{field}');", :style => "vertical-align: bottom;" %>
|
||||
<% when :date, :date_past %>
|
||||
<%= text_field_tag "v[#{field}][]", query.values_for(field), :id => "values_#{field}", :size => 3 %> <%= l(:label_day_plural) %>
|
||||
<%= text_field_tag "v[#{field}][]", query.value_for(field), :class => "values_#{field}", :size => 3 %> <%= l(:label_day_plural) %>
|
||||
<% when :string, :text %>
|
||||
<%= text_field_tag "v[#{field}][]", query.values_for(field), :id => "values_#{field}", :size => 30 %>
|
||||
<%= text_field_tag "v[#{field}][]", query.value_for(field), :class => "values_#{field}", :size => 30 %>
|
||||
<% when :integer %>
|
||||
<%= text_field_tag "v[#{field}][]", query.values_for(field), :id => "values_#{field}", :size => 3 %>
|
||||
<%= text_field_tag "v[#{field}][]", query.values_for(field), :id => "values_#{field}", :size => 3 %>
|
||||
<%= text_field_tag "v[#{field}][]", query.value_for(field), :class => "values_#{field}", :size => 3 %>
|
||||
<%= text_field_tag "v[#{field}][]", query.value_for(field, 1), :class => "values_#{field}", :size => 3 %>
|
||||
<% end %>
|
||||
</div>
|
||||
<script type="text/javascript">toggle_filter('<%= field %>');</script>
|
||||
|
|
|
@ -976,3 +976,4 @@ bg:
|
|||
enumeration_activities: Дейности (time tracking)
|
||||
enumeration_system_activity: Системна активност
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -991,3 +991,4 @@ bs:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -980,3 +980,4 @@ ca:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -981,3 +981,4 @@ cs:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -994,3 +994,4 @@ da:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -996,3 +996,4 @@ de:
|
|||
text_scm_command_not_available: Scm Kommando ist nicht verfügbar. Bitte prüfen Sie die Einstellungen im Administrationspanel.
|
||||
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -977,3 +977,4 @@ el:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -980,3 +980,4 @@ en-GB:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -623,6 +623,7 @@ en:
|
|||
label_in_more_than: in more than
|
||||
label_greater_or_equal: '>='
|
||||
label_less_or_equal: '<='
|
||||
label_between: between
|
||||
label_in: in
|
||||
label_today: today
|
||||
label_all_time: all time
|
||||
|
|
|
@ -1014,3 +1014,4 @@ es:
|
|||
text_scm_config: Puede configurar las órdenes de cada scm en configuration/configuration.yml. Por favor, reinicie la aplicación después de editarlo
|
||||
text_scm_command_not_available: La orden para el Scm no está disponible. Por favor, compruebe la configuración en el panel de administración.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -981,3 +981,4 @@ eu:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -980,3 +980,4 @@ fa:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -998,3 +998,4 @@ fi:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -939,6 +939,7 @@ fr:
|
|||
enumeration_activities: Activités (suivi du temps)
|
||||
label_greater_or_equal: ">="
|
||||
label_less_or_equal: "<="
|
||||
label_between: entre
|
||||
label_view_all_revisions: Voir toutes les révisions
|
||||
label_tag: Tag
|
||||
label_branch: Branche
|
||||
|
|
|
@ -989,3 +989,4 @@ gl:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -982,3 +982,4 @@ he:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -984,3 +984,4 @@ hr:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -996,3 +996,4 @@
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -985,3 +985,4 @@ id:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -978,3 +978,4 @@ it:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -1007,3 +1007,4 @@ ja:
|
|||
label_issues_visibility_public: プライベートチケット以外
|
||||
text_issues_destroy_descendants_confirmation: %{count}個の子チケットも削除されます。
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -1029,3 +1029,4 @@ ko:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -1037,3 +1037,4 @@ lt:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -972,3 +972,4 @@ lv:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -977,3 +977,4 @@ mk:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -978,3 +978,4 @@ mn:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -959,3 +959,4 @@ nl:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -964,3 +964,4 @@
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -994,3 +994,4 @@ pl:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -998,3 +998,4 @@ pt-BR:
|
|||
text_scm_config: Você pode configurar seus comandos de versionamento em config/configurations.yml. Por favor reinicie a aplicação após alterá-lo.
|
||||
text_scm_command_not_available: Comando de versionamento não disponível. Por favor verifique as configurações no painel de administração.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -982,3 +982,4 @@ pt:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -970,3 +970,4 @@ ro:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -1090,3 +1090,4 @@ ru:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -972,3 +972,4 @@ sk:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -973,3 +973,4 @@ sl:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -977,3 +977,4 @@ sr-YU:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -978,3 +978,4 @@ sr:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -1018,3 +1018,4 @@ sv:
|
|||
enumeration_activities: Aktiviteter (tidsuppföljning)
|
||||
enumeration_system_activity: Systemaktivitet
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -974,3 +974,4 @@ th:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -996,3 +996,4 @@ tr:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -973,3 +973,4 @@ uk:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -1028,3 +1028,4 @@ vi:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -1058,3 +1058,4 @@
|
|||
enumeration_activities: 活動 (時間追蹤)
|
||||
enumeration_system_activity: 系統活動
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -980,3 +980,4 @@ zh:
|
|||
text_scm_config: You can configure your scm commands in config/configuration.yml. Please restart the application after editing it.
|
||||
text_scm_command_not_available: Scm command is not available. Please check settings on the administration panel.
|
||||
notice_issue_successful_create: Issue %{id} created.
|
||||
label_between: between
|
||||
|
|
|
@ -127,6 +127,10 @@ class ActiveSupport::TestCase
|
|||
def assert_error_tag(options={})
|
||||
assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options))
|
||||
end
|
||||
|
||||
def assert_include(expected, s)
|
||||
assert s.include?(expected), "\"#{expected}\" not found in \"#{s}\""
|
||||
end
|
||||
|
||||
# Shoulda macros
|
||||
def self.should_render_404
|
||||
|
|
|
@ -130,6 +130,21 @@ class QueryTest < ActiveSupport::TestCase
|
|||
assert query.statement.include?("CAST(custom_values.value AS decimal(60,3)) <= 30")
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_between
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter('done_ratio', '><', ['30', '40'])
|
||||
assert_include "#{Issue.table_name}.done_ratio BETWEEN 30 AND 40", query.statement
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_between_on_custom_field
|
||||
f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true)
|
||||
query = Query.new(:project => Project.find(1), :name => '_')
|
||||
query.add_filter("cf_#{f.id}", '><', ['30', '40'])
|
||||
assert_include "CAST(custom_values.value AS decimal(60,3)) BETWEEN 30 AND 40", query.statement
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_in_more_than
|
||||
Issue.find(7).update_attribute(:due_date, (Date.today + 15))
|
||||
|
|
Loading…
Reference in New Issue