diff options
author | Markus Koller <mkoller@gitlab.com> | 2019-09-03 19:45:00 +0200 |
---|---|---|
committer | Markus Koller <mkoller@gitlab.com> | 2019-09-10 15:24:29 +0200 |
commit | f1926b321deb8b922dead991fb4d8bea42699f9f (patch) | |
tree | 7dfb7b613152cc6282b1f169e781f11f736de36a /app/controllers/dashboard/todos_controller.rb | |
parent | 60755fbc406bd25ab526339899f97a2b27aeb272 (diff) | |
download | gitlab-ce-f1926b321deb8b922dead991fb4d8bea42699f9f.tar.gz |
Add controller concern for paginated collections65988-optimize-snippet-listings
We had similar code in a few places to redirect to the last page if
the given page number is out of range. This unifies the handling in a
new controller concern and adds usage of it in all snippet listings.
Diffstat (limited to 'app/controllers/dashboard/todos_controller.rb')
-rw-r--r-- | app/controllers/dashboard/todos_controller.rb | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index 8f6fcb362d2..940d1482611 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -2,6 +2,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController include ActionView::Helpers::NumberHelper + include PaginatedCollection before_action :authorize_read_project!, only: :index before_action :authorize_read_group!, only: :index @@ -12,7 +13,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController @todos = @todos.page(params[:page]) @todos = @todos.with_entity_associations - return if redirect_out_of_range(@todos) + return if redirect_out_of_range(@todos, todos_page_count(@todos)) end def destroy @@ -82,28 +83,15 @@ class Dashboard::TodosController < Dashboard::ApplicationController } end - def todo_params - params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id) - end - - # rubocop: disable CodeReuse/ActiveRecord - def redirect_out_of_range(todos) - total_pages = - if todo_params.except(:sort, :page).empty? - (current_user.todos_pending_count.to_f / todos.limit_value).ceil - else - todos.total_pages - end - - return false if total_pages.zero? - - out_of_range = todos.current_page > total_pages - - if out_of_range - redirect_to url_for(safe_params.merge(page: total_pages, only_path: true)) + def todos_page_count(todos) + if todo_params.except(:sort, :page).empty? # rubocop: disable CodeReuse/ActiveRecord + (current_user.todos_pending_count.to_f / todos.limit_value).ceil + else + todos.total_pages end + end - out_of_range + def todo_params + params.permit(:action_id, :author_id, :project_id, :type, :sort, :state, :group_id) end - # rubocop: enable CodeReuse/ActiveRecord end |