]> source.dussan.org Git - redmine.git/commitdiff
Enumerations can now have custom fields defined on them. #4077
authorEric Davis <edavis@littlestreamsoftware.com>
Wed, 21 Oct 2009 22:34:22 +0000 (22:34 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Wed, 21 Oct 2009 22:34:22 +0000 (22:34 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2945 e93f8b46-1217-0410-a6f0-8f06a7374b81

12 files changed:
app/controllers/enumerations_controller.rb
app/helpers/custom_fields_helper.rb
app/models/document_category_custom_field.rb [new file with mode: 0644]
app/models/enumeration.rb
app/models/issue_priority_custom_field.rb [new file with mode: 0644]
app/models/time_entry_activity_custom_field.rb [new file with mode: 0644]
app/views/custom_fields/_form.rhtml
app/views/enumerations/_form.rhtml
test/fixtures/custom_fields.yml
test/fixtures/custom_values.yml
test/unit/enumeration_test.rb
test/unit/time_entry_activity_test.rb

index 63965fae12fcf00f76679bf191a582e0c00b3f4b..8070df03d5c90c4ae5ad102ac7e6ac2fcd072b06 100644 (file)
@@ -17,6 +17,9 @@
 
 class EnumerationsController < ApplicationController
   before_filter :require_admin
+
+  helper :custom_fields
+  include CustomFieldsHelper
   
   def index
     list
index 6e99b6a7cbdb727c3470a054b6156c396e312246..2545dd893ba11e654aaf5630f1e2a3b6f41e6fd9 100644 (file)
@@ -22,7 +22,10 @@ module CustomFieldsHelper
             {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
             {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
             {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
-            {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural}
+            {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
+            {:name => 'TimeEntryActivityCustomField', :label => TimeEntryActivity::OptionName},
+            {:name => 'IssuePriorityCustomField', :label => IssuePriority::OptionName},
+            {:name => 'DocumentCategoryCustomField', :label => DocumentCategory::OptionName}
             ]
   end
   
diff --git a/app/models/document_category_custom_field.rb b/app/models/document_category_custom_field.rb
new file mode 100644 (file)
index 0000000..5cde029
--- /dev/null
@@ -0,0 +1,23 @@
+# redMine - project management software
+# Copyright (C) 2006  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+class DocumentCategoryCustomField < CustomField
+  def type_name
+    :enumeration_doc_categories
+  end
+end
+
index 380a4d3d21d2cbdec777506e9adb725afce418c7..4fb7d6d07f5e85d53466c80a4603cf2d1f65eab7 100644 (file)
@@ -17,6 +17,7 @@
 
 class Enumeration < ActiveRecord::Base
   acts_as_list :scope => 'type = \'#{type}\''
+  acts_as_customizable
 
   before_destroy :check_integrity
   
diff --git a/app/models/issue_priority_custom_field.rb b/app/models/issue_priority_custom_field.rb
new file mode 100644 (file)
index 0000000..559bafe
--- /dev/null
@@ -0,0 +1,23 @@
+# redMine - project management software
+# Copyright (C) 2006  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+class IssuePriorityCustomField < CustomField
+  def type_name
+    :enumeration_issue_priorities
+  end
+end
+
diff --git a/app/models/time_entry_activity_custom_field.rb b/app/models/time_entry_activity_custom_field.rb
new file mode 100644 (file)
index 0000000..149bbb5
--- /dev/null
@@ -0,0 +1,23 @@
+# redMine - project management software
+# Copyright (C) 2006  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+class TimeEntryActivityCustomField < CustomField
+  def type_name
+    :enumeration_time_entry_activities
+  end
+end
+
index b9d7ec017a86a7d4356fe6592d4c2e184287b59e..f82d28784cca8762901cf410ebc6eeca231686eb 100644 (file)
@@ -94,6 +94,9 @@ when "IssueCustomField" %>
 <% when "TimeEntryCustomField" %>
     <p><%= f.check_box :is_required %></p>
 
+<% else %>
+    <p><%= f.check_box :is_required %></p>
+    
 <% end %>
 <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
 </div>
index dac0c93319552b28e6a0ecd3d121cbc1d1c4c251..741bbc5d932a0f869b0a558953857e7a5beb45c4 100644 (file)
@@ -9,4 +9,8 @@
 <p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
 <%= check_box 'enumeration', 'is_default'  %></p>
 <!--[eoform:optvalue]-->
+
+<% @enumeration.custom_field_values.each do |value| %>
+       <p><%= custom_field_tag_with_label :enumeration, value %></p>
+<% end %>
 </div>
\ No newline at end of file
index b4b58c4d4a84b3b9b287789b76ab0abd1b098d47..dcbef29d69d43a6913f214d51ebd3fabc9878174 100644 (file)
@@ -87,4 +87,17 @@ custom_fields_006:
   field_format: float
   default_value: ""
   editable: true
-  
\ No newline at end of file
+custom_fields_007: 
+  name: Billable
+  min_length: 0
+  regexp: ""
+  is_for_all: false
+  is_filter: true
+  type: TimeEntryActivityCustomField
+  max_length: 0
+  possible_values: ""
+  id: 7
+  is_required: false
+  field_format: bool
+  default_value: ""
+  editable: true
index 783aa75c9b0bab6f1ca1ce88efebd8d4782d8c6e..4e6f4b3ffcfcca679da538535b0c00a89c56763f 100644 (file)
@@ -83,4 +83,9 @@ custom_values_014:
   customized_id: 5
   id: 14
   value: "-7.6"
-  
\ No newline at end of file
+custom_values_015: 
+  customized_type: TimeEntryActivity
+  custom_field_id: 7
+  customized_id: 10
+  id: 15
+  value: true
index 4dc6e15c345be7343b5b4638e0cf58b4b4eef50d..663077352419b3f1ac54ab647464a8bff6424d93 100644 (file)
@@ -18,7 +18,7 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class EnumerationTest < ActiveSupport::TestCase
-  fixtures :enumerations, :issues
+  fixtures :enumerations, :issues, :custom_fields, :custom_values
 
   def setup
   end
@@ -81,4 +81,9 @@ class EnumerationTest < ActiveSupport::TestCase
     assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
     assert_equal 5, Enumeration.find(6).objects_count
   end
+
+  def test_should_be_customizable
+    assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
+  end
+
 end
index 9422a91ab776c5589284444dbb3be8399de51e79..16077c0c93a7eeb728b6563679bc9c589b3f770a 100644 (file)
@@ -32,5 +32,54 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
   def test_option_name
     assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
   end
+
+  def test_create_with_custom_field
+    field = TimeEntryActivityCustomField.find_by_name('Billable')
+    e = TimeEntryActivity.new(:name => 'Custom Data')
+    e.custom_field_values = {field.id => "1"}
+    assert e.save
+
+    e.reload
+    assert_equal "1", e.custom_value_for(field).value
+  end
+
+  def test_create_without_required_custom_field_should_fail
+    field = TimeEntryActivityCustomField.find_by_name('Billable')
+    field.update_attribute(:is_required, true)
+
+    e = TimeEntryActivity.new(:name => 'Custom Data')
+    assert !e.save
+    assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
+  end
+
+  def test_create_with_required_custom_field_should_succeed
+    field = TimeEntryActivityCustomField.find_by_name('Billable')
+    field.update_attribute(:is_required, true)
+
+    e = TimeEntryActivity.new(:name => 'Custom Data')
+    e.custom_field_values = {field.id => "1"}
+    assert e.save
+  end
+
+  def test_update_issue_with_required_custom_field_change
+    field = TimeEntryActivityCustomField.find_by_name('Billable')
+    field.update_attribute(:is_required, true)
+
+    e = TimeEntryActivity.find(10)
+    assert e.available_custom_fields.include?(field)
+    # No change to custom field, record can be saved
+    assert e.save
+    # Blanking custom field, save should fail
+    e.custom_field_values = {field.id => ""}
+    assert !e.save
+    assert e.errors.on(:custom_values)
+    
+    # Update custom field to valid value, save should succeed
+    e.custom_field_values = {field.id => "0"}
+    assert e.save
+    e.reload
+    assert_equal "0", e.custom_value_for(field).value
+  end
+
 end