summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-11 16:33:51 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-11 16:33:51 +0000
commit3a28848ca03ae7d7e02c1bc9373a9f373cf0efeb (patch)
treebc5fd2f13bec04e46bc9b0aa71c784dfe90cb865 /app
parent1ca69f2af1eb152264fa0b0493f5173900da2f08 (diff)
downloadredmine-3a28848ca03ae7d7e02c1bc9373a9f373cf0efeb.tar.gz
redmine-3a28848ca03ae7d7e02c1bc9373a9f373cf0efeb.zip
Ability to sort the issue list by text, list, date and boolean custom fields (#1139).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2257 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/custom_field.rb21
-rw-r--r--app/models/custom_value.rb4
-rw-r--r--app/models/query.rb2
3 files changed, 26 insertions, 1 deletions
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 4759b714b..344f277e4 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -59,11 +59,32 @@ class CustomField < ActiveRecord::Base
v.custom_field.is_required = false
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
end
+
+ # Returns a ORDER BY clause that can used to sort customized
+ # objects by their value of the custom field.
+ # Returns false, if the custom field can not be used for sorting.
+ def order_statement
+ case field_format
+ when 'string', 'list', 'date', 'bool'
+ # COALESCE is here to make sure that blank and NULL values are sorted equally
+ "COALESCE((SELECT cv_sort.value FROM #{CustomValue.table_name} cv_sort" +
+ " WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
+ " AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
+ " AND cv_sort.custom_field_id=#{id} LIMIT 1), '')"
+ else
+ nil
+ end
+ end
def <=>(field)
position <=> field.position
end
+ def self.customized_class
+ self.name =~ /^(.+)CustomField$/
+ begin; $1.constantize; rescue nil; end
+ end
+
# to move in project_custom_field
def self.for_all
find(:all, :conditions => ["is_for_all=?", true], :order => 'position')
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 1d453baf0..085d242fa 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -30,6 +30,10 @@ class CustomValue < ActiveRecord::Base
self.value == '1'
end
+ def to_s
+ value.to_s
+ end
+
protected
def validate
if value.blank?
diff --git a/app/models/query.rb b/app/models/query.rb
index 1a4845975..0016cb24b 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -35,7 +35,7 @@ class QueryCustomFieldColumn < QueryColumn
def initialize(custom_field)
self.name = "cf_#{custom_field.id}".to_sym
- self.sortable = false
+ self.sortable = custom_field.order_statement || false
@cf = custom_field
end