gitlab-org--gitlab-foss/app/controllers/dashboard/todos_controller.rb

41 lines
928 B
Ruby
Raw Normal View History

2016-02-20 08:59:59 -05:00
class Dashboard::TodosController < Dashboard::ApplicationController
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!
todo_notice = 'Todo was successfully marked as done.'
2016-02-20 08:59:59 -05:00
respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: todo_notice }
2016-02-20 08:59:59 -05:00
format.js { render nothing: true }
format.json do
render json: { status: 'OK', notice: todo_notice }
end
2016-02-20 08:59:59 -05:00
end
end
2016-02-20 14:53:25 -05:00
def destroy_all
@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