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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
50a8f16e
Commit
50a8f16e
authored
8 years ago
by
Alex Braha Stoll
Committed by
Adam Niedzielski
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add count badges to both dashboard and group milestones
parent
81ad6111
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
105 additions
and
20 deletions
+105
-20
app/controllers/dashboard/milestones_controller.rb
app/controllers/dashboard/milestones_controller.rb
+1
-0
app/controllers/groups/milestones_controller.rb
app/controllers/groups/milestones_controller.rb
+1
-0
app/models/global_milestone.rb
app/models/global_milestone.rb
+22
-0
app/views/dashboard/milestones/index.html.haml
app/views/dashboard/milestones/index.html.haml
+5
-5
app/views/groups/milestones/index.html.haml
app/views/groups/milestones/index.html.haml
+1
-1
app/views/projects/milestones/index.html.haml
app/views/projects/milestones/index.html.haml
+5
-5
app/views/shared/_milestones_filter.html.haml
app/views/shared/_milestones_filter.html.haml
+3
-9
changelogs/unreleased/24421-personal-milestone-count-badges.yml
...logs/unreleased/24421-personal-milestone-count-badges.yml
+4
-0
spec/models/global_milestone_spec.rb
spec/models/global_milestone_spec.rb
+63
-0
No files found.
app/controllers/dashboard/milestones_controller.rb
View file @
50a8f16e
...
...
@@ -5,6 +5,7 @@ class Dashboard::MilestonesController < Dashboard::ApplicationController
def
index
respond_to
do
|
format
|
format
.
html
do
@milestone_states
=
GlobalMilestone
.
states_count
(
@projects
)
@milestones
=
Kaminari
.
paginate_array
(
milestones
).
page
(
params
[
:page
])
end
format
.
json
do
...
...
This diff is collapsed.
Click to expand it.
app/controllers/groups/milestones_controller.rb
View file @
50a8f16e
...
...
@@ -6,6 +6,7 @@ class Groups::MilestonesController < Groups::ApplicationController
def
index
respond_to
do
|
format
|
format
.
html
do
@milestone_states
=
GlobalMilestone
.
states_count
(
@projects
)
@milestones
=
Kaminari
.
paginate_array
(
milestones
).
page
(
params
[
:page
])
end
end
...
...
This diff is collapsed.
Click to expand it.
app/models/global_milestone.rb
View file @
50a8f16e
...
...
@@ -28,6 +28,28 @@ class GlobalMilestone
new
(
title
,
child_milestones
)
end
def
self
.
states_count
(
projects
)
relation
=
MilestonesFinder
.
new
.
execute
(
projects
,
state:
'all'
)
milestones_by_state_and_title
=
relation
.
reorder
(
nil
).
group
(
:state
,
:title
).
count
opened
=
count_by_state
(
milestones_by_state_and_title
,
'active'
)
closed
=
count_by_state
(
milestones_by_state_and_title
,
'closed'
)
all
=
milestones_by_state_and_title
.
map
{
|
(
_
,
title
),
_
|
title
}.
uniq
.
count
{
opened:
opened
,
closed:
closed
,
all:
all
}
end
def
self
.
count_by_state
(
milestones_by_state_and_title
,
state
)
milestones_by_state_and_title
.
count
do
|
(
milestone_state
,
_
),
_
|
milestone_state
==
state
end
end
private_class_method
:count_by_state
def
initialize
(
title
,
milestones
)
@title
=
title
@name
=
title
...
...
This diff is collapsed.
Click to expand it.
app/views/dashboard/milestones/index.html.haml
View file @
50a8f16e
-
page_title
"Milestones"
-
header_title
"Milestones"
,
dashboard_milestones_path
-
page_title
'Milestones'
-
header_title
'Milestones'
,
dashboard_milestones_path
.top-area
=
render
'shared/milestones_filter'
=
render
'shared/milestones_filter'
,
counts:
@milestone_states
.nav-controls
=
render
'shared/new_project_item_select'
,
path:
'milestones/new'
,
label:
"New Milestone"
,
include_groups:
true
=
render
'shared/new_project_item_select'
,
path:
'milestones/new'
,
label:
'New Milestone'
,
include_groups:
true
.milestones
%ul
.content-list
...
...
@@ -15,4 +15,4 @@
-
else
-
@milestones
.
each
do
|
milestone
|
=
render
'milestone'
,
milestone:
milestone
=
paginate
@milestones
,
theme:
"gitlab"
=
paginate
@milestones
,
theme:
'gitlab'
This diff is collapsed.
Click to expand it.
app/views/groups/milestones/index.html.haml
View file @
50a8f16e
...
...
@@ -2,7 +2,7 @@
=
render
"groups/head_issues"
.top-area
=
render
'shared/milestones_filter'
=
render
'shared/milestones_filter'
,
counts:
@milestone_states
.nav-controls
-
if
can?
(
current_user
,
:admin_milestones
,
@group
)
...
...
This diff is collapsed.
Click to expand it.
app/views/projects/milestones/index.html.haml
View file @
50a8f16e
-
@no_container
=
true
-
page_title
"Milestones"
=
render
"projects/issues/head"
-
page_title
'Milestones'
=
render
'projects/issues/head'
%div
{
class:
container_class
}
.top-area
=
render
'shared/milestones_filter'
=
render
'shared/milestones_filter'
,
counts:
milestone_counts
(
@project
.
milestones
)
.nav-controls
-
if
can?
(
current_user
,
:admin_milestone
,
@project
)
=
link_to
new_namespace_project_milestone_path
(
@project
.
namespace
,
@project
),
class:
"btn btn-new"
,
title:
"New Milestone"
do
=
link_to
new_namespace_project_milestone_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-new'
,
title:
'New Milestone'
do
New Milestone
.milestones
...
...
@@ -19,4 +19,4 @@
%li
.nothing-here-block
No milestones to show
=
paginate
@milestones
,
theme:
"gitlab"
=
paginate
@milestones
,
theme:
'gitlab'
This diff is collapsed.
Click to expand it.
app/views/shared/_milestones_filter.html.haml
View file @
50a8f16e
-
if
@project
-
counts
=
milestone_counts
(
@project
.
milestones
)
%ul
.nav-links
%li
{
class:
milestone_class_for_state
(
params
[
:state
],
'opened'
,
true
)
}
>
=
link_to
milestones_filter_path
(
state:
'opened'
)
do
Open
-
if
@project
%span
.badge
=
counts
[
:opened
]
%li
{
class:
milestone_class_for_state
(
params
[
:state
],
'closed'
)
}
>
=
link_to
milestones_filter_path
(
state:
'closed'
)
do
Closed
-
if
@project
%span
.badge
=
counts
[
:closed
]
%li
{
class:
milestone_class_for_state
(
params
[
:state
],
'all'
)
}
>
=
link_to
milestones_filter_path
(
state:
'all'
)
do
All
-
if
@project
%span
.badge
=
counts
[
:all
]
This diff is collapsed.
Click to expand it.
changelogs/unreleased/24421-personal-milestone-count-badges.yml
0 → 100644
View file @
50a8f16e
---
title
:
Add dashboard and group milestones count badges
merge_request
:
9836
author
:
Alex Braha Stoll
This diff is collapsed.
Click to expand it.
spec/models/global_milestone_spec.rb
View file @
50a8f16e
...
...
@@ -92,6 +92,41 @@ describe GlobalMilestone, models: true do
end
end
describe
'.states_count'
do
context
'when the projects have milestones'
do
before
do
create
(
:closed_milestone
,
title:
'Active Group Milestone'
,
project:
project3
)
create
(
:active_milestone
,
title:
'Active Group Milestone'
,
project:
project1
)
create
(
:active_milestone
,
title:
'Active Group Milestone'
,
project:
project2
)
create
(
:closed_milestone
,
title:
'Closed Group Milestone'
,
project:
project1
)
create
(
:closed_milestone
,
title:
'Closed Group Milestone'
,
project:
project2
)
create
(
:closed_milestone
,
title:
'Closed Group Milestone'
,
project:
project3
)
end
it
'returns the quantity of global milestones in each possible state'
do
expected_count
=
{
opened:
1
,
closed:
2
,
all:
2
}
count
=
GlobalMilestone
.
states_count
(
Project
.
all
)
expect
(
count
).
to
eq
(
expected_count
)
end
end
context
'when the projects do not have milestones'
do
before
do
project1
end
it
'returns 0 as the quantity of global milestones in each state'
do
expected_count
=
{
opened:
0
,
closed:
0
,
all:
0
}
count
=
GlobalMilestone
.
states_count
(
Project
.
all
)
expect
(
count
).
to
eq
(
expected_count
)
end
end
end
describe
'#initialize'
do
let
(
:milestone1_project1
)
{
create
(
:milestone
,
title:
"Milestone v1.2"
,
project:
project1
)
}
let
(
:milestone1_project2
)
{
create
(
:milestone
,
title:
"Milestone v1.2"
,
project:
project2
)
}
...
...
@@ -127,4 +162,32 @@ describe GlobalMilestone, models: true do
expect
(
global_milestone
.
safe_title
).
to
eq
(
'git-test'
)
end
end
describe
'#state'
do
context
'when at least one milestone is active'
do
it
'returns active'
do
title
=
'Active Group Milestone'
milestones
=
[
create
(
:active_milestone
,
title:
title
),
create
(
:closed_milestone
,
title:
title
)
]
global_milestone
=
GlobalMilestone
.
new
(
title
,
milestones
)
expect
(
global_milestone
.
state
).
to
eq
(
'active'
)
end
end
context
'when all milestones are closed'
do
it
'returns closed'
do
title
=
'Closed Group Milestone'
milestones
=
[
create
(
:closed_milestone
,
title:
title
),
create
(
:closed_milestone
,
title:
title
)
]
global_milestone
=
GlobalMilestone
.
new
(
title
,
milestones
)
expect
(
global_milestone
.
state
).
to
eq
(
'closed'
)
end
end
end
end
This diff is collapsed.
Click to expand it.
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