Milestone basic scaffold

This commit is contained in:
Dmitriy Zaporozhets 2012-04-09 00:28:58 +03:00
parent 667edcdd75
commit 23d950855d
28 changed files with 424 additions and 36 deletions

View file

@ -17,6 +17,7 @@ class Ability
:read_project,
:read_wiki,
:read_issue,
:read_milestone,
:read_snippet,
:read_team_member,
:read_merge_request,
@ -42,6 +43,7 @@ class Ability
:modify_merge_request,
:admin_project,
:admin_issue,
:admin_milestone,
:admin_snippet,
:admin_team_member,
:admin_merge_request,

View file

@ -1,5 +1,6 @@
class Issue < ActiveRecord::Base
belongs_to :project
belongs_to :milestone
belongs_to :author, :class_name => "User"
belongs_to :assignee, :class_name => "User"
has_many :notes, :as => :noteable, :dependent => :destroy

29
app/models/milestone.rb Normal file
View file

@ -0,0 +1,29 @@
class Milestone < ActiveRecord::Base
belongs_to :project
has_many :issues
validates_presence_of :project_id
validates_presence_of :title
def self.active
where("due_date > ? ", Date.today)
end
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

View file

@ -12,6 +12,7 @@ class Project < ActiveRecord::Base
has_many :events, :dependent => :destroy
has_many :merge_requests, :dependent => :destroy
has_many :issues, :dependent => :destroy, :order => "position"
has_many :milestones, :dependent => :destroy
has_many :users_projects, :dependent => :destroy
has_many :notes, :dependent => :destroy
has_many :snippets, :dependent => :destroy