2016-02-20 08:59:59 -05:00
|
|
|
class Dashboard::TodosController < Dashboard::ApplicationController
|
2016-03-17 08:54:02 -04:00
|
|
|
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
|
2016-03-19 17:37:54 -04:00
|
|
|
@todos = @todos.page(params[:page])
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2016-03-16 19:56:23 -04:00
|
|
|
todo.done
|
2016-02-20 08:59:59 -05:00
|
|
|
|
2016-02-23 15:09:35 -05:00
|
|
|
todo_notice = 'Todo was successfully marked as done.'
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
respond_to do |format|
|
2016-02-23 15:09:35 -05:00
|
|
|
format.html { redirect_to dashboard_todos_path, notice: todo_notice }
|
2016-03-15 21:16:25 -04:00
|
|
|
format.js { head :ok }
|
2016-02-23 15:09:35 -05:00
|
|
|
format.json do
|
2016-03-17 08:54:02 -04:00
|
|
|
render json: { count: @todos.size, done_count: current_user.todos.done.count }
|
2016-02-23 15:09:35 -05:00
|
|
|
end
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 14:53:25 -05:00
|
|
|
def destroy_all
|
2016-03-16 19:56:23 -04: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.' }
|
2016-03-15 21:16:25 -04:00
|
|
|
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
|