You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tracker.rb 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2011 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. class Tracker < ActiveRecord::Base
  18. before_destroy :check_integrity
  19. has_many :issues
  20. has_many :workflows, :dependent => :delete_all do
  21. def copy(source_tracker)
  22. Workflow.copy(source_tracker, nil, proxy_association.owner, nil)
  23. end
  24. end
  25. has_and_belongs_to_many :projects
  26. 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'
  27. acts_as_list
  28. validates_presence_of :name
  29. validates_uniqueness_of :name
  30. validates_length_of :name, :maximum => 30
  31. named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
  32. def to_s; name end
  33. def <=>(tracker)
  34. name <=> tracker.name
  35. end
  36. def self.all
  37. find(:all, :order => 'position')
  38. end
  39. # Returns an array of IssueStatus that are used
  40. # in the tracker's workflows
  41. def issue_statuses
  42. if @issue_statuses
  43. return @issue_statuses
  44. elsif new_record?
  45. return []
  46. end
  47. ids = Workflow.
  48. connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}").
  49. flatten.
  50. uniq
  51. @issue_statuses = IssueStatus.find_all_by_id(ids).sort
  52. end
  53. private
  54. def check_integrity
  55. raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id])
  56. end
  57. end