Class: ImportDatasetsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/import_datasets_controller.rb

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#createObject

POST /import_datasets POST /import_datasets.json



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/import_datasets_controller.rb', line 45

def create
  # TODO: Must not default to DwC-A dataset.
  @import_dataset = ImportDataset::DarwinCore.create_with_subtype_detection(import_dataset_params)

  respond_to do |format|
    if @import_dataset.save
      format.html { redirect_to @import_dataset.becomes(ImportDataset), notice: 'Import dataset was successfully created.' }
      format.json { render :show, status: :created, location: @import_dataset.becomes(ImportDataset) }
    else
      format.html { render :new }
      format.json { render json: @import_dataset.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /import_datasets/1 DELETE /import_datasets/1.json



76
77
78
79
80
81
82
83
84
# File 'app/controllers/import_datasets_controller.rb', line 76

def destroy
  ImportDataset.transaction do
    @import_dataset.destroy
  end
  respond_to do |format|
    format.html { redirect_to import_datasets_url, notice: 'Import dataset was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /import_datasets/1/edit



40
41
# File 'app/controllers/import_datasets_controller.rb', line 40

def edit
end

#importObject

POST /import_datasets/1/import.json



19
20
21
22
23
24
25
26
27
# File 'app/controllers/import_datasets_controller.rb', line 19

def import
  params.permit(:record_id, :retry_errored, filter: {})

  @results = @import_dataset.import(5000, 100,
    retry_errored: params[:retry_errored],
    filters: params[:filter],
    record_id: params[:record_id]
  )
end

#import_dataset_paramsObject (private)

Only allow a list of trusted parameters through.



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

def import_dataset_params
  params.require(:import_dataset).permit(
    :source,
    :description,
    import_settings: [
      :nomenclatural_code,
      :row_type
    ])
end

#indexObject

GET /import_datasets GET /import_datasets.json



8
9
10
11
# File 'app/controllers/import_datasets_controller.rb', line 8

def index
  @recent_objects = ImportDataset.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10).map { |i| i.becomes(ImportDataset) }
  render '/shared/data/all/index'
end

#listObject



86
87
88
# File 'app/controllers/import_datasets_controller.rb', line 86

def list
  @import_datasets = ImportDataset.with_project_id(sessions_current_project_id).order(:id).page(params[:page])
end

#newObject

GET /import_datasets/new



35
36
37
# File 'app/controllers/import_datasets_controller.rb', line 35

def new
  @import_dataset = ImportDataset.new
end

#set_import_datasetObject (private)

Use callbacks to share common setup or constraints between actions.



92
93
94
# File 'app/controllers/import_datasets_controller.rb', line 92

def set_import_dataset
  @import_dataset = ImportDataset.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /import_datasets/1 GET /import_datasets/1.json



15
16
# File 'app/controllers/import_datasets_controller.rb', line 15

def show
end

#stop_importObject

POST /import_datasets/1/stop_import.json



30
31
32
# File 'app/controllers/import_datasets_controller.rb', line 30

def stop_import
  @import_dataset.stop_import
end

#updateObject

PATCH/PUT /import_datasets/1 PATCH/PUT /import_datasets/1.json



62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/import_datasets_controller.rb', line 62

def update
  respond_to do |format|
    if @import_dataset.update(import_dataset_params)
      format.html { redirect_to @import_dataset.becomes(ImportDataset), notice: 'Import dataset was successfully updated.' }
      format.json { render :show, status: :ok, location: @import_dataset.becomes(ImportDataset) }
    else
      format.html { render :edit }
      format.json { render json: @import_dataset.errors, status: :unprocessable_entity }
    end
  end
end