2012-11-19 13:24:05 -05: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-04-08 17:28:58 -04:00
|
|
|
class Milestone < ActiveRecord::Base
|
2012-09-26 14:17:17 -04:00
|
|
|
attr_accessible :title, :description, :due_date, :closed
|
|
|
|
|
2012-04-08 17:28:58 -04:00
|
|
|
belongs_to :project
|
|
|
|
has_many :issues
|
2012-10-26 09:53:45 -04:00
|
|
|
has_many :merge_requests
|
2012-04-08 17:28:58 -04:00
|
|
|
|
2012-10-08 20:10:04 -04:00
|
|
|
validates :title, presence: true
|
|
|
|
validates :project, presence: true
|
2012-11-13 19:20:37 -05:00
|
|
|
validates :closed, inclusion: { in: [true, false] }
|
2012-04-08 17:28:58 -04:00
|
|
|
|
|
|
|
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-09-27 02:28:10 -04:00
|
|
|
User.where(id: issues.pluck(:assignee_id))
|
2012-04-24 14:49:34 -04:00
|
|
|
end
|
|
|
|
|
2012-10-29 17:45:11 -04:00
|
|
|
def open_items_count
|
|
|
|
self.issues.opened.count + self.merge_requests.opened.count
|
2012-10-29 16:40:00 -04:00
|
|
|
end
|
|
|
|
|
2012-10-29 17:45:11 -04:00
|
|
|
def closed_items_count
|
|
|
|
self.issues.closed.count + self.merge_requests.closed.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def total_items_count
|
|
|
|
self.issues.count + self.merge_requests.count
|
2012-10-29 16:40:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def percent_complete
|
2012-10-29 17:45:11 -04:00
|
|
|
((closed_items_count * 100) / total_items_count).abs
|
2012-08-25 13:54:38 -04:00
|
|
|
rescue ZeroDivisionError
|
|
|
|
100
|
2012-04-08 17:28:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def expires_at
|
|
|
|
"expires at #{due_date.stamp("Aug 21, 2011")}" if due_date
|
|
|
|
end
|
|
|
|
end
|