diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-03-13 19:17:59 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-03-13 19:17:59 +0000 |
commit | 71d88e55352a51b20dd5e2a4a44aa695834a36b9 (patch) | |
tree | 8d5708333c51b7da7319a5c182350758b00dc535 /app/models/query.rb | |
parent | b91489ce6bb0943cff50946af6e64be65d3ccd80 (diff) | |
download | redmine-71d88e55352a51b20dd5e2a4a44aa695834a36b9.tar.gz redmine-71d88e55352a51b20dd5e2a4a44aa695834a36b9.zip |
Get rid of sort_helper when using queries.
git-svn-id: http://svn.redmine.org/redmine/trunk@16390 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/query.rb')
-rw-r--r-- | app/models/query.rb | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index 7a43ca6fc..192502024 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -377,6 +377,7 @@ class Query < ActiveRecord::Base self.group_by = params[:group_by] || (params[:query] && params[:query][:group_by]) self.column_names = params[:c] || (params[:query] && params[:query][:column_names]) self.totalable_names = params[:t] || (params[:query] && params[:query][:totalable_names]) + self.sort_criteria = params[:sort] || (params[:query] && params[:query][:sort_criteria]) self end @@ -710,37 +711,40 @@ class Query < ActiveRecord::Base options[:totalable_names] || default_totalable_names || [] end + def default_sort_criteria + [] + end + def sort_criteria=(arg) - c = [] - if arg.is_a?(Hash) - arg = arg.keys.sort.collect {|k| arg[k]} - end - if arg - c = arg.select {|k,o| !k.to_s.blank?}.slice(0,3).collect {|k,o| [k.to_s, (o == 'desc' || o == false) ? 'desc' : 'asc']} - end - write_attribute(:sort_criteria, c) + c = Redmine::SortCriteria.new(arg) + write_attribute(:sort_criteria, c.to_a) + c end def sort_criteria - read_attribute(:sort_criteria) || [] + c = read_attribute(:sort_criteria) + if c.blank? + c = default_sort_criteria + end + Redmine::SortCriteria.new(c) end - def sort_criteria_key(arg) - sort_criteria && sort_criteria[arg] && sort_criteria[arg].first + def sort_criteria_key(index) + sort_criteria[index].try(:first) end - def sort_criteria_order(arg) - sort_criteria && sort_criteria[arg] && sort_criteria[arg].last + def sort_criteria_order(index) + sort_criteria[index].try(:last) end - def sort_criteria_order_for(key) - sort_criteria.detect {|k, order| key.to_s == k}.try(:last) + def sort_clause + sort_criteria.sort_clause(sortable_columns) end # Returns the SQL sort order that should be prepended for grouping def group_by_sort_order if column = group_by_column - order = (sort_criteria_order_for(column.name) || column.default_order || 'asc').try(:upcase) + order = (sort_criteria.order_for(column.name) || column.default_order || 'asc').try(:upcase) Array(column.sortable).map {|s| "#{s} #{order}"} end end @@ -878,6 +882,14 @@ class Query < ActiveRecord::Base totals end + def css_classes + s = sort_criteria.first + if s.present? + key, asc = s + "sort-by-#{key.to_s.dasherize} sort-#{asc}" + end + end + private def grouped_query(&block) |