##// END OF EJS Templates
Fixed that grouping issue by key/value custom field does not work (#22178)....
Jean-Philippe Lang -
r14842:e0ae0f287a5f
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,74 +1,80
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class CustomFieldEnumeration < ActiveRecord::Base
18 class CustomFieldEnumeration < ActiveRecord::Base
19 belongs_to :custom_field
19 belongs_to :custom_field
20 attr_accessible :name, :active, :position
20 attr_accessible :name, :active, :position
21
21
22 validates_presence_of :name, :position, :custom_field_id
22 validates_presence_of :name, :position, :custom_field_id
23 validates_length_of :name, :maximum => 60
23 validates_length_of :name, :maximum => 60
24 validates_numericality_of :position, :only_integer => true
24 validates_numericality_of :position, :only_integer => true
25 before_create :set_position
25 before_create :set_position
26
26
27 scope :active, lambda { where(:active => true) }
27 scope :active, lambda { where(:active => true) }
28
28
29 def to_s
29 def to_s
30 name.to_s
30 name.to_s
31 end
31 end
32
32
33 def objects_count
33 def objects_count
34 custom_values.count
34 custom_values.count
35 end
35 end
36
36
37 def in_use?
37 def in_use?
38 objects_count > 0
38 objects_count > 0
39 end
39 end
40
40
41 alias :destroy_without_reassign :destroy
41 alias :destroy_without_reassign :destroy
42 def destroy(reassign_to=nil)
42 def destroy(reassign_to=nil)
43 if reassign_to
43 if reassign_to
44 custom_values.update_all(:value => reassign_to.id.to_s)
44 custom_values.update_all(:value => reassign_to.id.to_s)
45 end
45 end
46 destroy_without_reassign
46 destroy_without_reassign
47 end
47 end
48
48
49 def custom_values
49 def custom_values
50 custom_field.custom_values.where(:value => id.to_s)
50 custom_field.custom_values.where(:value => id.to_s)
51 end
51 end
52
52
53 def self.update_each(custom_field, attributes)
53 def self.update_each(custom_field, attributes)
54 return unless attributes.is_a?(Hash)
54 return unless attributes.is_a?(Hash)
55 transaction do
55 transaction do
56 attributes.each do |enumeration_id, enumeration_attributes|
56 attributes.each do |enumeration_id, enumeration_attributes|
57 enumeration = custom_field.enumerations.find_by_id(enumeration_id)
57 enumeration = custom_field.enumerations.find_by_id(enumeration_id)
58 if enumeration
58 if enumeration
59 enumeration.attributes = enumeration_attributes
59 enumeration.attributes = enumeration_attributes
60 unless enumeration.save
60 unless enumeration.save
61 raise ActiveRecord::Rollback
61 raise ActiveRecord::Rollback
62 end
62 end
63 end
63 end
64 end
64 end
65 end
65 end
66 end
66 end
67
67
68 def self.fields_for_order_statement(table=nil)
69 table ||= table_name
70 columns = ['position']
71 columns.uniq.map {|field| "#{table}.#{field}"}
72 end
73
68 private
74 private
69
75
70 def set_position
76 def set_position
71 max = self.class.where(:custom_field_id => custom_field_id).maximum(:position) || 0
77 max = self.class.where(:custom_field_id => custom_field_id).maximum(:position) || 0
72 self.position = max + 1
78 self.position = max + 1
73 end
79 end
74 end
80 end
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now