2012-04-08 23:28:58 +02:00
|
|
|
class Milestone < ActiveRecord::Base
|
2012-09-26 20:17:17 +02:00
|
|
|
attr_accessible :title, :description, :due_date, :closed
|
|
|
|
|
2012-04-08 23:28:58 +02:00
|
|
|
belongs_to :project
|
|
|
|
has_many :issues
|
|
|
|
|
2012-10-09 02:10:04 +02:00
|
|
|
validates :title, presence: true
|
|
|
|
validates :project, presence: true
|
2012-04-08 23:28:58 +02:00
|
|
|
|
|
|
|
def self.active
|
2012-04-19 20:24:02 +02:00
|
|
|
where("due_date > ? OR due_date IS NULL", Date.today)
|
2012-04-08 23:28:58 +02:00
|
|
|
end
|
|
|
|
|
2012-04-24 20:49:34 +02:00
|
|
|
def participants
|
2012-09-27 08:28:10 +02:00
|
|
|
User.where(id: issues.pluck(:assignee_id))
|
2012-04-24 20:49:34 +02:00
|
|
|
end
|
|
|
|
|
2012-04-08 23:28:58 +02:00
|
|
|
def percent_complete
|
2012-08-25 19:54:38 +02:00
|
|
|
((self.issues.closed.count * 100) / self.issues.count).abs
|
|
|
|
rescue ZeroDivisionError
|
|
|
|
100
|
2012-04-08 23:28:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def expires_at
|
|
|
|
"expires at #{due_date.stamp("Aug 21, 2011")}" if due_date
|
|
|
|
end
|
|
|
|
end
|
2012-09-27 08:20:36 +02:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: milestones
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# title :string(255) not null
|
|
|
|
# project_id :integer not null
|
|
|
|
# description :text
|
|
|
|
# due_date :date
|
|
|
|
# closed :boolean default(FALSE), not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
2012-10-09 10:14:17 +02:00
|
|
|
|