Skip to content

Commit

Permalink
Merge pull request #3279 from DMPRoadmap/pagination-fix
Browse files Browse the repository at this point in the history
fix to properly use max per page settings
  • Loading branch information
benjaminfaure authored Jan 27, 2023
2 parents 68ac8a7 + 66b628c commit 00459b6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

- Added CHANGELOG.md and Danger Github Action [#3257](https://github.com/DMPRoadmap/roadmap/issues/3257)
- Added validation with custom error message in research_output.rb to ensure a user does not enter a very large value as 'Anticipated file size'. [#3161](https://github.com/DMPRoadmap/roadmap/issues/3161)
- Added popover for org profile page and added explanation for public plan
- Added popover for org profile page and added explanation for public plan
### Fixed

- Fixed discrepencies with default/max per_page values for API and UI pagination
- Updated JS that used to call the TinyMCE `setMode()` function so that it now calls `mode.set()` because the former is now deprecated.

### Changed
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/api/v0/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def index
plan_ids = extract_param_list(params, 'plan')
@plans = @plans.where(id: plan_ids) if plan_ids.present?
# apply pagination after filtering
@args = { per_page: params[:per_page], page: params[:page] }
max_per_page = Rails.configuration.x.application.api_max_page_size
page = params.fetch('page', 1).to_i
per_page = params.fetch('per_page', max_per_page).to_i
per_page = max_per_page if @per_page > max_per_page
@args = { per_page: per_page, page: page }
@plans = refine_query(@plans)
respond_with @plans
end
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/api/v1/base_api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ def base_response_content
# Retrieve the requested pagination params or use defaults
# only allow 100 per page as the max
def pagination_params
max_per_page = Rails.configuration.x.application.api_max_page_size
@page = params.fetch('page', 1).to_i
@per_page = params.fetch('per_page', 20).to_i
@per_page = 100 if @per_page > 100
@per_page = params.fetch('per_page', max_per_page).to_i
@per_page = max_per_page if @per_page > max_per_page
end

# Parse the body of the incoming request
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/paginable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def refine_query(scope)
if @args[:page] != 'ALL'
# Can raise error if page is not a number
scope = scope.page(@args[:page])
.per(@args.fetch(:per_page, Rails.configuration.x.application.api_max_page_size))
.per(@args.fetch(:per_page, Rails.configuration.x.results_per_page))
end
scope
end
Expand Down

0 comments on commit 00459b6

Please sign in to comment.