Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

issue.rb 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. class Issue < ActiveRecord::Base
  18. belongs_to :project
  19. belongs_to :tracker
  20. belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
  21. belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
  22. belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
  23. belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
  24. belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
  25. belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
  26. #has_many :histories, :class_name => 'IssueHistory', :dependent => true, :order => "issue_histories.created_on DESC", :include => :status
  27. has_many :journals, :as => :journalized, :dependent => true
  28. has_many :attachments, :as => :container, :dependent => true
  29. has_many :custom_values, :dependent => true, :as => :customized
  30. has_many :custom_fields, :through => :custom_values
  31. validates_presence_of :subject, :description, :priority, :tracker, :author, :status
  32. validates_inclusion_of :done_ratio, :in => 0..100
  33. validates_associated :custom_values, :on => :update
  34. # set default status for new issues
  35. def before_validation
  36. self.status = IssueStatus.default if new_record?
  37. end
  38. def validate
  39. if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
  40. errors.add :due_date, :activerecord_error_not_a_date
  41. end
  42. if self.due_date and self.start_date and self.due_date < self.start_date
  43. errors.add :due_date, :activerecord_error_greater_than_start_date
  44. end
  45. end
  46. #def before_create
  47. # build_history
  48. #end
  49. def before_save
  50. if @current_journal
  51. # attributes changes
  52. (Issue.column_names - %w(id description)).each {|c|
  53. @current_journal.details << JournalDetail.new(:property => 'attr',
  54. :prop_key => c,
  55. :old_value => @issue_before_change.send(c),
  56. :value => send(c)) unless send(c)==@issue_before_change.send(c)
  57. }
  58. # custom fields changes
  59. custom_values.each {|c|
  60. @current_journal.details << JournalDetail.new(:property => 'cf',
  61. :prop_key => c.custom_field_id,
  62. :old_value => @custom_values_before_change[c.custom_field_id],
  63. :value => c.value) unless @custom_values_before_change[c.custom_field_id]==c.value
  64. }
  65. @current_journal.save unless @current_journal.details.empty? and @current_journal.notes.empty?
  66. end
  67. end
  68. def long_id
  69. "%05d" % self.id
  70. end
  71. def custom_value_for(custom_field)
  72. self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id }
  73. return nil
  74. end
  75. def init_journal(user, notes = "")
  76. @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
  77. @issue_before_change = self.clone
  78. @custom_values_before_change = {}
  79. self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
  80. @current_journal
  81. end
  82. private
  83. # Creates an history for the issue
  84. #def build_history
  85. # @history = self.histories.build
  86. # @history.status = self.status
  87. # @history.author = self.author
  88. #end
  89. end