annotate .svn/pristine/0a/0ac45c1808f5ee15f2487069dcbe64385e65e79f.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 class Tracker < ActiveRecord::Base
Chris@1296 19
Chris@1296 20 CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject description priority_id is_private).freeze
Chris@1296 21 # Fields that can be disabled
Chris@1296 22 # Other (future) fields should be appended, not inserted!
Chris@1296 23 CORE_FIELDS = %w(assigned_to_id category_id fixed_version_id parent_issue_id start_date due_date estimated_hours done_ratio).freeze
Chris@1296 24 CORE_FIELDS_ALL = (CORE_FIELDS_UNDISABLABLE + CORE_FIELDS).freeze
Chris@1296 25
Chris@1296 26 before_destroy :check_integrity
Chris@1296 27 has_many :issues
Chris@1296 28 has_many :workflow_rules, :dependent => :delete_all do
Chris@1296 29 def copy(source_tracker)
Chris@1296 30 WorkflowRule.copy(source_tracker, nil, proxy_association.owner, nil)
Chris@1296 31 end
Chris@1296 32 end
Chris@1296 33
Chris@1296 34 has_and_belongs_to_many :projects
Chris@1296 35 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'
Chris@1296 36 acts_as_list
Chris@1296 37
Chris@1296 38 attr_protected :field_bits
Chris@1296 39
Chris@1296 40 validates_presence_of :name
Chris@1296 41 validates_uniqueness_of :name
Chris@1296 42 validates_length_of :name, :maximum => 30
Chris@1296 43
Chris@1296 44 scope :sorted, order("#{table_name}.position ASC")
Chris@1296 45 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
Chris@1296 46
Chris@1296 47 def to_s; name end
Chris@1296 48
Chris@1296 49 def <=>(tracker)
Chris@1296 50 position <=> tracker.position
Chris@1296 51 end
Chris@1296 52
Chris@1296 53 # Returns an array of IssueStatus that are used
Chris@1296 54 # in the tracker's workflows
Chris@1296 55 def issue_statuses
Chris@1296 56 if @issue_statuses
Chris@1296 57 return @issue_statuses
Chris@1296 58 elsif new_record?
Chris@1296 59 return []
Chris@1296 60 end
Chris@1296 61
Chris@1296 62 ids = WorkflowTransition.
Chris@1296 63 connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{WorkflowTransition.table_name} WHERE tracker_id = #{id} AND type = 'WorkflowTransition'").
Chris@1296 64 flatten.
Chris@1296 65 uniq
Chris@1296 66
Chris@1296 67 @issue_statuses = IssueStatus.find_all_by_id(ids).sort
Chris@1296 68 end
Chris@1296 69
Chris@1296 70 def disabled_core_fields
Chris@1296 71 i = -1
Chris@1296 72 @disabled_core_fields ||= CORE_FIELDS.select { i += 1; (fields_bits || 0) & (2 ** i) != 0}
Chris@1296 73 end
Chris@1296 74
Chris@1296 75 def core_fields
Chris@1296 76 CORE_FIELDS - disabled_core_fields
Chris@1296 77 end
Chris@1296 78
Chris@1296 79 def core_fields=(fields)
Chris@1296 80 raise ArgumentError.new("Tracker.core_fields takes an array") unless fields.is_a?(Array)
Chris@1296 81
Chris@1296 82 bits = 0
Chris@1296 83 CORE_FIELDS.each_with_index do |field, i|
Chris@1296 84 unless fields.include?(field)
Chris@1296 85 bits |= 2 ** i
Chris@1296 86 end
Chris@1296 87 end
Chris@1296 88 self.fields_bits = bits
Chris@1296 89 @disabled_core_fields = nil
Chris@1296 90 core_fields
Chris@1296 91 end
Chris@1296 92
Chris@1296 93 # Returns the fields that are disabled for all the given trackers
Chris@1296 94 def self.disabled_core_fields(trackers)
Chris@1296 95 if trackers.present?
Chris@1296 96 trackers.uniq.map(&:disabled_core_fields).reduce(:&)
Chris@1296 97 else
Chris@1296 98 []
Chris@1296 99 end
Chris@1296 100 end
Chris@1296 101
Chris@1296 102 # Returns the fields that are enabled for one tracker at least
Chris@1296 103 def self.core_fields(trackers)
Chris@1296 104 if trackers.present?
Chris@1296 105 trackers.uniq.map(&:core_fields).reduce(:|)
Chris@1296 106 else
Chris@1296 107 CORE_FIELDS.dup
Chris@1296 108 end
Chris@1296 109 end
Chris@1296 110
Chris@1296 111 private
Chris@1296 112 def check_integrity
Chris@1296 113 raise Exception.new("Can't delete tracker") if Issue.where(:tracker_id => self.id).any?
Chris@1296 114 end
Chris@1296 115 end