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
d9e9035b
Commit
d9e9035b
authored
Oct 17, 2016
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved Issue CSV label lookup from view to model
parent
431d4b77
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
8 deletions
+20
-8
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+2
-0
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+7
-0
app/views/projects/issues/index.csv.ruby
app/views/projects/issues/index.csv.ruby
+1
-8
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+10
-0
No files found.
app/controllers/projects/issues_controller.rb
View file @
d9e9035b
...
@@ -37,6 +37,8 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -37,6 +37,8 @@ class Projects::IssuesController < Projects::ApplicationController
if
params
[
:label_name
].
present?
if
params
[
:label_name
].
present?
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
,
title:
params
[
:label_name
]).
execute
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
,
title:
params
[
:label_name
]).
execute
elsif
request
.
format
.
csv?
@labels
=
@issues
.
labels_hash
end
end
@users
=
[]
@users
=
[]
...
...
app/models/concerns/issuable.rb
View file @
d9e9035b
...
@@ -178,6 +178,13 @@ module Issuable
...
@@ -178,6 +178,13 @@ module Issuable
end
end
end
end
def
labels_hash
eager_load
(
:labels
).
pluck
(
:id
,
'labels.title'
).
inject
(
Hash
.
new
([]))
do
|
memo
,
(
issue_id
,
label
)
|
memo
[
issue_id
]
+=
[
label
]
memo
end
end
# Includes table keys in group by clause when sorting
# Includes table keys in group by clause when sorting
# preventing errors in postgres
# preventing errors in postgres
#
#
...
...
app/views/projects/issues/index.csv.ruby
View file @
d9e9035b
labels
=
@issues
.
eager_load
(
:labels
).
pluck
(
:id
,
'labels.title'
).
inject
(
Hash
.
new
([]))
do
|
memo
,
(
issue_id
,
label
)
|
memo
[
issue_id
]
+=
[
label
]
memo
end
columns
=
{
columns
=
{
'Issue ID'
=>
'iid'
,
'Issue ID'
=>
'iid'
,
'Title'
=>
'title'
,
'Title'
=>
'title'
,
...
@@ -17,7 +10,7 @@ columns = {
...
@@ -17,7 +10,7 @@ columns = {
'Created At (UTC)'
=>
->
(
issue
)
{
issue
.
created_at
&
.
to_s
(
:csv
)
},
'Created At (UTC)'
=>
->
(
issue
)
{
issue
.
created_at
&
.
to_s
(
:csv
)
},
'Updated At (UTC)'
=>
->
(
issue
)
{
issue
.
updated_at
&
.
to_s
(
:csv
)
},
'Updated At (UTC)'
=>
->
(
issue
)
{
issue
.
updated_at
&
.
to_s
(
:csv
)
},
'Milestone'
=>
->
(
issue
)
{
issue
.
milestone
&
.
title
},
'Milestone'
=>
->
(
issue
)
{
issue
.
milestone
&
.
title
},
'Labels'
=>
->
(
issue
)
{
labels
[
issue
.
id
].
sort
.
join
(
','
).
presence
}
'Labels'
=>
->
(
issue
)
{
@
labels
[
issue
.
id
].
sort
.
join
(
','
).
presence
}
}
}
CsvBuilder
.
new
(
@issues
.
includes
(
:author
,
:assignee
),
columns
).
render
CsvBuilder
.
new
(
@issues
.
includes
(
:author
,
:assignee
),
columns
).
render
spec/models/concerns/issuable_spec.rb
View file @
d9e9035b
...
@@ -331,6 +331,16 @@ describe Issue, "Issuable" do
...
@@ -331,6 +331,16 @@ describe Issue, "Issuable" do
end
end
end
end
describe
'.labels_hash'
do
let
(
:feature_label
)
{
create
(
:label
,
title:
'Feature'
)
}
let!
(
:issues
)
{
create_list
(
:labeled_issue
,
3
,
labels:
[
feature_label
])
}
it
'maps issue ids to labels titles'
do
issue_id
=
issues
.
first
.
id
expect
(
Issue
.
labels_hash
[
issue_id
]).
to
eq
[
'Feature'
]
end
end
describe
'#user_notes_count'
do
describe
'#user_notes_count'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:issue1
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue1
)
{
create
(
:issue
,
project:
project
)
}
...
...
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