Class: SearchController

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

Overview

Handles most of the indexes of plates/tubes

Defined Under Namespace

Classes: InputError

Instance Method Summary collapse

Instance Method Details

#createObject

rubocop:todo Metrics/AbcSize



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/search_controller.rb', line 38

def create # rubocop:todo Metrics/AbcSize
  raise 'You have not supplied a labware barcode' if params[:plate_barcode].blank?

  respond_to { |format| format.html { redirect_to find_labware(params[:plate_barcode]) } }
rescue StandardError => e
  flash.now[:error] = e.message

  # rendering new without re-searching for the ongoing plates...
  respond_to do |format|
    format.html { render :new }
    format.json { render json: { error: e.message }, status: :not_found }
  end
end

#find_labware(barcode) ⇒ Object



52
53
54
55
56
# File 'app/controllers/search_controller.rb', line 52

def find_labware(barcode)
  Sequencescape::Api::V2
    .minimal_labware_by_barcode(barcode)
    .tap { |labware| raise "Sorry, could not find labware with the barcode '#{barcode}'." if labware.nil? }
end

#find_qcable(barcode) ⇒ Object



58
59
60
61
62
# File 'app/controllers/search_controller.rb', line 58

def find_qcable(barcode)
  api.search.find(Settings.searches['Find qcable by barcode']).first(barcode: barcode)
rescue Sequencescape::Api::ResourceNotFound => e
  raise e, "Sorry, could not find qcable with the barcode '#{barcode}'."
end

#newObject



10
# File 'app/controllers/search_controller.rb', line 10

def new; end

#ongoing_platesObject

rubocop:todo Metrics/AbcSize



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

def ongoing_plates # rubocop:todo Metrics/AbcSize
  plate_search = api.search.find(Settings.searches.fetch('Find plates'))
  @purpose_options = helpers.purpose_options('plate')
  @search_options = OngoingPlate.new(ongoing_plate_search_params)

  @search_options.page = params['page'].to_i if params['page'].present?
  @search_results = plate_search.all(Limber::Plate, @search_options.search_parameters)
  @search_options.total_results = @search_results.size
end

#ongoing_tubesObject

rubocop:todo Metrics/AbcSize



22
23
24
25
26
27
28
29
30
# File 'app/controllers/search_controller.rb', line 22

def ongoing_tubes # rubocop:todo Metrics/AbcSize
  tube_search = api.search.find(Settings.searches.fetch('Find tubes'))
  @purpose_options = helpers.purpose_options('tube')
  @search_options = OngoingTube.new(ongoing_tube_search_params)
  @search_options.page = params['page'].to_i if params['page'].present?

  @search_results = tube_search.all(Limber::Tube, @search_options.search_parameters)
  @search_options.total_results = @search_results.size
end

#qcablesObject



32
33
34
35
36
# File 'app/controllers/search_controller.rb', line 32

def qcables
  respond_to { |format| format.json { redirect_to find_qcable(qcable_barcode) } }
rescue Sequencescape::Api::ResourceNotFound, ActionController::ParameterMissing, InputError => e
  render json: { 'error' => e.message }
end