2012-06-26 14:23:09 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: milestones
|
|
|
|
#
|
|
|
|
# id :integer(4) not null, primary key
|
|
|
|
# title :string(255) not null
|
|
|
|
# project_id :integer(4) not null
|
|
|
|
# description :text
|
|
|
|
# due_date :date
|
|
|
|
# closed :boolean(1) default(FALSE), not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
|
2012-04-08 17:28:58 -04:00
|
|
|
class Milestone < ActiveRecord::Base
|
|
|
|
belongs_to :project
|
|
|
|
has_many :issues
|
|
|
|
|
|
|
|
validates_presence_of :project_id
|
|
|
|
validates_presence_of :title
|
|
|
|
|
|
|
|
def self.active
|
2012-04-19 14:24:02 -04:00
|
|
|
where("due_date > ? OR due_date IS NULL", Date.today)
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
|
|
|
|
2012-04-24 14:49:34 -04:00
|
|
|
def participants
|
2012-08-10 18:07:50 -04:00
|
|
|
User.where(id: issues.map(&:assignee_id))
|
2012-04-24 14:49:34 -04:00
|
|
|
end
|
|
|
|
|
2012-04-08 17:28:58 -04:00
|
|
|
def percent_complete
|
|
|
|
@percent_complete ||= begin
|
|
|
|
total_i = self.issues.count
|
|
|
|
closed_i = self.issues.closed.count
|
|
|
|
if total_i > 0
|
|
|
|
(closed_i * 100) / total_i
|
|
|
|
else
|
|
|
|
100
|
|
|
|
end
|
|
|
|
rescue => ex
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def expires_at
|
|
|
|
"expires at #{due_date.stamp("Aug 21, 2011")}" if due_date
|
|
|
|
end
|
|
|
|
end
|