2016-04-02 18:10:28 +05:30
|
|
|
class Dashboard::TodosController < Dashboard::ApplicationController
|
2016-06-22 15:30:34 +05:30
|
|
|
include TodosHelper
|
|
|
|
|
|
|
|
before_action :find_todos, only: [:index, :destroy_all]
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
def index
|
2016-06-02 11:05:42 +05:30
|
|
|
@todos = @todos.page(params[:page])
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2016-06-22 15:30:34 +05:30
|
|
|
TodoService.new.mark_todos_as_done([todo], current_user)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
2016-06-22 15:30:34 +05:30
|
|
|
format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
|
2016-06-02 11:05:42 +05:30
|
|
|
format.js { head :ok }
|
2016-06-22 15:30:34 +05:30
|
|
|
format.json { render json: { count: todos_pending_count, done_count: todos_done_count } }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_all
|
2016-06-22 15:30:34 +05:30
|
|
|
TodoService.new.mark_todos_as_done(@todos, current_user)
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
|
2016-06-02 11:05:42 +05:30
|
|
|
format.js { head :ok }
|
2016-06-22 15:30:34 +05:30
|
|
|
format.json { render json: { count: todos_pending_count, done_count: todos_done_count } }
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def todo
|
2016-06-22 15:30:34 +05:30
|
|
|
@todo ||= find_todos.find(params[:id])
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def find_todos
|
2016-06-22 15:30:34 +05:30
|
|
|
@todos ||= TodosFinder.new(current_user, params).execute
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|