gitlab-org--gitlab-foss/app/controllers/dashboard/todos_controller.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

2016-02-20 08:59:59 -05:00
class Dashboard::TodosController < Dashboard::ApplicationController
before_action :find_todos, only: [:index, :destroy_all]
2016-02-20 14:53:25 -05:00
2016-02-20 08:59:59 -05:00
def index
2016-07-26 17:21:20 -04:00
@sort = params[:sort]
2016-12-20 13:52:09 -05:00
@todos = @todos.page(params[:page])
if @todos.out_of_range? && @todos.total_pages != 0
redirect_to dashboard_todos_path(page: @todos.total_pages)
end
2016-02-20 08:59:59 -05:00
end
def destroy
TodoService.new.mark_todos_as_done_by_ids([params[:id]], current_user)
2016-02-20 08:59:59 -05:00
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
format.js { head :ok }
format.json { render json: todos_counts }
2016-02-20 08:59:59 -05:00
end
end
2016-02-20 14:53:25 -05:00
def destroy_all
TodoService.new.mark_todos_as_done(@todos, current_user)
2016-02-20 14:53:25 -05:00
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
format.js { head :ok }
format.json { render json: todos_counts }
2016-02-20 14:53:25 -05:00
end
end
2016-02-20 08:59:59 -05:00
private
2016-02-20 14:53:25 -05:00
def find_todos
@todos ||= TodosFinder.new(current_user, params).execute
2016-02-20 14:53:25 -05:00
end
def todos_counts
{
count: current_user.todos_pending_count,
done_count: current_user.todos_done_count
}
end
2016-02-20 08:59:59 -05:00
end