BigW Consortium Gitlab

todos_controller.rb 1.03 KB
Newer Older
1
class Dashboard::TodosController < Dashboard::ApplicationController
2
  before_action :find_todos, only: [:index, :destroy_all]
3

4
  def index
Felipe Artur committed
5
    @sort = params[:sort]
6
    @todos = @todos.page(params[:page])
7 8 9
  end

  def destroy
10
    TodoService.new.mark_todos_as_done_by_ids([params[:id]], current_user)
11 12

    respond_to do |format|
13
      format.html { redirect_to dashboard_todos_path, notice: 'Todo was successfully marked as done.' }
14
      format.js { head :ok }
15
      format.json { render json: todos_counts }
16 17 18
    end
  end

19
  def destroy_all
20
    TodoService.new.mark_todos_as_done(@todos, current_user)
21 22 23

    respond_to do |format|
      format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
24
      format.js { head :ok }
25
      format.json { render json: todos_counts }
26 27 28
    end
  end

29 30
  private

31
  def find_todos
32
    @todos ||= TodosFinder.new(current_user, params).execute
33
  end
34 35 36

  def todos_counts
    {
37 38
      count: current_user.todos_pending_count,
      done_count: current_user.todos_done_count
39 40
    }
  end
41
end