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