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

45 lines
1 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, :destroy_all]
2016-02-20 14:53:25 -05:00
2016-02-20 08:59:59 -05:00
def index
@todos = @todos.page(params[:page])
2016-02-20 08:59:59 -05:00
end
def destroy
todo.done
2016-02-20 08:59:59 -05:00
todo_notice = 'Todo was successfully marked as done.'
2016-02-20 08:59:59 -05:00
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: todo_notice }
format.js { head :ok }
format.json do
render json: { count: @todos.size, done_count: current_user.todos.done.count }
end
2016-02-20 08:59:59 -05:00
end
end
2016-02-20 14:53:25 -05:00
def destroy_all
@todos.each(&:done)
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 }
2016-03-17 09:08:59 -04:00
format.json do
find_todos
render json: { count: @todos.size, done_count: current_user.todos.done.count }
end
2016-02-20 14:53:25 -05:00
end
end
2016-02-20 08:59:59 -05:00
private
def todo
@todo ||= current_user.todos.find(params[:id])
end
2016-02-20 14:53:25 -05:00
def find_todos
@todos = TodosFinder.new(current_user, params).execute
end
2016-02-20 08:59:59 -05:00
end