Class: ResourceImportFilesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/resource_import_files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /resource_import_files POST /resource_import_files.json



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

def create
  @resource_import_file = ResourceImportFile.new(resource_import_file_params)
  @resource_import_file.user = current_user

  respond_to do |format|
    if @resource_import_file.save
      if @resource_import_file.mode == 'import'
        ResourceImportFileJob.perform_later(@resource_import_file)
      end
      format.html { redirect_to @resource_import_file, notice: t('import.successfully_created', model: t('activerecord.models.resource_import_file')) }
      format.json { render json: @resource_import_file, status: :created, location: @resource_import_file }
    else
      prepare_options
      format.html { render action: "new" }
      format.json { render json: @resource_import_file.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /resource_import_files/1 DELETE /resource_import_files/1.json



97
98
99
100
101
102
103
104
# File 'app/controllers/resource_import_files_controller.rb', line 97

def destroy
  @resource_import_file.destroy

  respond_to do |format|
    format.html { redirect_to resource_import_files_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.resource_import_file')) }
    format.json { head :no_content }
  end
end

#editObject

GET /resource_import_files/1/edit



53
54
# File 'app/controllers/resource_import_files_controller.rb', line 53

def edit
end

#indexObject

GET /resource_import_files GET /resource_import_files.json



8
9
10
11
12
13
14
15
# File 'app/controllers/resource_import_files_controller.rb', line 8

def index
  @resource_import_files = ResourceImportFile.page(params[:page])

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @resource_import_files }
  end
end

#newObject

GET /resource_import_files/new GET /resource_import_files/new.json



42
43
44
45
46
47
48
49
50
# File 'app/controllers/resource_import_files_controller.rb', line 42

def new
  @resource_import_file = ResourceImportFile.new
  @resource_import_file.library_id = current_user.profile.library_id

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @resource_import_file }
  end
end

#showObject

GET /resource_import_files/1 GET /resource_import_files/1.json



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/resource_import_files_controller.rb', line 19

def show
  if @resource_import_file.resource_import.path
    unless ENV['ENJU_STORAGE'] == 's3'
      file = @resource_import_file.resource_import.path
    end
  end
  @resource_import_results = @resource_import_file.resource_import_results.page(params[:page])

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @resource_import_file }
    format.download {
      if ENV['ENJU_STORAGE'] == 's3'
        redirect_to @resource_import_file.resource_import.expiring_url(10)
      else
        send_file file, filename: @resource_import_file.resource_import_file_name, type: 'application/octet-stream'
      end
    }
  end
end

#updateObject

PUT /resource_import_files/1 PUT /resource_import_files/1.json



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/resource_import_files_controller.rb', line 79

def update
  respond_to do |format|
    if @resource_import_file.update(resource_import_file_params)
      if @resource_import_file.mode == 'import'
        ResourceImportFileJob.perform_later(@resource_import_file)
      end
      format.html { redirect_to @resource_import_file, notice: t('controller.successfully_updated', model: t('activerecord.models.resource_import_file')) }
      format.json { head :no_content }
    else
      prepare_options
      format.html { render action: "edit" }
      format.json { render json: @resource_import_file.errors, status: :unprocessable_entity }
    end
  end
end