diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-07-05 12:20:07 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-07-05 12:20:07 +0000 |
commit | 4cecc1beeda2337f50090d9fc0fe1d54fb8d54e2 (patch) | |
tree | ae525d4ae044a57c48e01462eb76e34e485ed6e3 /app/models/tracker.rb | |
parent | 51a1bf90dda6bc22b29b3801fbb7139b891376e5 (diff) | |
download | redmine-4cecc1beeda2337f50090d9fc0fe1d54fb8d54e2.tar.gz redmine-4cecc1beeda2337f50090d9fc0fe1d54fb8d54e2.zip |
Ability to disable standard fields on a per tracker basis (#1091).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9912 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/tracker.rb')
-rw-r--r-- | app/models/tracker.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/models/tracker.rb b/app/models/tracker.rb index ce34f782c..109e0f423 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -16,6 +16,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Tracker < ActiveRecord::Base + + # Other fields should be appended, not inserted! + CORE_FIELDS = %w(assigned_to_id category_id fixed_version_id parent_issue_id start_date due_date estimated_hours done_ratio) + before_destroy :check_integrity has_many :issues has_many :workflows, :dependent => :delete_all do @@ -28,6 +32,8 @@ class Tracker < ActiveRecord::Base has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id' acts_as_list + attr_protected :field_bits + validates_presence_of :name validates_uniqueness_of :name validates_length_of :name, :maximum => 30 @@ -58,6 +64,39 @@ class Tracker < ActiveRecord::Base @issue_statuses = IssueStatus.find_all_by_id(ids).sort end + def disabled_core_fields + i = -1 + @disabled_core_fields ||= CORE_FIELDS.select { i += 1; (fields_bits || 0) & (2 ** i) != 0} + end + + def core_fields + CORE_FIELDS - disabled_core_fields + end + + def core_fields=(fields) + raise ArgumentError.new("Tracker.core_fields takes an array") unless fields.is_a?(Array) + + bits = 0 + CORE_FIELDS.each_with_index do |field, i| + unless fields.include?(field) + bits |= 2 ** i + end + end + self.fields_bits = bits + @disabled_core_fields = nil + core_fields + end + + # Returns the fields that are disabled for all the given trackers + def self.disabled_core_fields(trackers) + trackers.uniq.map(&:disabled_core_fields).reduce(:&) + end + + # Returns the fields that are enabled for one tracker at least + def self.core_fields(trackers) + trackers.uniq.map(&:core_fields).reduce(:|) + end + private def check_integrity raise Exception.new("Can't delete tracker") if Issue.where(:tracker_id => self.id).any? |