2016-02-20 08:59:59 -05:00
|
|
|
class Dashboard::TodosController < Dashboard::ApplicationController
|
2016-02-21 10:52:37 -05:00
|
|
|
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
|
|
|
|
@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 14:53:25 -05:00
|
|
|
def destroy_all
|
2016-02-22 14:53:07 -05:00
|
|
|
@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 { render nothing: true }
|
|
|
|
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
|