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
ac060701
Commit
ac060701
authored
Feb 02, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use serializer to group environments into folders
parent
40a82435
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
app/serializers/environment_serializer.rb
app/serializers/environment_serializer.rb
+39
-0
No files found.
app/serializers/environment_serializer.rb
View file @
ac060701
class
EnvironmentSerializer
<
BaseSerializer
class
EnvironmentSerializer
<
BaseSerializer
Struct
.
new
(
'Item'
,
:name
,
:size
,
:id
,
:latest
)
entity
EnvironmentEntity
entity
EnvironmentEntity
def
with_folders
tap
{
@itemize
=
true
}
end
def
itemized?
@itemize
end
def
represent
(
resource
,
opts
=
{})
# resource = paginate(resource) if paginated?
if
itemized?
itemize
(
resource
).
map
do
|
item
|
{
name:
item
.
name
,
size:
item
.
size
,
latest:
super
(
item
.
latest
,
opts
)
}
end
else
super
(
resource
,
opts
)
end
end
private
def
itemize
(
resource
)
items
=
resource
.
group
(
:item_name
).
order
(
'item_name ASC'
)
.
pluck
(
'COALESCE(environment_type, name) AS item_name'
,
'COUNT(*) AS environments_count'
,
'MAX(id) AS last_environment_id'
)
environments
=
resource
.
where
(
id:
items
.
map
(
&
:last
))
items
.
zip
(
environments
).
map
do
|
item
|
Struct
::
Item
.
new
(
*
item
.
flatten
)
end
end
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