Class: Sdb::SampleManifestsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/sdb/sample_manifests_controller.rb

Overview

rubocop:todo Metrics/ClassLength

Constant Summary collapse

LIMIT_ERROR_LENGTH =
10_000

Instance Method Summary collapse

Instance Method Details

#createObject

rubocop:todo Metrics/AbcSize



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

def create # rubocop:todo Metrics/AbcSize
  @sample_manifest_generator =
    SampleManifest::Generator.new(params[:sample_manifest], current_user, SampleManifestExcel.configuration)

  if @sample_manifest_generator.execute
    flash.update(@sample_manifest_generator.print_job_message)
    redirect_to sample_manifest_path(@sample_manifest_generator.sample_manifest)
  else
    flash[:error] = @sample_manifest_generator.errors.full_messages.join(', ')
    redirect_to new_sample_manifest_path
  end
end

#exportObject



8
9
10
11
12
13
14
15
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 8

def export
  @manifest = SampleManifest.find(params[:id])
  send_data(
    @manifest.generated_document.current_data,
    filename: "#{@manifest.default_filename}.xlsx",
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  )
end

#indexObject



26
27
28
29
30
31
32
33
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 26

def index
  pending_sample_manifests =
    SampleManifest.pending_manifests.includes(:study, :supplier, :user).paginate(page: params[:page])
  completed_sample_manifests =
    SampleManifest.completed_manifests.includes(:study, :supplier, :user).paginate(page: params[:page])
  @display_manifests = pending_sample_manifests | completed_sample_manifests
  @sample_manifests = SampleManifest.paginate(page: params[:page])
end

#newObject



43
44
45
46
47
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 43

def new
  set_default_params
  @sample_manifest = SampleManifest.new(new_manifest_params)
  set_instance_variables
end


62
63
64
65
66
67
68
69
70
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 62

def print_labels
  print_job = setup_print_job
  if print_job.execute
    flash[:notice] = print_job.success
  else
    flash[:error] = print_job.errors.full_messages.join('; ')
  end
  redirect_back_or_to(root_path)
end

#showObject

Show the manifest



36
37
38
39
40
41
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 36

def show
  @study_id = @sample_manifest.study_id
  @samples = @sample_manifest.samples.paginate(page: params[:page])
  @barcode_types = Rails.application.config.tube_manifest_barcode_config[:barcode_type_labels].values.sort
  @asset_type = @sample_manifest.asset_type
end

#uploaded_spreadsheetObject



17
18
19
20
21
22
23
24
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 17

def uploaded_spreadsheet
  @manifest = SampleManifest.find(params[:id])
  send_data(
    @manifest.uploaded_document.current_data,
    filename: @manifest.uploaded_document.filename,
    type: @manifest.uploaded_document.content_type || 'application/vnd.ms-excel'
  )
end