Class: OtusController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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

Instance Method Details

#autocompleteObject



111
112
113
# File 'app/controllers/otus_controller.rb', line 111

def autocomplete
  @otus = Queries::Otu::Autocomplete.new(params.require(:term), project_id: sessions_current_project_id).autocomplete
end

#batch_loadObject



115
116
117
# File 'app/controllers/otus_controller.rb', line 115

def batch_load
  # see app/views/otus/batch_load.html.erb
end

#batch_paramsObject (private)



251
252
253
254
255
256
257
258
259
260
261
# File 'app/controllers/otus_controller.rb', line 251

def batch_params
  params.permit(
    :name, :file, :import_level,
    :create_new_otu, :source_id, :type_select, :create_new_predicate,
    files: [])
    .merge(
      user_id: sessions_current_user_id,
      project_id: sessions_current_project_id)
    .to_h
    .symbolize_keys
end

#by_nameObject

GET api/v1/otus/by_name/:name?token=:token&project_id=:id



230
231
232
233
# File 'app/controllers/otus_controller.rb', line 230

def by_name
  @otu_name = params.require(:name)
  @otu_ids  = Queries::Otu::Autocomplete.new(@otu_name, project_id: params.require(:project_id)).all.pluck(:id)
end

#collection_objectsObject

GET /api/v1/otus/1/collection_objects



98
99
100
# File 'app/controllers/otus_controller.rb', line 98

def collection_objects
  @collection_objects = Otu.find(params[:id]).collection_objects.pluck(:id)
end

#createObject

POST /otus POST /otus.json



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

def create
  @otu = Otu.new(otu_params)

  respond_to do |format|
    if @otu.save
      format.html { redirect_to @otu,
                    notice: "Otu '#{@otu.name}' was successfully created." }
      format.json { render action: :show, status: :created, location: @otu }
    else
      format.html { render action: 'new' }
      format.json { render json: @otu.errors, status: :unprocessable_entity }
    end
  end
end

#create_data_attributes_batch_loadObject

TODO: AUTOGENERATED STUB, check and update



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'app/controllers/otus_controller.rb', line 207

def create_data_attributes_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :data_attributes_batch_load_otus_md5)
    @result = BatchLoad::Import::Otus::DataAttributesInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} TODO RECORD TYPES were created."
      render 'otus/batch_load/data_attributes/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :batch_load
end

#create_identifiers_batch_loadObject



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/controllers/otus_controller.rb', line 154

def create_identifiers_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :batch_load_otus_identifiers_md5)
    @result = BatchLoad::Import::Otus::IdentifiersInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully processed file, #{@result.total_records_created} otus were created."
      render('otus/batch_load/identifiers/create')
      return
    else
      flash[:alert] = 'Batch import failed.'
    end
    render(:batch_load)
  end
end

#create_simple_batch_file_loadObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'app/controllers/otus_controller.rb', line 179

def create_simple_batch_file_load
  if params[:files] && digested_cookie_exists?(params[:files][0].tempfile, :batch_file_load_simple_md5)
    @result = BatchFileLoad::Import::Otus::SimpleInterpreter.new(batch_params)

    if @result.create
      flash[:notice] = "Successfully processed #{@result.total_files_processed} file(s), #{@result.total_records_created} otus were created."
      render 'otus/batch_file_load/simple/create'
      return
    else
      flash[:alert] = 'Batch import failed.'
      render :batch_load
    end
  end
end

#create_simple_batch_loadObject



130
131
132
133
134
135
136
137
138
139
140
141
# File 'app/controllers/otus_controller.rb', line 130

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :batch_otus_md5)
    @result = BatchLoad::Import::Otus.new(batch_params.merge(user_map))
    if @result.create
      flash[:notice] = "Successfully processed file, #{@result.total_records_created} otus were created."
      render('otus/batch_load/simple/create') and return
    else
      flash[:alert] = 'Batch import failed.'
    end
    render(:batch_load)
  end
end

#destroyObject

DELETE /otus/1 DELETE /otus/1.json



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

def destroy
  @otu.destroy
  respond_to do |format|
    format.html { redirect_to otus_url }
    format.json { head :no_content }
  end
end

#downloadObject

GET /otus/download



223
224
225
226
227
# File 'app/controllers/otus_controller.rb', line 223

def download
  send_data Export::Download.generate_csv(Otu.where(project_id: sessions_current_project_id)),
    type: 'text',
    filename: "otus_#{DateTime.now}.csv"
end

#editObject

GET /otus/1/edit



32
33
# File 'app/controllers/otus_controller.rb', line 32

def edit
end

#filter_paramsObject (private)



263
264
265
266
267
268
269
270
271
# File 'app/controllers/otus_controller.rb', line 263

def filter_params
  params.permit(
    :taxon_name_id, :otu_id,
    biological_association_ids: [], taxon_name_ids: [], otu_ids: [],
    taxon_name_relationship_ids: [],taxon_name_classification_ids: [],
    asserted_distribution_ids: [],
    data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :attribute_subject_id, :attribute_subject_type, :value ]
  )
end

#indexObject

GET /otus GET /otus.json



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/otus_controller.rb', line 9

def index
  respond_to do |format|
    format.html do
      @recent_objects = Otu.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @otus = Queries::Otu::Filter.new(filter_params).all.where(project_id: sessions_current_project_id).page(params[:page]).per(params[:per] || 500)
    }
  end
end

#listObject



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

def list
  @otus = Otu.with_project_id(sessions_current_project_id).page(params[:page]).per(params[:per])
end

GET /otus/1/navigation.json



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

def navigation
end

#newObject

GET /otus/new



27
28
29
# File 'app/controllers/otus_controller.rb', line 27

def new
  @otu = Otu.new
end

#otu_paramsObject (private)



247
248
249
# File 'app/controllers/otus_controller.rb', line 247

def otu_params
  params.require(:otu).permit(:name, :taxon_name_id)
end

#preview_data_attributes_batch_loadObject

TODO: AUTOGENERATED STUB, check and update



195
196
197
198
199
200
201
202
203
204
# File 'app/controllers/otus_controller.rb', line 195

def preview_data_attributes_batch_load
  if params[:file]
    @result = BatchLoad::Import::Otus::DataAttributesInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :data_attributes_batch_load_otus_md5)
    render 'otus/batch_load/data_attributes/preview'
  else
    flash[:notice] = "No file provided!"
    redirect_to action: :batch_load
  end
end

#preview_identifiers_batch_loadObject



143
144
145
146
147
148
149
150
151
152
# File 'app/controllers/otus_controller.rb', line 143

def preview_identifiers_batch_load
  if params[:file]
    @result = BatchLoad::Import::Otus::IdentifiersInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :batch_load_otus_identifiers_md5)
    render('otus/batch_load/identifiers/preview')
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

#preview_simple_batch_file_loadObject



168
169
170
171
172
173
174
175
176
177
# File 'app/controllers/otus_controller.rb', line 168

def preview_simple_batch_file_load
  if params[:files]
    @result = BatchFileLoad::Import::Otus::SimpleInterpreter.new(batch_params)
    digest_cookie(params[:files][0].tempfile, :batch_file_load_simple_md5)
    render 'otus/batch_file_load/simple/preview'
  else
    flash[:notice] = 'No file(s) provided!'
    redirect_to action: :batch_load
  end
end

#preview_simple_batch_loadObject



119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/otus_controller.rb', line 119

def preview_simple_batch_load
  if params[:file]
    @result = BatchLoad::Import::Otus.new(batch_params.merge(user_map))
    digest_cookie(params[:file].tempfile, :batch_otus_md5)
    render('otus/batch_load/simple/preview')
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

#searchObject



102
103
104
105
106
107
108
109
# File 'app/controllers/otus_controller.rb', line 102

def search
  if params[:id].blank?
    redirect_to(otus_path,
                notice: 'You must select an item from the list with a click or tab press before clicking show.')
  else
    redirect_to otu_path(params[:id])
  end
end

#select_optionsObject

GET /otus/select_options?target=TaxonDetermination



236
237
238
# File 'app/controllers/otus_controller.rb', line 236

def select_options
  @otus = Otu.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:target))
end

#set_otuObject (private)



242
243
244
245
# File 'app/controllers/otus_controller.rb', line 242

def set_otu
  @otu = Otu.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @otu
end

#showObject

GET /otus/1 GET /otus/1.json



23
24
# File 'app/controllers/otus_controller.rb', line 23

def show
end

#updateObject

PATCH/PUT /otus/1 PATCH/PUT /otus/1.json



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

def update
  respond_to do |format|
    if @otu.update(otu_params)
      format.html { redirect_to @otu, notice: 'Otu was successfully updated.' }
      format.json { render :show, location: @otu }
    else
      format.html { render action: 'edit' }
      format.json { render json: @otu.errors, status: :unprocessable_entity }
    end
  end
end

#user_mapObject (private)

rubocop:disable Style/StringHashKeys



274
275
276
# File 'app/controllers/otus_controller.rb', line 274

def user_map
  {user_header_map: {'otu' => 'otu_name'}}
end