Class: Sdb::SampleManifestsController

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

Constant Summary collapse

LIMIT_ERROR_LENGTH =
10000

Instance Method Summary collapse

Instance Method Details

#createObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 32

def create
  @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


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

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


54
55
56
57
58
59
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 54

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

#newObject


21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 21

def new
  params[:only_first_label] ||= false
  @sample_manifest = SampleManifest.new(new_manifest_params)
  @study_id = params[:study_id] || ''
  @studies = Study.alphabetical.pluck(:name, :id)
  @suppliers = Supplier.alphabetical.pluck(:name, :id)
  @purposes = @sample_manifest.acceptable_purposes.pluck(:name, :id)
  @barcode_printers = @sample_manifest.applicable_barcode_printers.pluck(:name)
  @templates        = SampleManifestExcel.configuration.manifest_types.by_asset_type(params[:asset_type]).to_a
end

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

def print_labels
  print_job = LabelPrinter::PrintJob.new(params[:printer],
                                         LabelPrinter::Label::SampleManifestRedirect,
                                         sample_manifest: @sample_manifest)
  if print_job.execute
    flash[:notice] = print_job.success
  else
    flash[:error] = print_job.errors.full_messages.join('; ')
  end
  redirect_back fallback_location: root_path
end

#showObject

Show the manifest


49
50
51
52
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 49

def show
  @study_id = @sample_manifest.study_id
  @samples = @sample_manifest.samples.paginate(page: params[:page])
end

#uploaded_spreadsheetObject


14
15
16
17
18
19
# File 'app/controllers/sdb/sample_manifests_controller.rb', line 14

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