Class: Admin::BulkActionsController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/bulk_actions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /bulk_actions POST /bulk_actions.json



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/admin/bulk_actions_controller.rb', line 32

def create
  @bulk_action = BulkAction.new(bulk_action_params)

  respond_to do |format|
    if @bulk_action.save
      format.html do
        redirect_to admin_bulk_action_path(@bulk_action), notice: "Bulk action was successfully created."
      end
      format.json { render :show, status: :created, location: @bulk_action }
    else
      format.html { render :new }
      format.json { render json: @bulk_action.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /bulk_actions/1 DELETE /bulk_actions/1.json



66
67
68
69
70
71
72
# File 'app/controllers/admin/bulk_actions_controller.rb', line 66

def destroy
  @bulk_action.destroy
  respond_to do |format|
    format.html { redirect_to admin_bulk_actions_url, notice: "Bulk action was successfully destroyed." }
    format.json { head :no_content }
  end
end

#editObject

GET /bulk_actions/1/edit



27
28
# File 'app/controllers/admin/bulk_actions_controller.rb', line 27

def edit
end

#indexObject

GET /bulk_actions GET /bulk_actions.json



10
11
12
# File 'app/controllers/admin/bulk_actions_controller.rb', line 10

def index
  @pagy, @bulk_actions = pagy(BulkAction.all.order(created_at: :desc), items: 20)
end

#newObject

GET /bulk_actions/new



22
23
24
# File 'app/controllers/admin/bulk_actions_controller.rb', line 22

def new
  @bulk_action = BulkAction.new(scope: params[:scope])
end

#revertObject



80
81
82
83
84
85
# File 'app/controllers/admin/bulk_actions_controller.rb', line 80

def revert
  @bulk_action.revert!
  @bulk_action.state_machine.transition_to!(:queued)
  redirect_to admin_bulk_action_url(@bulk_action),
    notice: "Revert bulk action is running. Check back soon for results."
end

#runObject



74
75
76
77
78
# File 'app/controllers/admin/bulk_actions_controller.rb', line 74

def run
  @bulk_action.run!
  # @bulk_action.state_machine.transition_to!(:queued)
  redirect_to admin_bulk_action_url(@bulk_action), notice: "Bulk action is running. Check back soon for results."
end

#showObject

GET /bulk_actions/1 GET /bulk_actions/1.json



16
17
18
19
# File 'app/controllers/admin/bulk_actions_controller.rb', line 16

def show
  @pagy, @documents = pagy(@bulk_action.documents, items: 30)
  @bulk_action.check_run_state
end

#updateObject

PATCH/PUT /bulk_actions/1 PATCH/PUT /bulk_actions/1.json



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/admin/bulk_actions_controller.rb', line 50

def update
  respond_to do |format|
    if @bulk_action.update(bulk_action_params)
      format.html do
        redirect_to admin_bulk_action_path(@bulk_action), notice: "Bulk action was successfully updated."
      end
      format.json { render :show, status: :ok, location: @bulk_action }
    else
      format.html { render :edit }
      format.json { render json: @bulk_action.errors, status: :unprocessable_entity }
    end
  end
end