##// END OF EJS Templates
Enumerations can now have custom fields defined on them. #4077...
Eric Davis -
r2831:ac4937a76755
parent child
Show More
@@ -0,0 +1,23
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class DocumentCategoryCustomField < CustomField
19 def type_name
20 :enumeration_doc_categories
21 end
22 end
23
@@ -0,0 +1,23
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class IssuePriorityCustomField < CustomField
19 def type_name
20 :enumeration_issue_priorities
21 end
22 end
23
@@ -0,0 +1,23
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class TimeEntryActivityCustomField < CustomField
19 def type_name
20 :enumeration_time_entry_activities
21 end
22 end
23
@@ -17,6 +17,9
17
17
18 class EnumerationsController < ApplicationController
18 class EnumerationsController < ApplicationController
19 before_filter :require_admin
19 before_filter :require_admin
20
21 helper :custom_fields
22 include CustomFieldsHelper
20
23
21 def index
24 def index
22 list
25 list
@@ -22,7 +22,10 module CustomFieldsHelper
22 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
22 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
23 {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
23 {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
24 {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
24 {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
25 {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural}
25 {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
26 {:name => 'TimeEntryActivityCustomField', :label => TimeEntryActivity::OptionName},
27 {:name => 'IssuePriorityCustomField', :label => IssuePriority::OptionName},
28 {:name => 'DocumentCategoryCustomField', :label => DocumentCategory::OptionName}
26 ]
29 ]
27 end
30 end
28
31
@@ -17,6 +17,7
17
17
18 class Enumeration < ActiveRecord::Base
18 class Enumeration < ActiveRecord::Base
19 acts_as_list :scope => 'type = \'#{type}\''
19 acts_as_list :scope => 'type = \'#{type}\''
20 acts_as_customizable
20
21
21 before_destroy :check_integrity
22 before_destroy :check_integrity
22
23
@@ -94,6 +94,9 when "IssueCustomField" %>
94 <% when "TimeEntryCustomField" %>
94 <% when "TimeEntryCustomField" %>
95 <p><%= f.check_box :is_required %></p>
95 <p><%= f.check_box :is_required %></p>
96
96
97 <% else %>
98 <p><%= f.check_box :is_required %></p>
99
97 <% end %>
100 <% end %>
98 <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
101 <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
99 </div>
102 </div>
@@ -9,4 +9,8
9 <p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
9 <p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
10 <%= check_box 'enumeration', 'is_default' %></p>
10 <%= check_box 'enumeration', 'is_default' %></p>
11 <!--[eoform:optvalue]-->
11 <!--[eoform:optvalue]-->
12
13 <% @enumeration.custom_field_values.each do |value| %>
14 <p><%= custom_field_tag_with_label :enumeration, value %></p>
15 <% end %>
12 </div> No newline at end of file
16 </div>
@@ -87,4 +87,17 custom_fields_006:
87 field_format: float
87 field_format: float
88 default_value: ""
88 default_value: ""
89 editable: true
89 editable: true
90 No newline at end of file
90 custom_fields_007:
91 name: Billable
92 min_length: 0
93 regexp: ""
94 is_for_all: false
95 is_filter: true
96 type: TimeEntryActivityCustomField
97 max_length: 0
98 possible_values: ""
99 id: 7
100 is_required: false
101 field_format: bool
102 default_value: ""
103 editable: true
@@ -83,4 +83,9 custom_values_014:
83 customized_id: 5
83 customized_id: 5
84 id: 14
84 id: 14
85 value: "-7.6"
85 value: "-7.6"
86 No newline at end of file
86 custom_values_015:
87 customized_type: TimeEntryActivity
88 custom_field_id: 7
89 customized_id: 10
90 id: 15
91 value: true
@@ -18,7 +18,7
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class EnumerationTest < ActiveSupport::TestCase
20 class EnumerationTest < ActiveSupport::TestCase
21 fixtures :enumerations, :issues
21 fixtures :enumerations, :issues, :custom_fields, :custom_values
22
22
23 def setup
23 def setup
24 end
24 end
@@ -81,4 +81,9 class EnumerationTest < ActiveSupport::TestCase
81 assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
81 assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
82 assert_equal 5, Enumeration.find(6).objects_count
82 assert_equal 5, Enumeration.find(6).objects_count
83 end
83 end
84
85 def test_should_be_customizable
86 assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
87 end
88
84 end
89 end
@@ -32,5 +32,54 class TimeEntryActivityTest < ActiveSupport::TestCase
32 def test_option_name
32 def test_option_name
33 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
33 assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
34 end
34 end
35
36 def test_create_with_custom_field
37 field = TimeEntryActivityCustomField.find_by_name('Billable')
38 e = TimeEntryActivity.new(:name => 'Custom Data')
39 e.custom_field_values = {field.id => "1"}
40 assert e.save
41
42 e.reload
43 assert_equal "1", e.custom_value_for(field).value
44 end
45
46 def test_create_without_required_custom_field_should_fail
47 field = TimeEntryActivityCustomField.find_by_name('Billable')
48 field.update_attribute(:is_required, true)
49
50 e = TimeEntryActivity.new(:name => 'Custom Data')
51 assert !e.save
52 assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
53 end
54
55 def test_create_with_required_custom_field_should_succeed
56 field = TimeEntryActivityCustomField.find_by_name('Billable')
57 field.update_attribute(:is_required, true)
58
59 e = TimeEntryActivity.new(:name => 'Custom Data')
60 e.custom_field_values = {field.id => "1"}
61 assert e.save
62 end
63
64 def test_update_issue_with_required_custom_field_change
65 field = TimeEntryActivityCustomField.find_by_name('Billable')
66 field.update_attribute(:is_required, true)
67
68 e = TimeEntryActivity.find(10)
69 assert e.available_custom_fields.include?(field)
70 # No change to custom field, record can be saved
71 assert e.save
72 # Blanking custom field, save should fail
73 e.custom_field_values = {field.id => ""}
74 assert !e.save
75 assert e.errors.on(:custom_values)
76
77 # Update custom field to valid value, save should succeed
78 e.custom_field_values = {field.id => "0"}
79 assert e.save
80 e.reload
81 assert_equal "0", e.custom_value_for(field).value
82 end
83
35 end
84 end
36
85
General Comments 0
You need to be logged in to leave comments. Login now