Class: PlatesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

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

Instance Method Details

#createObject


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

def create
  ActiveRecord::Base.transaction do
    plate_creator         = Plate::Creator.find(params[:plates][:creator_id])
    barcode_printer       = BarcodePrinter.find(params[:plates][:barcode_printer])
    source_plate_barcodes = params[:plates][:source_plates]

    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'
        format.html { redirect_to(new_plate_path) }
      elsif plate_creator.execute(source_plate_barcodes, barcode_printer, scanned_user, Plate::CreatorParameters.new(params[:plates]))
        flash[:notice] = 'Created plates and printed barcodes'
        format.html { redirect_to(new_plate_path) }
      else
        flash[:error] = 'Failed to create plates'
        format.html { redirect_to(new_plate_path) }
      end
    end
  end
rescue Plate::Creator::PlateCreationError, ActiveRecord::RecordNotFound => e
  respond_to do |format|
    flash[:error] = e.message
    format.html { redirect_to(new_plate_path) }
  end
end

#create_sample_tubesObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/plates_controller.rb', line 56

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|
    if asset_group = Plate::SampleTubeFactory.create_sample_tubes_asset_group_and_print_barcodes(plates, barcode_printer, study)
      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


78
79
80
81
82
83
84
85
86
# File 'app/controllers/plates_controller.rb', line 78

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


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

def new
  @plate_creators   = Plate::Creator.order(:name)
  @barcode_printers = BarcodePrinterType96Plate.first.barcode_printers
  @barcode_printers = BarcodePrinter.order('name asc') if @barcode_printers.blank?

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

#showObject


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

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

#to_sample_tubesObject


51
52
53
54
# File 'app/controllers/plates_controller.rb', line 51

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