Class: Dashboard::TodosController

Inherits:
ApplicationController
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper, Analytics::UniqueVisitsHelper, PaginatedCollection
Defined in:
app/controllers/dashboard/todos_controller.rb

Instance Method Summary collapse

Methods included from Analytics::UniqueVisitsHelper

#track_visit, #visitor_id

Instance Method Details

#bulk_restoreObject


52
53
54
55
56
# File 'app/controllers/dashboard/todos_controller.rb', line 52

def bulk_restore
  TodoService.new.restore_todos(current_user.todos.for_ids(params[:ids]), current_user)

  render json: todos_counts
end

#destroyObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/dashboard/todos_controller.rb', line 20

def destroy
  todo = current_user.todos.find(params[:id])

  TodoService.new.resolve_todo(todo, current_user, resolved_by_action: :mark_done)

  respond_to do |format|
    format.html do
      redirect_to dashboard_todos_path,
                  status: :found,
                  notice: _('To-do item successfully marked as done.')
    end
    format.js { head :ok }
    format.json { render json: todos_counts }
  end
end

#destroy_allObject


36
37
38
39
40
41
42
43
44
# File 'app/controllers/dashboard/todos_controller.rb', line 36

def destroy_all
  updated_ids = TodoService.new.resolve_todos(@todos, current_user, resolved_by_action: :mark_all_done)

  respond_to do |format|
    format.html { redirect_to dashboard_todos_path, status: :found, notice: _('Everything on your to-do list is marked as done.') }
    format.js { head :ok }
    format.json { render json: todos_counts.merge(updated_ids: updated_ids) }
  end
end

#indexObject


12
13
14
15
16
17
18
# File 'app/controllers/dashboard/todos_controller.rb', line 12

def index
  @sort = params[:sort]
  @todos = @todos.page(params[:page])
  @todos = @todos.with_entity_associations

  return if redirect_out_of_range(@todos, todos_page_count(@todos))
end

#restoreObject


46
47
48
49
50
# File 'app/controllers/dashboard/todos_controller.rb', line 46

def restore
  TodoService.new.restore_todo(current_user.todos.find(params[:id]), current_user)

  render json: todos_counts
end