gitlab-org--gitlab-foss/app/controllers/dashboard/todos_controller.rb
Jacob Schatz fa570525db Adds small AJAX optimistic functionality to todos.
Fixes #13656
A good first step and boring solution.
2016-03-17 12:20:14 +00:00

40 lines
928 B
Ruby

class Dashboard::TodosController < Dashboard::ApplicationController
before_action :find_todos, only: [:index, :destroy_all]
def index
@todos = @todos.page(params[:page]).per(PER_PAGE)
end
def destroy
todo.done!
todo_notice = 'Todo was successfully marked as done.'
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: todo_notice }
format.js { render nothing: true }
format.json do
render json: { status: 'OK', notice: todo_notice }
end
end
end
def destroy_all
@todos.each(&:done!)
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
private
def todo
@todo ||= current_user.todos.find(params[:id])
end
def find_todos
@todos = TodosFinder.new(current_user, params).execute
end
end