Commit ac4937a7 authored by Eric Davis's avatar Eric Davis

Enumerations can now have custom fields defined on them. #4077

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2945 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 29ab7b41
......@@ -17,6 +17,9 @@
class EnumerationsController < ApplicationController
before_filter :require_admin
helper :custom_fields
include CustomFieldsHelper
def index
list
......
......@@ -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
......
# 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
......@@ -17,6 +17,7 @@
class Enumeration < ActiveRecord::Base
acts_as_list :scope => 'type = \'#{type}\''
acts_as_customizable
before_destroy :check_integrity
......
# 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
# 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
......@@ -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>
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment