Class: Tasks::Nomenclature::PaperCatalogController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/nomenclature/paper_catalog_controller.rb

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#indexObject

GET /tasks/nomenclature/paper_catalog?taxon_name_id=123



5
6
7
8
9
10
11
# File 'app/controllers/tasks/nomenclature/paper_catalog_controller.rb', line 5

def index
  if params[:taxon_name_id]
    @taxon_name = Protonym.where(project_id: sessions_current_project_id).find(params[:taxon_name_id])
  else
    @taxon_name = nil
  end
end

#previewObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/tasks/nomenclature/paper_catalog_controller.rb', line 13

def preview
  redirect_to action: :index, warning: 'You must (re)select a TaxonName for each of Preview/Download' and return if params[:taxon_name_id].blank?

  @taxon_name = TaxonName.where(project_id: sessions_current_project_id).find(params[:taxon_name_id])

  c = @taxon_name.descendants.that_is_valid.count
  if c > 10000
    redirect_to :index, message: "Export of #{c} is too presently too large." and return
  end

  @data = helpers.recursive_catalog_tag(@taxon_name)

  # TODO: move logic out
  if params[:submit] == 'Download'
    s = render_to_string(partial: '/tasks/nomenclature/paper_catalog/preview', locals: {taxon_name: @taxon_name, data: @data }, layout: false, formats: [:html])
    a = ::Export::PaperCatalog.export(@taxon_name, s)
    send_data(File.read(a), filename: "#{@taxon_name.name}_paper_catalog_#{DateTime.now}.zip", type: 'application/zip') and return
  end

  render :index
end