Class: OtusController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/otus_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 inherited from ApplicationController

#set_time_zone

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, #cumulative_projects_created_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_initials, #project_link, #project_login_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #sound_cumulative_gb_per_year, #sound_gb_per_year, #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

#api_alphabetical_index ⇒ Object



292
293
294
295
296
297
298
299
300
301
# File 'app/controllers/otus_controller.rb', line 292

def api_alphabetical_index
  @otus = ::Queries::Otu::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .page(params[:page])
    .per(params[:per])
    .eager_load(:taxon_name)
    .order(:cached, 'otus.name')

  render '/otus/api/v1/index'
end

#api_autocomplete ⇒ Object

GET /api/v1/otus/autocomplete



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'app/controllers/otus_controller.rb', line 323

def api_autocomplete
  @term = params.require(:term)

  include_common_names =
    params[:include_common_names].present? ? true : false

  @otu_metadata = ::Queries::Otu::Autocomplete.new(
    @term,
    project_id: sessions_current_project_id,
    with_taxon_name: params[:with_taxon_name],
    having_taxon_name_only: params[:having_taxon_name_only],
    include_common_names:,
    include_taxon_name: true
  ).api_autocomplete_extended

  if include_common_names
    @otu_metadata.each do |m|
      m[:common_names] = m[:otu].common_names
    end
  end

  render '/otus/api/v1/autocomplete'
end

#api_citations_inventory ⇒ Object

GET /api/v1/otus/:id/inventory/citations



438
439
440
441
# File 'app/controllers/otus_controller.rb', line 438

def api_citations_inventory
  @catalog = Catalog::Inventory.new(targets: [@otu])
  render '/otus/api/v1/inventory/citations'
end

#api_content ⇒ Object

GET /api/v1/otus/:id/inventory/content



411
412
413
414
415
416
417
418
419
# File 'app/controllers/otus_controller.rb', line 411

def api_content
  topic_ids = [params[:topic_id]].flatten.compact.uniq
  otu_ids = params[:coordinate_otus] == 'true' ? Otu.coordinate_otus(@otu.id).pluck(:id) : [@otu.id]

  @public_content = PublicContent.where(otu_id: otu_ids, project_id: sessions_current_project_id)
  @public_content = @public_content.joins(:topic).where(topic_id: topic_ids) unless topic_ids.empty?

  render '/otus/api/v1/inventory/content'
end

#api_determined_to_rank ⇒ Object



303
304
305
# File 'app/controllers/otus_controller.rb', line 303

def api_determined_to_rank
  render json: helpers.dwc_determined_to_rank(@otu, sessions_current_project_id)
end

#api_distribution ⇒ Object

TODO: Considerations .json

  • Scope Genus, Family by default
  • 404 when no CachedMap computable

.geo_json

  • Always returns result, could be empty

GET /api/v1/otus/:id/inventory/distribution.json GET /api/v1/otus/:id/inventory/distribution.geojson



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'app/controllers/otus_controller.rb', line 486

def api_distribution
  respond_to do |format|
    format.json do
      @cached_map_type = params[:cached_map_type] || 'CachedMapItem::WebLevel1'
      @quicker_cached_map = @otu.quicker_cached_map(@cached_map_type)
      if @quicker_cached_map.blank?
        render json: { error: 'no map available'}, status: :not_found and return
      end
      render '/otus/api/v1/inventory/distribution'
    end
    format.geojson do
      if params[:coordinate_otus] == 'false'
        @otus = Otu.where(id: @otu.id)
        render '/otus/distribution_by_otus' and return
      end
      render '/otus/api/v1/inventory/distribution'
    end
  end

end

#api_distribution_is_absent ⇒ Object

GET /api/v1/otus/:id/inventory/distribution_is_absent.geojson



612
613
614
615
616
617
618
619
620
621
622
623
# File 'app/controllers/otus_controller.rb', line 612

def api_distribution_is_absent
  @descendants = params[:descendants] == 'true'
  respond_to do |format|
    format.geojson do
      if params[:coordinate_otus] == 'false'
        @otus = Otu.where(id: @otu.id)
        render '/otus/distribution_is_absent_by_otus' and return
      end
      render '/otus/api/v1/inventory/distribution_is_absent'
    end
  end
end

GET /api/v1/otus/:id/inventory/dwc_gallery.json?per=1&page=2



403
404
405
406
407
408
# File 'app/controllers/otus_controller.rb', line 403

def api_dwc_gallery
  # see otus_helper

  @data = helpers.dwc_gallery_data(@otu, dwc_occurrence_id: params[:dwc_occurrence_id])
  render '/otus/api/v1/inventory/dwc_gallery'
end

#api_dwc_inventory ⇒ Object

GET /api/v1/otus/:id/inventory/dwc



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'app/controllers/otus_controller.rb', line 379

def api_dwc_inventory
  respond_to do |format|
    format.csv do
      send_data Export::CSV.generate_csv(
        DwcOccurrence.scoped_by_otu(@otu),
        exclude_columns: ['id', 'created_by_id', 'updated_by_id', 'project_id', 'updated_at', 'rebuild_set'],
        header_converters: [:dwc_headers]),
      type: 'text',
      filename: "dwc_#{helpers.label_for_otu(@otu).gsub(/\W/,'_')}_#{DateTime.now}.tsv"
    end

    format.json do
      if params[:page].blank? && params[:per].blank?
        render json: DwcOccurrence.scoped_by_otu(@otu).to_json
      else # only apply if provided, do not fall back to default scope
        r = DwcOccurrence.scoped_by_otu(@otu).page(params[:page]).per(params[:per])
        assign_pagination(r)
        render json: r.to_json
      end
    end
  end
end

#api_image_inventory ⇒ Object

GET /api/v1/otus/:id/inventory/images

  • routed here to take advantage of Pagination


349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'app/controllers/otus_controller.rb', line 349

def api_image_inventory
  @depictions = ::Queries::Depiction::Filter.new(
    project_id: sessions_current_project_id,
    otu_id: [params.require(:otu_id)],
    otu_scope: (params[:otu_scope] || :all)
  ).all
    .joins("LEFT OUTER JOIN observations ON (observations.id = depictions.depiction_object_id and depictions.depiction_object_type = 'Observation')")
    .joins('LEFT OUTER JOIN descriptors ON descriptors.id = observations.descriptor_id')
    .eager_load(image: [:attribution])
  if params[:sort_order]
    @depictions = @depictions.order( Arel.sql( conditional_sort('depictions.depiction_object_type', params[:sort_order]) + ', descriptors.position, depictions.depiction_object_id, depictions.position' ))
  else
    @depictions = @depictions.order('depictions.depiction_object_type, descriptors.position, depictions.depiction_object_id, depictions.position')
  end
  @depictions = @depictions.page(params[:page]).per(params[:per])

  render '/otus/api/v1/inventory/images'
end

#api_index ⇒ Object

GET /api/v1/otus.csv GET /api/v1/otus



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'app/controllers/otus_controller.rb', line 272

def api_index
  q = ::Queries::Otu::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('otus.id')

  respond_to do |format|
    format.json {
      @otus = q.page(params[:page]).per(params[:per])
      render '/otus/api/v1/index'
    }
    format.csv {
      @otus = q
      send_data Export::CSV.generate_csv(
        @otus,
        exclude_columns: %w{updated_by_id created_by_id project_id},
      ), type: 'text', filename: "otus_#{DateTime.now}.tsv"
    }
  end
end

#api_key_inventory ⇒ Object

GET /api/v1/otus/:id/inventory/keys



369
370
371
# File 'app/controllers/otus_controller.rb', line 369

def api_key_inventory
  render json: helpers.otu_key_inventory(@otu)
end

#api_nomenclature_citations ⇒ Object

GET /api/v1/otus/:id/inventory/nomenclature_citations



444
445
446
447
448
449
450
451
# File 'app/controllers/otus_controller.rb', line 444

def api_nomenclature_citations
  if @otu.taxon_name
    @data = ::Catalog::Nomenclature::Entry.new(@otu.taxon_name)
    render '/otus/api/v1/inventory/nomenclature_citations'
  else
    render json: {}, status: :unprocessable_content
  end
end

#api_show ⇒ Object

GET /api/v1/otus/:id



308
309
310
# File 'app/controllers/otus_controller.rb', line 308

def api_show
  render '/otus/api/v1/show'
end

#api_taxonomy_inventory ⇒ Object

GET /api/v1/otus/:id/inventory/taxonomy



374
375
376
# File 'app/controllers/otus_controller.rb', line 374

def api_taxonomy_inventory
  render '/otus/api/v1/inventory/taxonomy'
end

#api_type_material_inventory ⇒ Object

GET /api/v1/otus/:id/inventory/type_material



422
423
424
425
426
427
428
429
# File 'app/controllers/otus_controller.rb', line 422

def api_type_material_inventory
  @type_materials = TypeMaterial.where(protonym_id: @otu.taxon_name&.valid_taxon_name&.historical_taxon_names&.select(:id))
    .joins(:protonym)
    .preload(:protonym, collection_object: [:collecting_event, :repository, :dwc_occurrence, :biocuration_classes, :identifiers])
    .order('taxon_names.cached_is_valid DESC, taxon_names.cached_nomenclature_date, type_materials.id')

  render '/otus/api/v1/inventory/type_material'
end

#autocomplete ⇒ Object



312
313
314
315
316
317
318
319
320
# File 'app/controllers/otus_controller.rb', line 312

def autocomplete
  @otus = ::Queries::Otu::Autocomplete.new(
    params.require(:term),
    exact: params[:exact],  # 'true',
    project_id: sessions_current_project_id,
    with_taxon_name: params[:with_taxon_name],
    having_taxon_name_only: params[:having_taxon_name_only],
  ).autocomplete
end

#autoselect ⇒ Object

GET /otus/autoselect



508
509
510
511
512
513
514
515
516
# File 'app/controllers/otus_controller.rb', line 508

def autoselect
  render json: ::Autoselect::Otu::Autoselect.new(
    term: params[:term],
    level: params[:level],
    project_id: sessions_current_project_id,
    user_id: sessions_current_user_id,
    **autoselect_params
  ).response
end

#autoselect_col_create ⇒ Object

POST /otus/autoselect_col_create Creates TaxonNames from a CoL alignment then wraps the result in an OTU: the name's existing one when it's unambiguous, else a new one if it has none. When the user has to choose the OTU, nothing is created (see Autoselect::Otu::ColExistingOtu).



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'app/controllers/otus_controller.rb', line 523

def autoselect_col_create
  tn_result = nil
  otu = nil

  # CatalogueOfLifeCreator's own transaction joins this one, so an ambiguous
  # OTU rolls back the TaxonNames too.
  ::ActiveRecord::Base.transaction do
    tn_result = ::Autoselect::TaxonName::CatalogueOfLifeCreator.new(
      rows:     autoselect_col_create_params,
      col_code: params[:col_code],
      project_id: sessions_current_project_id,
      user_id:    sessions_current_user_id
    ).call

    otu = ::Autoselect::Otu::ColExistingOtu.find_or_create_for(
      tn_result[:taxon_name_id],
      project_id: sessions_current_project_id,
      user_id: sessions_current_user_id
    )
  end

  render json: {
    otu_id: otu.id,
    taxon_name_id: tn_result[:taxon_name_id],
    global_id: otu.to_global_id.to_s
  }
rescue ::Autoselect::TaxonName::CatalogueOfLifeCreator::CreationError => e
  render json: {
    error:           e.message,
    failed_col_name: e.col_name,
    failed_col_id:   e.col_id
  }, status: :unprocessable_entity
rescue ::Autoselect::Otu::ColExistingOtu::AmbiguousOtuError => e
  render json: { error: e.message }, status: :unprocessable_entity
end

#autoselect_col_create_params ⇒ Object (private)



640
641
642
643
644
# File 'app/controllers/otus_controller.rb', line 640

def autoselect_col_create_params
  params.permit(rows: [:col_name, :col_rank, :col_id, :dataset_id, :taxonworks_id, :col_authorship, :col_year, :col_status])
        .fetch(:rows, [])
        .map(&:to_h)
end

#autoselect_params ⇒ Object (private)



636
637
638
# File 'app/controllers/otus_controller.rb', line 636

def autoselect_params
  params.permit(:show_info, :dataset_id).to_h.symbolize_keys
end

#batch_load ⇒ Object



131
132
133
# File 'app/controllers/otus_controller.rb', line 131

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

#batch_params ⇒ Object (private)



666
667
668
669
670
671
672
673
674
675
676
# File 'app/controllers/otus_controller.rb', line 666

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

#batch_update ⇒ Object

PATCH /otus/batch_update.json?otus_query=<>&otu=taxon_name_id=123}



257
258
259
260
261
262
263
264
265
266
267
268
# File 'app/controllers/otus_controller.rb', line 257

def batch_update
  if r = Otu.batch_update(
      preview: params[:preview],
      otu: otu_params.merge(by: sessions_current_user_id),
      otu_query: params[:otu_query],
      user_id: sessions_current_user_id,
      project_id: sessions_current_project_id)
    render json: r.to_json, status: :ok
  else
    render json: {}, status: :unprocessable_content
  end
end

GET /otus/1/navigation.json



67
68
69
# File 'app/controllers/otus_controller.rb', line 67

def breadcrumbs
  render json: :not_found and return if @otu.nil?
end

#by_name ⇒ Object

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



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

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

#citations_inventory ⇒ Object

GET /otus/:id/inventory/citations



432
433
434
435
# File 'app/controllers/otus_controller.rb', line 432

def citations_inventory
  @catalog = Catalog::Inventory.new(targets: [@otu])
  render '/otus/citations'
end

#collection_objects ⇒ Object

GET /otus/1/collection_objects



118
119
120
# File 'app/controllers/otus_controller.rb', line 118

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

#conditional_sort(name, array) ⇒ Object (private)

TODO: Move to generic toolkit in lib/queries



683
684
685
686
687
688
689
# File 'app/controllers/otus_controller.rb', line 683

def conditional_sort(name, array)
  safe_name = ApplicationRecord.sanitize_sql_for_order(name)
  s = "CASE #{safe_name} " + array.each_with_index.collect{|v,i|
    ApplicationRecord.sanitize_sql_for_conditions(["WHEN ? THEN #{i}", v])}.join(' ')
  s << ' ELSE 999999 END'
  s
end

#coordinate ⇒ Object

GET /otus/1/coordinate.json



61
62
63
64
# File 'app/controllers/otus_controller.rb', line 61

def coordinate
  @otus = Otu.coordinate_otus(@otu.id)
  render :index
end

#create ⇒ Object

POST /otus POST /otus.json



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/otus_controller.rb', line 73

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_content }
    end
  end
end

#create_data_attributes_batch_load ⇒ Object

TODO: AUTOGENERATED STUB, check and update



223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'app/controllers/otus_controller.rb', line 223

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_load ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/controllers/otus_controller.rb', line 170

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_morphospecies_otu ⇒ Object

POST /otus/create_morphospecies_otu TODO: sort out what morpho_ ("anchored OTU"?) looks like in general, across nomenclatural codes, add a view.



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'app/controllers/otus_controller.rb', line 562

def create_morphospecies_otu
  otu = ::Otu.create_morphospecies_otu(
    name: create_morphospecies_otu_params[:name],
    project_id: sessions_current_project_id,
    user_id: sessions_current_user_id
  )

  render json: {
    otu_id: otu.id,
    otu_name: otu.name,
    otu_object_label: helpers.label_for_otu(otu),
    otu_global_id: otu.to_global_id.to_s,
    taxon_name_id: otu.taxon_name.id,
    taxon_name_cached: otu.taxon_name.cached,
    taxon_name_cached_html: otu.taxon_name.cached_html,
    taxon_name_object_label: helpers.label_for_taxon_name(otu.taxon_name),
    taxon_name_global_id: otu.taxon_name.to_global_id.to_s
  }
rescue ::ArgumentError => e
  render json: { error: e.message }, status: :unprocessable_entity
end

#create_morphospecies_otu_params ⇒ Object (private)



646
647
648
# File 'app/controllers/otus_controller.rb', line 646

def create_morphospecies_otu_params
  params.permit(:name)
end

#create_simple_batch_file_load ⇒ Object



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

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_load ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/controllers/otus_controller.rb', line 146

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

#destroy ⇒ Object

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



104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/otus_controller.rb', line 104

def destroy
  @otu.destroy
  respond_to do |format|
    if @otu.destroyed?
      format.html { destroy_redirect @otu, notice: 'OTU was successfully destroyed.' }
      format.json { head :no_content}
    else
      format.html { destroy_redirect @otu, notice: 'OTU was not destroyed, ' + @otu.errors.full_messages.join('; ') }
      format.json { render json: @otu.errors, status: :unprocessable_content }
    end
  end
end

#distribution ⇒ Object

TODO: Redirect to json if too big? GET /otus/:id/inventory/distribution.json GET /otus/:id/inventory/distribution.geojson



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'app/controllers/otus_controller.rb', line 456

def distribution
  respond_to do |format|
    format.json do
      @cached_map_type = params[:cached_map_type] || 'CachedMapItem::WebLevel1'
      @quicker_cached_map = @otu.quicker_cached_map(@cached_map_type)

      render json: { error: 'no map available'}, status: :not_found unless @quicker_cached_map.present? and return
    end

    format.geojson do
      if params[:coordinate_otus] == 'false'
        @otus = Otu.where(id: @otu.id)
        render :distribution_by_otus
      end
    end
  end
end

#distribution_by_otus ⇒ Object

Distribution for exactly the OTUs in otu_id (coordinate OTUs are not added) GET|POST /otus/distribution.geojson?otu_id=1&otu_id=2



599
600
601
602
# File 'app/controllers/otus_controller.rb', line 599

def distribution_by_otus
  @otus = distribution_otus
  render json: { error: 'otu_id is required' }, status: :unprocessable_content if @otus.nil?
end

#distribution_is_absent ⇒ Object

GET /otus/:id/inventory/distribution_is_absent.geojson



585
586
587
588
589
590
591
592
593
594
595
# File 'app/controllers/otus_controller.rb', line 585

def distribution_is_absent
  @descendants = params[:descendants] == 'true'
  respond_to do |format|
    format.geojson do
      if params[:coordinate_otus] == 'false'
        @otus = Otu.where(id: @otu.id)
        render :distribution_is_absent_by_otus
      end
    end
  end
end

#distribution_is_absent_by_otus ⇒ Object

Absent distribution for exactly the OTUs in otu_id (coordinate OTUs are not added) GET|POST /otus/distribution_is_absent.geojson?otu_id=1&otu_id=2



606
607
608
609
# File 'app/controllers/otus_controller.rb', line 606

def distribution_is_absent_by_otus
  @otus = distribution_otus
  render json: { error: 'otu_id is required' }, status: :unprocessable_content if @otus.nil?
end

#distribution_otus ⇒ ActiveRecord::Relation? (private)

Returns nil when no otu_id is provided.

Returns:

  • (ActiveRecord::Relation, nil) —

    nil when no otu_id is provided



629
630
631
632
633
634
# File 'app/controllers/otus_controller.rb', line 629

def distribution_otus
  otu_ids = [params[:otu_id]].flatten.compact_blank
  return nil if otu_ids.empty?

  Otu.where(project_id: sessions_current_project_id, id: otu_ids)
end

#download ⇒ Object

GET /otus/download



239
240
241
242
243
# File 'app/controllers/otus_controller.rb', line 239

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

#edit ⇒ Object

GET /otus/1/edit



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

def edit
end

#index ⇒ Object

GET /otus GET /otus.json



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/otus_controller.rb', line 17

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(params).all
        .page(params[:page])
        .per(params[:per])
        .eager_load(:taxon_name)
        .order(:cached, 'otus.name')
    }
  end
end

#list ⇒ Object



47
48
49
# File 'app/controllers/otus_controller.rb', line 47

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

GET /otus/1/navigation.json



57
58
# File 'app/controllers/otus_controller.rb', line 57

def navigation
end

#new ⇒ Object

GET /otus/new



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

def new
  @otu = Otu.new
end

#otu_params ⇒ Object (private)

end end



662
663
664
# File 'app/controllers/otus_controller.rb', line 662

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

#preview_data_attributes_batch_load ⇒ Object

TODO: AUTOGENERATED STUB, check and update



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

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_load ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'app/controllers/otus_controller.rb', line 159

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_load ⇒ Object



184
185
186
187
188
189
190
191
192
193
# File 'app/controllers/otus_controller.rb', line 184

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_load ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/otus_controller.rb', line 135

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

#search ⇒ Object



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

def search
  if params[:id].blank?
    redirect_to(otus_path,
                alert: '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_options ⇒ Object

GET /otus/select_options?target=TaxonDetermination



252
253
254
# File 'app/controllers/otus_controller.rb', line 252

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

#set_otu ⇒ Object (private)



650
651
652
653
# File 'app/controllers/otus_controller.rb', line 650

def set_otu
  @otu = Otu.where(project_id: sessions_current_project_id).eager_load(:taxon_name).find(params[:id])
  @recent_object = @otu
end

#show ⇒ Object

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



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

def show
end

#timeline ⇒ Object

GET /otus/1/timeline.json



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

def timeline
  @catalog = Catalog::Timeline.new(targets: [@otu])
end

#update ⇒ Object

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



90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/otus_controller.rb', line 90

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_content }
    end
  end
end

#user_map ⇒ Object (private)



678
679
680
# File 'app/controllers/otus_controller.rb', line 678

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