Class: PlatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plates_controller.rb

Overview

rubocop:todo Style/Documentation

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Method Details

#createObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/plates_controller.rb', line 22

def create
  @creator = plate_creator = Plate::Creator.find(params[:plates][:creator_id])
  barcode_printer = BarcodePrinter.find(params[:plates][:barcode_printer])
  source_plate_barcodes = params[:plates][:source_plates]
  create_asset_group = params[:plates][:create_asset_group] == 'Yes'

  scanned_user = User.find_with_barcode_or_swipecard_code(params[:plates][:user_barcode])

  respond_to do |format|
    if scanned_user.nil?
      flash[:error] = 'Please scan your user barcode'
    elsif tube_rack_sources?
      plate_creator.create_plates_from_tube_racks!(
        tube_racks,
        barcode_printer,
        scanned_user,
        create_asset_group
      )
    else
      plate_creator.execute(
        source_plate_barcodes,
        barcode_printer,
        scanned_user,
        create_asset_group,
        Plate::CreatorParameters.new(params[:plates])
      )
    end
    flash[:notice] = 'Created plates successfully'
    flash[:warning] = plate_creator.warnings if plate_creator.warnings.present?
    format.html { render(new_plate_path) }
  end
rescue StandardError => e
  respond_to do |format|
    flash[:error] = e.message
    format.html { render(new_plate_path) }
  end
end

#create_sample_tubesObject


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/plates_controller.rb', line 90

def create_sample_tubes
  barcode_printer = BarcodePrinter.find(params[:plates][:barcode_printer])
  barcode_array = params[:plates][:source_plates].scan(/\w+/)
  plates = Plate.with_barcode(barcode_array)
  study = Study.find(params[:plates][:study])

  respond_to do |format|
    asset_group = Plate::SampleTubeFactory.create_sample_tubes_asset_group_and_print_barcodes(plates,
                                                                                              barcode_printer,
                                                                                              study)
    if asset_group
      flash[:notice] = 'Created tubes and printed barcodes'
      # makes request properties partial show
      format.html { redirect_to(new_submission_path(study_id: asset_group.study.id)) }
      format.xml  { render xml: asset_group, status: :created }
      format.json { render json: asset_group, status: :created }
    else
      flash[:error] = 'Failed to create sample tubes'
      format.html { redirect_to(to_sample_tubes_plates_path) }
      format.xml  { render xml: flash.to_xml, status: :unprocessable_entity }
      format.json { render json: flash.to_json, status: :unprocessable_entity }
    end
  end
end

#fluidigm_fileObject


115
116
117
118
119
120
121
122
123
# File 'app/controllers/plates_controller.rb', line 115

def fluidigm_file
  if logged_in?
    @plate = Plate.includes(wells: [{ samples: :sample_metadata }, :map]).find(params[:id])
    @parents = @plate.parents
    respond_to do |format|
      format.csv { render csv: @plate, content_type: 'text/csv' }
    end
  end
end

#newObject


10
11
12
13
14
15
16
# File 'app/controllers/plates_controller.rb', line 10

def new
  respond_to do |format|
    format.html
    format.xml  { render xml: @plate }
    format.json { render json: @plate }
  end
end

#set_barcode_printersObject


64
65
66
67
# File 'app/controllers/plates_controller.rb', line 64

def set_barcode_printers
  @barcode_printers = BarcodePrinterType96Plate.first.barcode_printers
  @barcode_printers = BarcodePrinter.order('name asc') if @barcode_printers.blank?
end

#set_plate_creatorsObject


60
61
62
# File 'app/controllers/plates_controller.rb', line 60

def set_plate_creators
  @plate_creators = Plate::Creator.order(:name)
end

#showObject


18
19
20
# File 'app/controllers/plates_controller.rb', line 18

def show
  @plate = Plate.find(params[:id])
end

#to_sample_tubesObject


85
86
87
88
# File 'app/controllers/plates_controller.rb', line 85

def to_sample_tubes
  @barcode_printers = BarcodePrinter.all
  @studies = Study.alphabetical
end

#tube_rack_barcodesObject


69
70
71
72
73
# File 'app/controllers/plates_controller.rb', line 69

def tube_rack_barcodes
  return [] unless params.dig(:plates).dig(:source_plates)

  params[:plates][:source_plates].split(/[\s,]+/)
end

#tube_rack_sources?Boolean

Returns:

  • (Boolean)

75
76
77
78
79
# File 'app/controllers/plates_controller.rb', line 75

def tube_rack_sources?
  return false if tube_rack_barcodes.empty?

  tube_racks.count == tube_rack_barcodes.length
end

#tube_racksObject


81
82
83
# File 'app/controllers/plates_controller.rb', line 81

def tube_racks
  @tube_racks ||= TubeRack.joins(:barcodes).where(barcodes: { barcode: tube_rack_barcodes })
end