summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-03-12 18:06:54 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-03-12 18:06:54 +0000
commitc7c8dc71f2fc8f224deb0a5340f7bbb8906e584d (patch)
treede3c8964542f8bb72cef67f462df910c4e6446f7 /app/models
parent2b585407cb66a26f81ea0bcb8a922dd1203e25e0 (diff)
downloadredmine-c7c8dc71f2fc8f224deb0a5340f7bbb8906e584d.tar.gz
redmine-c7c8dc71f2fc8f224deb0a5340f7bbb8906e584d.zip
Ability to save "sort order" in custom queries (#2899).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2572 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/query.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index 5c9fad5e5..99ebb757e 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -28,6 +28,11 @@ class QueryColumn
def caption
l("field_#{name}")
end
+
+ # Returns true if the column is sortable, otherwise false
+ def sortable?
+ !sortable.nil?
+ end
end
class QueryCustomFieldColumn < QueryColumn
@@ -52,6 +57,7 @@ class Query < ActiveRecord::Base
belongs_to :user
serialize :filters
serialize :column_names
+ serialize :sort_criteria, Array
attr_protected :project_id, :user_id
@@ -261,6 +267,27 @@ class Query < ActiveRecord::Base
column_names.nil? || column_names.empty?
end
+ def sort_criteria=(arg)
+ c = []
+ if arg.is_a?(Hash)
+ arg = arg.keys.sort.collect {|k| arg[k]}
+ end
+ c = arg.select {|k,o| !k.to_s.blank?}.slice(0,3).collect {|k,o| [k.to_s, o == 'desc' ? o : 'asc']}
+ write_attribute(:sort_criteria, c)
+ end
+
+ def sort_criteria
+ read_attribute(:sort_criteria) || []
+ end
+
+ def sort_criteria_key(arg)
+ sort_criteria && sort_criteria[arg] && sort_criteria[arg].first
+ end
+
+ def sort_criteria_order(arg)
+ sort_criteria && sort_criteria[arg] && sort_criteria[arg].last
+ end
+
def project_statement
project_clauses = []
if project && !@project.descendants.active.empty?