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
cc1d1411
Commit
cc1d1411
authored
Apr 25, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and extract DefaultPaginationStrategy.
parent
7e78eacd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
pagination.rb
lib/api/helpers/pagination.rb
+21
-8
pagination.rb
lib/gitlab/serializer/pagination.rb
+0
-2
No files found.
lib/api/helpers/pagination.rb
View file @
cc1d1411
...
@@ -2,6 +2,18 @@ module API
...
@@ -2,6 +2,18 @@ module API
module
Helpers
module
Helpers
module
Pagination
module
Pagination
def
paginate
(
relation
)
def
paginate
(
relation
)
DefaultPaginationStrategy
.
new
(
self
).
paginate
(
relation
)
end
class
DefaultPaginationStrategy
attr_reader
:ctx
delegate
:params
,
:header
,
:request
,
to: :ctx
def
initialize
(
ctx
)
@ctx
=
ctx
end
def
paginate
(
relation
)
relation
=
add_default_order
(
relation
)
relation
=
add_default_order
(
relation
)
relation
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
]).
tap
do
|
data
|
relation
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
]).
tap
do
|
data
|
...
@@ -11,6 +23,14 @@ module API
...
@@ -11,6 +23,14 @@ module API
private
private
def
add_default_order
(
relation
)
if
relation
.
is_a?
(
ActiveRecord
::
Relation
)
&&
relation
.
order_values
.
empty?
relation
=
relation
.
order
(
:id
)
end
relation
end
def
add_pagination_headers
(
paginated_data
)
def
add_pagination_headers
(
paginated_data
)
header
'X-Per-Page'
,
paginated_data
.
limit_value
.
to_s
header
'X-Per-Page'
,
paginated_data
.
limit_value
.
to_s
header
'X-Page'
,
paginated_data
.
current_page
.
to_s
header
'X-Page'
,
paginated_data
.
current_page
.
to_s
...
@@ -53,17 +73,10 @@ module API
...
@@ -53,17 +73,10 @@ module API
[
paginated_data
.
total_pages
,
1
].
max
[
paginated_data
.
total_pages
,
1
].
max
end
end
def
add_default_order
(
relation
)
if
relation
.
is_a?
(
ActiveRecord
::
Relation
)
&&
relation
.
order_values
.
empty?
relation
=
relation
.
order
(
:id
)
end
relation
end
def
data_without_counts?
(
paginated_data
)
def
data_without_counts?
(
paginated_data
)
paginated_data
.
is_a?
(
Kaminari
::
PaginatableWithoutCount
)
paginated_data
.
is_a?
(
Kaminari
::
PaginatableWithoutCount
)
end
end
end
end
end
end
end
end
end
lib/gitlab/serializer/pagination.rb
View file @
cc1d1411
...
@@ -17,8 +17,6 @@ module Gitlab
...
@@ -17,8 +17,6 @@ module Gitlab
end
end
end
end
private
# Methods needed by `API::Helpers::Pagination`
# Methods needed by `API::Helpers::Pagination`
#
#
...
...
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