summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-10-05 13:43:52 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-10-05 13:43:52 +0000
commitbf9bd0683d9184b33769954aad436f577967ee00 (patch)
treee48ffa1319259dc3659cd6c2aaeddb0ae350c7fe /app
parent5ae8e3787afa309d4e563a3c17804ede828f7a5a (diff)
parent063b9edc777e3df992e161c94572f4ff6ece9e02 (diff)
downloadgitlab-ce-bf9bd0683d9184b33769954aad436f577967ee00.tar.gz
Merge branch 'save-a-query-on-todos-with-no-filters' into 'master'
Save a query on the todos index page See merge request gitlab-org/gitlab-ce!14686
Diffstat (limited to 'app')
-rw-r--r--app/controllers/dashboard/todos_controller.rb30
1 files changed, 26 insertions, 4 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb
index a8b2b93b458..02c5857eea7 100644
--- a/app/controllers/dashboard/todos_controller.rb
+++ b/app/controllers/dashboard/todos_controller.rb
@@ -7,9 +7,8 @@ class Dashboard::TodosController < Dashboard::ApplicationController
def index
@sort = params[:sort]
@todos = @todos.page(params[:page])
- if @todos.out_of_range? && @todos.total_pages != 0
- redirect_to url_for(params.merge(page: @todos.total_pages, only_path: true))
- end
+
+ return if redirect_out_of_range(@todos)
end
def destroy
@@ -60,7 +59,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def find_todos
- @todos ||= TodosFinder.new(current_user, params).execute
+ @todos ||= TodosFinder.new(current_user, todo_params).execute
end
def todos_counts
@@ -69,4 +68,27 @@ class Dashboard::TodosController < Dashboard::ApplicationController
done_count: number_with_delimiter(current_user.todos_done_count)
}
end
+
+ def todo_params
+ params.permit(:action_id, :author_id, :project_id, :type, :sort, :state)
+ end
+
+ def redirect_out_of_range(todos)
+ total_pages =
+ if todo_params.except(:sort, :page).empty?
+ (current_user.todos_pending_count / 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(params.merge(page: total_pages, only_path: true))
+ end
+
+ out_of_range
+ end
end