Class: PlatesController

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

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #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

rubocop:todo Metrics/MethodLength



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
# File 'app/controllers/plates_controller.rb', line 23

def create # rubocop:todo Metrics/AbcSize
  @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

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



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

def create_sample_tubes # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  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



113
114
115
116
117
118
119
# File 'app/controllers/plates_controller.rb', line 113

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

#newObject



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

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

#set_barcode_printersObject



62
63
64
65
# File 'app/controllers/plates_controller.rb', line 62

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

#set_plate_creatorsObject

rubocop:enable Metrics/MethodLength



58
59
60
# File 'app/controllers/plates_controller.rb', line 58

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

#showObject



11
12
13
# File 'app/controllers/plates_controller.rb', line 11

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

#to_sample_tubesObject



83
84
85
86
# File 'app/controllers/plates_controller.rb', line 83

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

#tube_rack_barcodesObject



67
68
69
70
71
# File 'app/controllers/plates_controller.rb', line 67

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)


73
74
75
76
77
# File 'app/controllers/plates_controller.rb', line 73

def tube_rack_sources?
  return false if tube_rack_barcodes.empty?

  tube_racks.count == tube_rack_barcodes.length
end

#tube_racksObject



79
80
81
# File 'app/controllers/plates_controller.rb', line 79

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