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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
aa04757a
Commit
aa04757a
authored
Apr 04, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code improvements on burndown model and view partial
parent
47ce88a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
18 deletions
+18
-18
app/models/burndown.rb
app/models/burndown.rb
+12
-12
app/views/shared/milestones/_burndown.html.haml
app/views/shared/milestones/_burndown.html.haml
+1
-1
spec/models/burndown_spec.rb
spec/models/burndown_spec.rb
+5
-5
No files found.
app/models/burndown.rb
View file @
aa04757a
...
...
@@ -7,15 +7,12 @@ class Burndown
@end_date
=
@milestone
.
due_date
@end_date
=
Date
.
today
if
@end_date
.
present?
&&
@end_date
>
Date
.
today
milestone_issues
=
@milestone
.
issues
@issues_count
=
milestone_issues
.
count
@issues_weight
=
milestone_issues
.
sum
(
:weight
)
@issues_count
,
@issues_weight
=
milestone
.
issues
.
reorder
(
nil
).
pluck
(
'COUNT(*), COALESCE(SUM(weight), 0)'
).
first
end
# Returns the chart data in the following format:
# [date, issue count, issue weight] eg: [["2017-03-01", 33, 127], ["2017-03-02", 35, 73], ["2017-03-03", 28, 50]...]
def
chart_data
def
as_json
(
opts
=
nil
)
return
[]
unless
valid?
open_issues_count
=
issues_count
...
...
@@ -27,7 +24,10 @@ class Burndown
closed_issues_count
=
closed
.
count
closed_issues_weight
=
sum_issues_weight
(
closed
)
chart_data
<<
[
date
.
strftime
(
"%Y-%m-%d"
),
open_issues_count
-=
closed_issues_count
,
open_issues_weight
-=
closed_issues_weight
]
open_issues_count
-=
closed_issues_count
open_issues_weight
-=
closed_issues_weight
chart_data
<<
[
date
.
strftime
(
"%Y-%m-%d"
),
open_issues_count
,
open_issues_weight
]
reopened_count
=
reopened
.
count
reopened_weight
=
sum_issues_weight
(
reopened
)
...
...
@@ -44,22 +44,22 @@ class Burndown
private
def
sum_issues_weight
(
issues
)
issues
.
map
(
&
:weight
).
compact
.
reduce
(:
+
)
||
0
issues
.
map
(
&
:weight
).
sum
end
def
closed_and_reopened_issues_by
(
date
)
current_date
=
date
.
beginning_of_day
current_date
=
date
.
to_date
closed
=
issues_with_closed_at
.
select
{
|
issue
|
issue
.
closed_at
.
beginning_of_day
.
to_i
==
current_date
.
to_i
}
closed
=
issues_with_closed_at
.
select
{
|
issue
|
issue
.
closed_at
.
to_date
==
current_date
}
reopened
=
closed
.
select
{
|
issue
|
issue
.
state
==
'reopened'
}
return
closed
,
reopened
end
def
issues_with_closed_at
@issues
||=
@issues
_with_closed_at
||=
@milestone
.
issues
.
select
(
'closed_at, weight, state'
).
where
(
'closed_at IS NOT NULL'
).
order
(
'closed_at ASC'
)
where
(
'closed_at IS NOT NULL'
).
order
(
'closed_at ASC'
)
end
end
app/views/shared/milestones/_burndown.html.haml
View file @
aa04757a
...
...
@@ -16,7 +16,7 @@
Issues
%button
.btn.btn-xs
{
data:
{
show:
'weight'
}
}
Issue weight
.burndown-chart
{
data:
{
start_date:
milestone
.
start_date
.
strftime
(
"%Y-%m-%d"
),
due_date:
milestone
.
due_date
.
strftime
(
"%Y-%m-%d"
),
chart_data:
burndown
.
chart_data
.
to_json
}
}
.burndown-chart
{
data:
{
start_date:
burndown
.
start_date
.
strftime
(
"%Y-%m-%d"
),
due_date:
burndown
.
end_date
.
strftime
(
"%Y-%m-%d"
),
chart_data:
burndown
.
to_json
}
}
-
elsif
can?
(
current_user
,
:admin_milestone
,
@project
)
&&
cookies
[
'hide_burndown_message'
].
nil?
.burndown-hint.content-block.container-fluid
...
...
spec/models/burndown_spec.rb
View file @
aa04757a
...
...
@@ -27,7 +27,7 @@ describe Burndown, models: true do
Timecop
.
return
end
subject
{
described_class
.
new
(
milestone
).
chart_data
}
subject
{
described_class
.
new
(
milestone
).
to_json
}
it
"generates an array with date, issue count and weight"
do
expect
(
subject
).
to
eq
([
...
...
@@ -36,25 +36,25 @@ describe Burndown, models: true do
[
"2017-03-03"
,
28
,
56
],
[
"2017-03-04"
,
32
,
64
],
[
"2017-03-05"
,
21
,
42
]
])
]
.
to_json
)
end
it
"returns empty array if milestone start date is nil"
do
milestone
.
update
(
start_date:
nil
)
expect
(
subject
).
to
eq
([])
expect
(
subject
).
to
eq
([]
.
to_json
)
end
it
"returns empty array if milestone due date is nil"
do
milestone
.
update
(
due_date:
nil
)
expect
(
subject
).
to
eq
([])
expect
(
subject
).
to
eq
([]
.
to_json
)
end
it
"it counts until today if milestone due date > Date.today"
do
Timecop
.
travel
(
milestone
.
due_date
-
1
.
day
)
expect
(
subject
.
last
[
0
]).
to
eq
(
Time
.
now
.
strftime
(
"%Y-%m-%d"
))
expect
(
JSON
.
parse
(
subject
)
.
last
[
0
]).
to
eq
(
Time
.
now
.
strftime
(
"%Y-%m-%d"
))
end
# Creates, closes and reopens issues only for odd days numbers
...
...
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