To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / models / tracker.rb @ 912:5e80956cc792
History | View | Annotate | Download (2.19 KB)
| 1 | 909:cbb26bc654de | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | before_destroy :check_integrity
|
| 20 | 0:513646585e45 | Chris | 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 | 909:cbb26bc654de | Chris | |
| 27 | 0:513646585e45 | Chris | 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 | 507:0c939c159af4 | Chris | named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} |
| 36 | 909:cbb26bc654de | Chris | |
| 37 | 0:513646585e45 | Chris | def to_s; name end |
| 38 | 909:cbb26bc654de | Chris | |
| 39 | 0:513646585e45 | Chris | def <=>(tracker) |
| 40 | name <=> tracker.name |
||
| 41 | end
|
||
| 42 | |||
| 43 | def self.all |
||
| 44 | find(:all, :order => 'position') |
||
| 45 | end
|
||
| 46 | 909:cbb26bc654de | Chris | |
| 47 | 0:513646585e45 | Chris | # Returns an array of IssueStatus that are used
|
| 48 | # in the tracker's workflows
|
||
| 49 | def issue_statuses |
||
| 50 | if @issue_statuses |
||
| 51 | 909:cbb26bc654de | Chris | return @issue_statuses |
| 52 | 0:513646585e45 | Chris | elsif new_record?
|
| 53 | return []
|
||
| 54 | end
|
||
| 55 | 909:cbb26bc654de | Chris | |
| 56 | 0:513646585e45 | Chris | ids = Workflow.
|
| 57 | connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}").
|
||
| 58 | flatten. |
||
| 59 | uniq |
||
| 60 | 909:cbb26bc654de | Chris | |
| 61 | 0:513646585e45 | Chris | @issue_statuses = IssueStatus.find_all_by_id(ids).sort |
| 62 | end
|
||
| 63 | 909:cbb26bc654de | Chris | |
| 64 | 0:513646585e45 | Chris | private |
| 65 | def check_integrity |
||
| 66 | raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) |
||
| 67 | end
|
||
| 68 | end |