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