To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / models / tracker.rb @ 442:753f1380d6bc

History | View | Annotate | Download (2.1 KB)

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 Tracker < ActiveRecord::Base
19
  before_destroy :check_integrity  
20
  has_many :issues
21
  has_many :workflows, :dependent => :delete_all do
22
    def copy(source_tracker)
23
      Workflow.copy(source_tracker, nil, proxy_owner, nil)
24
    end
25
  end
26
  
27
  has_and_belongs_to_many :projects
28
  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'
29
  acts_as_list
30

    
31
  validates_presence_of :name
32
  validates_uniqueness_of :name
33
  validates_length_of :name, :maximum => 30
34

    
35
  def to_s; name end
36
  
37
  def <=>(tracker)
38
    name <=> tracker.name
39
  end
40

    
41
  def self.all
42
    find(:all, :order => 'position')
43
  end
44
  
45
  # Returns an array of IssueStatus that are used
46
  # in the tracker's workflows
47
  def issue_statuses
48
    if @issue_statuses
49
      return @issue_statuses 
50
    elsif new_record?
51
      return []
52
    end
53
    
54
    ids = Workflow.
55
            connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}").
56
            flatten.
57
            uniq
58
    
59
    @issue_statuses = IssueStatus.find_all_by_id(ids).sort
60
  end
61
  
62
private
63
  def check_integrity
64
    raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id])
65
  end
66
end