Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 class Tracker < ActiveRecord::Base
|
Chris@0
|
19 before_destroy :check_integrity
|
Chris@0
|
20 has_many :issues
|
Chris@0
|
21 has_many :workflows, :dependent => :delete_all do
|
Chris@0
|
22 def copy(source_tracker)
|
Chris@0
|
23 Workflow.copy(source_tracker, nil, proxy_owner, nil)
|
Chris@0
|
24 end
|
Chris@0
|
25 end
|
Chris@0
|
26
|
Chris@0
|
27 has_and_belongs_to_many :projects
|
Chris@0
|
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'
|
Chris@0
|
29 acts_as_list
|
Chris@0
|
30
|
Chris@0
|
31 validates_presence_of :name
|
Chris@0
|
32 validates_uniqueness_of :name
|
Chris@0
|
33 validates_length_of :name, :maximum => 30
|
Chris@0
|
34 validates_format_of :name, :with => /^[\w\s\'\-]*$/i
|
Chris@0
|
35
|
Chris@0
|
36 def to_s; name end
|
Chris@0
|
37
|
Chris@0
|
38 def <=>(tracker)
|
Chris@0
|
39 name <=> tracker.name
|
Chris@0
|
40 end
|
Chris@0
|
41
|
Chris@0
|
42 def self.all
|
Chris@0
|
43 find(:all, :order => 'position')
|
Chris@0
|
44 end
|
Chris@0
|
45
|
Chris@0
|
46 # Returns an array of IssueStatus that are used
|
Chris@0
|
47 # in the tracker's workflows
|
Chris@0
|
48 def issue_statuses
|
Chris@0
|
49 if @issue_statuses
|
Chris@0
|
50 return @issue_statuses
|
Chris@0
|
51 elsif new_record?
|
Chris@0
|
52 return []
|
Chris@0
|
53 end
|
Chris@0
|
54
|
Chris@0
|
55 ids = Workflow.
|
Chris@0
|
56 connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}").
|
Chris@0
|
57 flatten.
|
Chris@0
|
58 uniq
|
Chris@0
|
59
|
Chris@0
|
60 @issue_statuses = IssueStatus.find_all_by_id(ids).sort
|
Chris@0
|
61 end
|
Chris@0
|
62
|
Chris@0
|
63 private
|
Chris@0
|
64 def check_integrity
|
Chris@0
|
65 raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id])
|
Chris@0
|
66 end
|
Chris@0
|
67 end
|