2016-02-20 13:59:59 +00:00
|
|
|
class Dashboard::TodosController < Dashboard::ApplicationController
|
2016-02-21 15:52:37 +00:00
|
|
|
before_action :find_todos, only: [:index, :destroy_all]
|
2016-02-20 19:53:25 +00:00
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
def index
|
|
|
|
@todos = @todos.page(params[:page]).per(PER_PAGE)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
todo.done!
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
|
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 19:53:25 +00:00
|
|
|
def destroy_all
|
2016-02-22 19:53:07 +00:00
|
|
|
@todos.each(&:done!)
|
2016-02-20 19:53:25 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
|
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 13:59:59 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def todo
|
|
|
|
@todo ||= current_user.todos.find(params[:id])
|
|
|
|
end
|
2016-02-20 19:53:25 +00:00
|
|
|
|
|
|
|
def find_todos
|
|
|
|
@todos = TodosFinder.new(current_user, params).execute
|
|
|
|
end
|
2016-02-20 13:59:59 +00:00
|
|
|
end
|