Class: Admin::ImportsController

Inherits:
AdminController show all
Defined in:
app/controllers/admin/imports_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /imports POST /imports.json



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

def create
  @import = Import.new(import_params)

  respond_to do |format|
    if @import.save
      format.html do
        redirect_to admin_import_mappings_path(@import),
          notice: "Import was successful. Please set your import mapping rules."
      end
      format.json { render :show, status: :created, location: @import }
    else
      format.html { render :new }
      format.json { render json: @import.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /imports/1 DELETE /imports/1.json



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

def destroy
  @import.destroy
  respond_to do |format|
    format.html { redirect_to admin_imports_url, notice: "Import was successfully destroyed." }
    format.json { head :no_content }
  end
end

#editObject

GET /imports/1/edit



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

def edit
end

#indexObject

GET /imports GET /imports.json



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

def index
  @pagy, @imports = pagy(Import.all.order("created_at DESC"), items: 20)
end

#newObject

GET /imports/new



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

def new
  @import = Import.new
end

#runObject



73
74
75
76
# File 'app/controllers/admin/imports_controller.rb', line 73

def run
  @import.run!
  redirect_to admin_import_url(@import), notice: "Import is running. Check back soon for results."
end

#showObject

GET /imports/1 GET /imports/1.json



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

def show
  @pagy_failed, @import_failed_documents = pagy(@import.import_documents.not_in_state(:success), items: 50)
  @pagy_success, @import_success_documents = pagy(@import.import_documents.in_state(:success), items: 50)
end

#updateObject

PATCH/PUT /imports/1 PATCH/PUT /imports/1.json



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

def update
  respond_to do |format|
    if @import.update(import_params)
      format.html { redirect_to admin_import_path(@import), notice: "Import was successfully updated." }
      format.json { render :show, status: :ok, location: @import }
    else
      format.html { render :edit }
      format.json { render json: @import.errors, status: :unprocessable_entity }
    end
  end
end