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
3f584b16
Commit
3f584b16
authored
Sep 27, 2018
by
Chantal Rollison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create labels_as_hash_ concern, modify params for method
parent
1e4a88d4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
53 deletions
+42
-53
app/controllers/concerns/labels_as_hash.rb
app/controllers/concerns/labels_as_hash.rb
+28
-0
app/services/projects/autocomplete_service.rb
app/services/projects/autocomplete_service.rb
+5
-24
ee/app/services/groups/autocomplete_service.rb
ee/app/services/groups/autocomplete_service.rb
+5
-25
ee/spec/services/groups/autocomplete_service_spec.rb
ee/spec/services/groups/autocomplete_service_spec.rb
+2
-2
spec/services/projects/autocomplete_service_spec.rb
spec/services/projects/autocomplete_service_spec.rb
+2
-2
No files found.
app/controllers/concerns/labels_as_hash.rb
0 → 100644
View file @
3f584b16
# frozen_string_literal: true
module
LabelsAsHash
extend
ActiveSupport
::
Concern
def
labels_as_hash
(
target
=
nil
,
params
=
{})
available_labels
=
LabelsFinder
.
new
(
current_user
,
params
).
execute
label_hashes
=
available_labels
.
as_json
(
only:
[
:title
,
:color
])
if
target
&
.
respond_to?
(
:labels
)
already_set_labels
=
available_labels
&
target
.
labels
if
already_set_labels
.
present?
titles
=
already_set_labels
.
map
(
&
:title
)
label_hashes
.
each
do
|
hash
|
if
titles
.
include?
(
hash
[
'title'
])
hash
[
:set
]
=
true
end
end
end
end
label_hashes
end
end
app/services/projects/autocomplete_service.rb
View file @
3f584b16
...
...
@@ -2,6 +2,7 @@
module
Projects
class
AutocompleteService
<
BaseService
include
LabelsAsHash
def
issues
IssuesFinder
.
new
(
current_user
,
project_id:
project
.
id
,
state:
'opened'
).
execute
.
select
([
:iid
,
:title
])
end
...
...
@@ -22,34 +23,14 @@ module Projects
MergeRequestsFinder
.
new
(
current_user
,
project_id:
project
.
id
,
state:
'opened'
).
execute
.
select
([
:iid
,
:title
])
end
def
labels_as_hash
(
target
=
nil
)
available_labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
project
.
id
,
include_ancestor_groups:
true
).
execute
label_hashes
=
available_labels
.
as_json
(
only:
[
:title
,
:color
])
if
target
&
.
respond_to?
(
:labels
)
already_set_labels
=
available_labels
&
target
.
labels
if
already_set_labels
.
present?
titles
=
already_set_labels
.
map
(
&
:title
)
label_hashes
.
each
do
|
hash
|
if
titles
.
include?
(
hash
[
'title'
])
hash
[
:set
]
=
true
end
end
end
end
label_hashes
end
def
commands
(
noteable
,
type
)
return
[]
unless
noteable
QuickActions
::
InterpretService
.
new
(
project
,
current_user
).
available_commands
(
noteable
)
end
def
labels_as_hash
(
target
)
super
(
target
,
project_id:
project
.
id
,
include_ancestor_groups:
true
)
end
end
end
ee/app/services/groups/autocomplete_service.rb
View file @
3f584b16
module
Groups
class
AutocompleteService
<
Groups
::
BaseService
def
labels_as_hash
(
target
=
nil
)
available_labels
=
LabelsFinder
.
new
(
current_user
,
group_id:
group
.
id
,
include_ancestor_groups:
true
,
only_group_labels:
true
).
execute
label_hashes
=
available_labels
.
as_json
(
only:
[
:title
,
:color
])
if
target
&
.
respond_to?
(
:labels
)
already_set_labels
=
available_labels
&
target
.
labels
if
already_set_labels
.
present?
titles
=
already_set_labels
.
map
(
&
:title
)
label_hashes
.
each
do
|
hash
|
if
titles
.
include?
(
hash
[
'title'
])
hash
[
:set
]
=
true
end
end
end
end
label_hashes
end
include
LabelsAsHash
def
epics
# TODO: change to EpicsFinder once frontend supports epics from external groups.
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/6837
...
...
@@ -36,5 +12,9 @@ module Groups
end
end
end
def
labels_as_hash
(
target
)
super
(
target
,
group_id:
group
.
id
,
only_group_labels:
true
)
end
end
end
ee/spec/services/groups/autocomplete_service_spec.rb
View file @
3f584b16
...
...
@@ -19,11 +19,11 @@ describe Groups::AutocompleteService do
let!
(
:label1
)
{
create
(
:group_label
,
group:
group
)
}
let!
(
:label2
)
{
create
(
:group_label
,
group:
group
)
}
let!
(
:sub_group_label
)
{
create
(
:group_label
,
group:
sub_group
)
}
let!
(
:parent_group_label
)
{
create
(
:group_label
,
group:
group
.
parent
)
}
let!
(
:parent_group_label
)
{
create
(
:group_label
,
group:
group
.
parent
,
group_id:
group
.
id
)
}
it
'returns labels from own group and ancestor groups'
do
service
=
described_class
.
new
(
group
,
user
)
results
=
service
.
labels_as_hash
results
=
service
.
labels_as_hash
(
nil
)
expected_labels
=
[
label1
,
label2
,
parent_group_label
]
expect_labels_to_equal
(
results
,
expected_labels
)
...
...
spec/services/projects/autocomplete_service_spec.rb
View file @
3f584b16
...
...
@@ -148,7 +148,7 @@ describe Projects::AutocompleteService do
let!
(
:label1
)
{
create
(
:label
,
project:
project
)
}
let!
(
:label2
)
{
create
(
:label
,
project:
project
)
}
let!
(
:sub_group_label
)
{
create
(
:group_label
,
group:
sub_group
)
}
let!
(
:parent_group_label
)
{
create
(
:group_label
,
group:
group
.
parent
)
}
let!
(
:parent_group_label
)
{
create
(
:group_label
,
group:
group
.
parent
,
group_id:
group
.
id
)
}
before
do
create
(
:group_member
,
group:
group
,
user:
user
)
...
...
@@ -156,7 +156,7 @@ describe Projects::AutocompleteService do
it
'returns labels from project and ancestor groups'
do
service
=
described_class
.
new
(
project
,
user
)
results
=
service
.
labels_as_hash
results
=
service
.
labels_as_hash
(
nil
)
expected_labels
=
[
label1
,
label2
,
parent_group_label
]
expect_labels_to_equal
(
results
,
expected_labels
)
...
...
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