diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-11-28 09:31:56 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-11-28 09:31:56 +0000 |
commit | 4d2688e7a8b95a28c12f61b7d4ce8db6551283e8 (patch) | |
tree | d348eed57fb3bd7ace7796e4ed1a51165c420372 /app/helpers | |
parent | 86d8acb3446321a7d891b83bf73ecce27c20f849 (diff) | |
download | redmine-4d2688e7a8b95a28c12f61b7d4ce8db6551283e8.tar.gz redmine-4d2688e7a8b95a28c12f61b7d4ce8db6551283e8.zip |
Group filters in the filter select list (#13849).
git-svn-id: http://svn.redmine.org/redmine/trunk@13662 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/queries_helper.rb | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 1eb0fa593..64dd3f817 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -21,14 +21,35 @@ module QueriesHelper include ApplicationHelper def filters_options_for_select(query) - options_for_select(filters_options(query)) - end - - def filters_options(query) - options = [[]] - options += query.available_filters.map do |field, field_options| - [field_options[:name], field] + ungrouped = [] + grouped = {} + query.available_filters.map do |field, field_options| + if field_options[:type] == :relation + group = :label_related_issues + elsif field =~ /^(.+)\./ + # association filters + group = "field_#{$1}" + elsif %w(member_of_group assigned_to_role).include?(field) + group = :field_assigned_to + elsif field_options[:type] == :date_past || field_options[:type] == :date + group = :label_date + end + if group + (grouped[group] ||= []) << [field_options[:name], field] + else + ungrouped << [field_options[:name], field] + end + end + # Don't group dates if there's only one (eg. time entries filters) + if grouped[:label_date].try(:size) == 1 + ungrouped << grouped.delete(:label_date).first + end + s = options_for_select([[]] + ungrouped) + if grouped.present? + localized_grouped = grouped.map {|k,v| [l(k), v]} + s << grouped_options_for_select(localized_grouped) end + s end def query_filters_hidden_tags(query) |