Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
0b512af8
Commit
0b512af8
authored
Feb 18, 2013
by
Andrew8xx8
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Milestone uses StateMachine now
parent
29f70acc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
25 deletions
+39
-25
app/controllers/milestones_controller.rb
app/controllers/milestones_controller.rb
+1
-1
app/models/milestone.rb
app/models/milestone.rb
+18
-9
app/views/milestones/_milestone.html.haml
app/views/milestones/_milestone.html.haml
+2
-2
app/views/milestones/show.html.haml
app/views/milestones/show.html.haml
+4
-4
lib/api/milestones.rb
lib/api/milestones.rb
+2
-2
spec/models/milestone_spec.rb
spec/models/milestone_spec.rb
+2
-7
spec/requests/api/milestones_spec.rb
spec/requests/api/milestones_spec.rb
+10
-0
No files found.
app/controllers/milestones_controller.rb
View file @
0b512af8
...
...
@@ -12,7 +12,7 @@ class MilestonesController < ProjectResourceController
def
index
@milestones
=
case
params
[
:f
]
when
'all'
;
@project
.
milestones
.
order
(
"
closed
, due_date DESC"
)
when
'all'
;
@project
.
milestones
.
order
(
"
state
, due_date DESC"
)
when
'closed'
;
@project
.
milestones
.
closed
.
order
(
"due_date DESC"
)
else
@project
.
milestones
.
active
.
order
(
"due_date ASC"
)
end
...
...
app/models/milestone.rb
View file @
0b512af8
...
...
@@ -13,19 +13,32 @@
#
class
Milestone
<
ActiveRecord
::
Base
attr_accessible
:title
,
:description
,
:due_date
,
:
closed
,
:author_id_of_changes
attr_accessible
:title
,
:description
,
:due_date
,
:
state_event
,
:author_id_of_changes
attr_accessor
:author_id_of_changes
belongs_to
:project
has_many
:issues
has_many
:merge_requests
scope
:active
,
->
{
w
here
(
closed:
fals
e
)
}
scope
:closed
,
->
{
w
here
(
closed:
true
)
}
scope
:active
,
->
{
w
ith_state
(
:activ
e
)
}
scope
:closed
,
->
{
w
ith_state
(
:closed
)
}
validates
:title
,
presence:
true
validates
:project
,
presence:
true
validates
:closed
,
inclusion:
{
in:
[
true
,
false
]
}
state_machine
:state
,
:initial
=>
:active
do
event
:close
do
transition
:active
=>
:closed
end
event
:activate
do
transition
:closed
=>
:active
end
state
:closed
state
:active
end
def
expired?
if
due_date
...
...
@@ -68,17 +81,13 @@ class Milestone < ActiveRecord::Base
end
def
can_be_closed?
open
?
&&
issues
.
opened
.
count
.
zero?
active
?
&&
issues
.
opened
.
count
.
zero?
end
def
is_empty?
total_items_count
.
zero?
end
def
open?
!
closed
end
def
author_id
author_id_of_changes
end
...
...
app/views/milestones/_milestone.html.haml
View file @
0b512af8
%li
{
class:
"milestone milestone-#{milestone.closed ? 'closed' : 'open'}"
,
id:
dom_id
(
milestone
)
}
%li
{
class:
"milestone milestone-#{milestone.closed
?
? 'closed' : 'open'}"
,
id:
dom_id
(
milestone
)
}
.pull-right
-
if
can?
(
current_user
,
:admin_milestone
,
milestone
.
project
)
and
milestone
.
open?
-
if
can?
(
current_user
,
:admin_milestone
,
milestone
.
project
)
and
milestone
.
open
ed
?
=
link_to
edit_project_milestone_path
(
milestone
.
project
,
milestone
),
class:
"btn btn-small edit-milestone-link grouped"
do
%i
.icon-edit
Edit
...
...
app/views/milestones/show.html.haml
View file @
0b512af8
...
...
@@ -9,7 +9,7 @@
←
To milestones list
.span6
.pull-right
-
unless
@milestone
.
closed
-
unless
@milestone
.
closed
?
=
link_to
new_project_issue_path
(
@project
,
issue:
{
milestone_id:
@milestone
.
id
}),
class:
"btn btn-small grouped"
,
title:
"New Issue"
do
%i
.icon-plus
New Issue
...
...
@@ -25,12 +25,12 @@
%hr
%p
%span
All issues for this milestone are closed. You may close milestone now.
=
link_to
'Close Milestone'
,
project_milestone_path
(
@project
,
@milestone
,
milestone:
{
closed:
true
}),
method: :put
,
class:
"btn btn-small btn-remove"
=
link_to
'Close Milestone'
,
project_milestone_path
(
@project
,
@milestone
,
milestone:
{
state: :closed
}),
method: :put
,
class:
"btn btn-small btn-remove"
.ui-box.ui-box-show
.ui-box-head
%h4
.box-title
-
if
@milestone
.
closed
-
if
@milestone
.
closed
?
.error.status_info
Closed
-
elsif
@milestone
.
expired?
.error.status_info
Expired
...
...
@@ -63,7 +63,7 @@
%li
=
link_to
(
'All Issues'
,
'#'
)
%ul
.well-list
-
@issues
.
each
do
|
issue
|
%li
{
data:
{
closed:
issue
.
closed
}}
%li
{
data:
{
closed:
issue
.
closed
?
}}
=
link_to
[
@project
,
issue
]
do
%span
.badge.badge-info
##{issue.id}
–
...
...
lib/api/milestones.rb
View file @
0b512af8
...
...
@@ -59,14 +59,14 @@ module Gitlab
# title (optional) - The title of a milestone
# description (optional) - The description of a milestone
# due_date (optional) - The due date of a milestone
#
closed (optional) - The status of the milestone
#
state (optional) - The status of the milestone (close|activate)
# Example Request:
# PUT /projects/:id/milestones/:milestone_id
put
":id/milestones/:milestone_id"
do
authorize!
:admin_milestone
,
user_project
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
,
:
closed
]
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
,
:
state_event
]
if
@milestone
.
update_attributes
attrs
present
@milestone
,
with:
Entities
::
Milestone
else
...
...
spec/models/milestone_spec.rb
View file @
0b512af8
...
...
@@ -27,7 +27,6 @@ describe Milestone do
describe
"Validation"
do
it
{
should
validate_presence_of
(
:title
)
}
it
{
should
validate_presence_of
(
:project
)
}
it
{
should
ensure_inclusion_of
(
:closed
).
in_array
([
true
,
false
])
}
end
let
(
:milestone
)
{
create
(
:milestone
)
}
...
...
@@ -41,7 +40,7 @@ describe Milestone do
it
"should count closed issues"
do
IssueObserver
.
current_user
=
issue
.
author
issue
.
update_attributes
(
closed:
true
)
issue
.
close
milestone
.
issues
<<
issue
milestone
.
percent_complete
.
should
==
100
end
...
...
@@ -96,7 +95,7 @@ describe Milestone do
describe
:items_count
do
before
do
milestone
.
issues
<<
create
(
:issue
)
milestone
.
issues
<<
create
(
:
issue
,
closed:
tr
ue
)
milestone
.
issues
<<
create
(
:
closed_iss
ue
)
milestone
.
merge_requests
<<
create
(
:merge_request
)
end
...
...
@@ -109,8 +108,4 @@ describe Milestone do
describe
:can_be_closed?
do
it
{
milestone
.
can_be_closed?
.
should
be_true
}
end
describe
:open?
do
it
{
milestone
.
open?
.
should
be_true
}
end
end
spec/requests/api/milestones_spec.rb
View file @
0b512af8
...
...
@@ -44,4 +44,14 @@ describe Gitlab::API do
json_response
[
'title'
].
should
==
'updated title'
end
end
describe
"PUT /projects/:id/milestones/:milestone_id to close milestone"
do
it
"should update a project milestone"
do
put
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
"
,
user
),
state_event:
'close'
response
.
status
.
should
==
200
json_response
[
'state'
].
should
==
'closed'
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment