BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
environment_serializer.rb
app/serializers/environment_serializer.rb
+39
-0
No files found.
app/serializers/environment_serializer.rb
View file @
ac060701
class
EnvironmentSerializer
<
BaseSerializer
Struct
.
new
(
'Item'
,
:name
,
:size
,
:id
,
:latest
)
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
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