Class: LabwareController

Inherits:
ApplicationController show all
Includes:
RetentionInstructionHelper
Defined in:
app/controllers/labware_controller.rb

Overview

Handles viewing Labware information

See Also:

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods included from RetentionInstructionHelper

#find_retention_instruction_from_key, #find_retention_instruction_key_for_value, #find_retention_instruction_to_display, #retention_instruction_option_for_select

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

#destroyObject



80
81
82
83
84
85
86
87
# File 'app/controllers/labware_controller.rb', line 80

def destroy
  @asset.destroy

  respond_to do |format|
    format.html { redirect_to(assets_url) }
    format.xml { head :ok }
  end
end

#editObject



41
42
43
# File 'app/controllers/labware_controller.rb', line 41

def edit
  @valid_purposes_options = @asset.compatible_purposes.pluck(:name, :id)
end

#find_by_barcodeObject



151
152
# File 'app/controllers/labware_controller.rb', line 151

def find_by_barcode
end

#historyObject



49
50
51
52
53
54
55
# File 'app/controllers/labware_controller.rb', line 49

def history
  respond_to do |format|
    format.html
    format.xml { @request.events.to_xml }
    format.json { @request.events.to_json }
  end
end

#indexObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/labware_controller.rb', line 9

def index # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  if params[:study_id]
    @study = Study.find(params[:study_id])
    @assets = @study.assets_through_aliquots.order(:name).page(params[:page])
  else
    @assets = Labware.page(params[:page])
  end

  respond_to do |format|
    format.html
    if params[:study_id]
      format.xml { render xml: Study.find(params[:study_id]).assets_through_requests.to_xml }
    elsif params[:sample_id]
      format.xml { render xml: Sample.find(params[:sample_id]).assets.to_xml }
    elsif params[:asset_id]
      @asset = Labware.find(params[:asset_id])
      format.xml do
        render xml: [{ 'relations' => { 'parents' => @asset.parents, 'children' => @asset.children } }].to_xml
      end
    end
  end
end

#lab_viewObject



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/controllers/labware_controller.rb', line 154

def lab_view
  barcode = params.fetch(:barcode, '').strip

  if barcode.blank?
    redirect_to action: 'find_by_barcode'
    nil
  else
    @asset = Labware.find_from_barcode(barcode)
    if @asset.nil?
      redirect_to action: 'find_by_barcode', error: "Unable to find anything with this barcode: #{barcode}"
    end
  end
end

#lookupObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/labware_controller.rb', line 130

def lookup # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  return unless params[:asset] && params[:asset][:barcode]

  @assets = Labware.with_barcode(params[:asset][:barcode]).limit(50).page(params[:page])

  if @assets.size == 1
    redirect_to @assets.first
  elsif @assets.empty?
    flash.now[:error] = "No asset found with barcode #{params[:asset][:barcode]}"
    respond_to do |format|
      format.html { render action: 'lookup' }
      format.xml { render xml: @assets.to_xml }
    end
  else
    respond_to do |format|
      format.html { render action: 'index' }
      format.xml { render xml: @assets.to_xml }
    end
  end
end


94
95
96
97
98
99
100
101
102
# File 'app/controllers/labware_controller.rb', line 94

def print
  if @asset.printable?
    @printable = @asset.printable_target
    @direct_printing = (@asset.printable_target == @asset)
  else
    flash[:error] = "#{@asset.display_name} does not have a barcode so a label can not be printed."
    redirect_to labware_path(@asset)
  end
end


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

def print_assets
  print_job = LabelPrinter::PrintJob.new(params[:printer], LabelPrinter::Label::AssetRedirect, printables: @asset)
  if print_job.execute
    flash[:notice] = print_job.success
  else
    flash[:error] = print_job.errors.full_messages.join('; ')
  end
  redirect_to labware_path(@asset)
end


104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/labware_controller.rb', line 104

def print_labels
  print_job =
    LabelPrinter::PrintJob.new(params[:printer], LabelPrinter::Label::AssetRedirect, printables: params[:printables])
  if print_job.execute
    flash[:notice] = print_job.success
  else
    flash[:error] = print_job.errors.full_messages.join('; ')
  end

  redirect_to phi_x_url
end

#retention_instructionObject



45
46
47
# File 'app/controllers/labware_controller.rb', line 45

def retention_instruction
  @retention_instruction_options = retention_instruction_option_for_select
end

#showObject



32
33
34
35
36
37
38
39
# File 'app/controllers/labware_controller.rb', line 32

def show
  @source_plates = @asset.source_plates
  respond_to do |format|
    format.html { @aliquots = @asset.aliquots.include_summary.paginate(page: params[:page], per_page: 384) }
    format.xml
    format.json { render json: @asset }
  end
end

#show_plateObject



126
127
128
# File 'app/controllers/labware_controller.rb', line 126

def show_plate
  @asset = Plate.find(params[:id])
end

#summaryObject



89
90
91
92
# File 'app/controllers/labware_controller.rb', line 89

def summary
  @summary = UiHelper::Summary.new(per_page: 25, page: params[:page])
  @summary.load_asset(@asset)
end

#updateObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



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

def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  respond_to do |format|
    params_hash = params.to_unsafe_h
    current_retention_instruction = @asset.retention_instruction
    if @asset.update(labware_params.merge(params_hash.fetch(:lane, {})))
      if params_hash[:labware].key?(:retention_instruction) &&
           current_retention_instruction != @asset.retention_instruction
        EventFactory.record_retention_instruction_updates(@asset, current_user, current_retention_instruction)
      end
      flash[:notice] = find_flash(params_hash)
      if params[:lab_view]
        format.html { redirect_to(action: :lab_view, barcode: @asset.human_barcode) }
      else
        format.html { redirect_to(action: :show, id: @asset.id) }
        format.xml { head :ok }
      end
    else
      format.html { render action: 'edit' }
      format.xml { render xml: @asset.errors, status: :unprocessable_entity }
    end
  end
end