Class: ReceptionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/receptions_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

#confirm_receptionObject


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/receptions_controller.rb', line 71

def confirm_reception
  ActiveRecord::Base.transaction do
    assets = params[:asset_id]
    @errors = []
    asset_count = 0

    assets.each do |_index, asset_id|
      asset = Labware.find_by(id: asset_id)
      if asset.nil?
        @errors << "Asset not found with asset ID #{asset_id}"
      else
        asset_count += 1
        asset.events.create_scanned_into_lab!('OLD RECEPTION', current_user.)
        BroadcastEvent::LabwareReceived.create!(seed: asset, user: current_user, properties: { location_barcode: 'OLD RECEPTION' })
      end
    end

    if @errors.size > 0
      respond_to do |format|
        flash[:error] = "Could not update some locations: #{@errors.join(';')}"
        format.html { render action: 'reception' }
        format.xml  { render xml: @errors, status: :unprocessable_entity }
        format.json { render json: @errors, status: :unprocessable_entity }
      end
    else
      respond_to do |format|
        flash[:notice] = "Successfully updated #{asset_count} samples"
        format.html { render action: 'reception' }
        format.xml  { head :ok }
        format.json { head :ok }
      end
    end
  end
end

#find_asset_by_idObject


106
107
108
# File 'app/controllers/receptions_controller.rb', line 106

def find_asset_by_id
  @asset = Asset.find(params[:id])
end

#indexObject


7
8
9
# File 'app/controllers/receptions_controller.rb', line 7

def index
  @num_text_boxes = 10
end

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

def print
  @assets = [@asset]
end

#receive_barcodeObject


15
16
17
18
19
20
21
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
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/receptions_controller.rb', line 15

def receive_barcode
  barcodes = params[:barcode]
  @new_plates = []
  @errors = []
  @assets = []

  all_barcodes_blank = true

  barcodes.each do |_index, barcode_ws|
    # We don't perform strip! as this results in modification of the parameters themselves, which affects logging and
    # exception notification. This can hinder investigation of any issues, as it changes apparent user input.
    barcode = barcode_ws.strip
    if barcode.blank?
      next
    else
      all_barcodes_blank = false
    end

    unless barcode.size == 13
      @errors << "Invalid barcode size for: #{barcode}"
      next
    end
    if Barcode.check_EAN(barcode) == false
      @errors << "Wrong barcode checksum for barcode: #{barcode}"
      next
    end

    asset = Labware.find_by_barcode(barcode)

    if asset.nil?
      @errors << "Asset with barcode #{barcode} not found"
    else
      @assets << asset
    end
  end

  if all_barcodes_blank
    @errors << 'No barcodes have been entered or scanned'
  end

  if @errors.size > 0
    respond_to do |format|
      flash[:error] = "Error with scanned samples: #{@errors.join('. ')}"
      format.html { render action: :index }
      format.xml  { render xml: @errors, status: :unprocessable_entity }
      format.json { render json: @errors, status: :unprocessable_entity }
    end
  else
    respond_to do |format|
      format.html
      format.xml  { head :ok }
      format.json { head :ok }
    end
  end
end