Class: ImportDatasetsController

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

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

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

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

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



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

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



80
81
82
83
84
85
86
87
88
# File 'app/controllers/import_datasets_controller.rb', line 80

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



44
45
# File 'app/controllers/import_datasets_controller.rb', line 44

def edit
end

#importObject

POST /import_datasets/1/import.json



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

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

  @filters = params[: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)



99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/import_datasets_controller.rb', line 99

def import_dataset_params
  params.require(:import_dataset).permit(
    :source,
    :description,
    import_settings: [
      :nomenclatural_code,
      :row_type,
      :col_sep,
      :quote_char
    ])
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



90
91
92
# File 'app/controllers/import_datasets_controller.rb', line 90

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

#newObject

GET /import_datasets/new



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

def new
  @import_dataset = ImportDataset.new
end

#set_import_datasetObject (private)



95
96
97
# File 'app/controllers/import_datasets_controller.rb', line 95

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



31
32
33
34
35
36
# File 'app/controllers/import_datasets_controller.rb', line 31

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

  @filters = params[:filter]
  @import_dataset.stop_import
end

#updateObject

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



66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/import_datasets_controller.rb', line 66

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