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 Creates a new Import object and redirects to import mappings if successful.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/admin/imports_controller.rb', line 58

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, status: :unprocessable_entity }
      format.json { render json: @import.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /imports/1 DELETE /imports/1.json Deletes an Import object and redirects to the imports list.



93
94
95
96
97
98
99
# File 'app/controllers/admin/imports_controller.rb', line 93

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 Prepares an existing Import object for editing.



52
53
# File 'app/controllers/admin/imports_controller.rb', line 52

def edit
end

#indexObject

GET /imports GET /imports.json Lists all imports with pagination.



32
33
34
# File 'app/controllers/admin/imports_controller.rb', line 32

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

#newObject

GET /imports/new Initializes a new Import object.



46
47
48
# File 'app/controllers/admin/imports_controller.rb', line 46

def new
  @import = Import.new
end

#runObject

Runs the import process and redirects to the import show page.



102
103
104
105
# File 'app/controllers/admin/imports_controller.rb', line 102

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 Displays a specific import and its associated documents, with pagination for success and failed states.



39
40
41
42
# File 'app/controllers/admin/imports_controller.rb', line 39

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

#updateObject

PATCH/PUT /imports/1 PATCH/PUT /imports/1.json Updates an existing Import object and redirects to the import if successful.



78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/admin/imports_controller.rb', line 78

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, status: :unprocessable_entity }
      format.json { render json: @import.errors, status: :unprocessable_entity }
    end
  end
end