2016-02-20 08:59:59 -05:00
|
|
|
class Dashboard::TodosController < Dashboard::ApplicationController
|
2016-06-14 22:09:48 -04: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
|
2016-07-26 17:21:20 -04:00
|
|
|
@sort = params[:sort]
|
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-08-17 15:54:31 -04:00
|
|
|
TodoService.new.mark_todos_as_done_by_ids([params[:id]], current_user)
|
2016-02-20 08:59:59 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
2016-06-14 22:09:48 -04:00
|
|
|
format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
|
2016-03-15 21:16:25 -04:00
|
|
|
format.js { head :ok }
|
2016-07-11 02:10:04 -04:00
|
|
|
format.json { render json: todos_counts }
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 14:53:25 -05:00
|
|
|
def destroy_all
|
2016-06-02 09:46:58 -04:00
|
|
|
TodoService.new.mark_todos_as_done(@todos, current_user)
|
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-07-11 02:10:04 -04:00
|
|
|
format.json { render json: todos_counts }
|
2016-02-20 14:53:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
private
|
|
|
|
|
2016-02-20 14:53:25 -05:00
|
|
|
def find_todos
|
2016-06-14 22:09:48 -04:00
|
|
|
@todos ||= TodosFinder.new(current_user, params).execute
|
2016-02-20 14:53:25 -05:00
|
|
|
end
|
2016-07-11 02:10:04 -04:00
|
|
|
|
|
|
|
def todos_counts
|
|
|
|
{
|
2016-08-11 12:39:50 -04:00
|
|
|
count: current_user.todos_pending_count,
|
|
|
|
done_count: current_user.todos_done_count
|
2016-07-11 02:10:04 -04:00
|
|
|
}
|
|
|
|
end
|
2016-02-20 08:59:59 -05:00
|
|
|
end
|