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
d5a595b5
Commit
d5a595b5
authored
Sep 19, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add LabelsFinder
parent
52e0c3b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
app/finders/labels_finder.rb
app/finders/labels_finder.rb
+58
-0
No files found.
app/finders/labels_finder.rb
0 → 100644
View file @
d5a595b5
class
LabelsFinder
def
initialize
(
current_user
,
params
=
{})
@current_user
=
current_user
@params
=
params
end
def
execute
items
=
init_collection
items
=
with_title
(
items
)
sort
(
items
)
end
private
attr_reader
:current_user
,
:params
def
init_collection
label_ids
=
[]
label_ids
<<
Label
.
where
(
group_id:
projects
.
where
.
not
(
group:
nil
).
select
(
:namespace_id
)).
select
(
:id
)
label_ids
<<
Label
.
where
(
project_id:
projects
).
select
(
:id
)
union
=
Gitlab
::
SQL
::
Union
.
new
(
label_ids
)
Label
.
where
(
"labels.id IN (
#{
union
.
to_sql
}
)"
)
.
reorder
(
title: :asc
)
end
def
with_title
(
items
)
items
=
items
.
where
(
title:
title
)
if
title
.
present?
items
end
def
sort
(
items
)
items
.
reorder
(
title: :asc
)
end
def
project_id
params
[
:project_id
].
presence
end
def
title
params
[
:title
].
presence
end
def
projects
return
@projects
if
defined?
(
@projects
)
if
project_id
@projects
=
ProjectsFinder
.
new
.
execute
(
current_user
)
.
where
(
id:
project_id
)
.
reorder
(
nil
)
else
@projects
=
Project
.
none
end
@projects
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