Class: AssetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/assets_controller.rb,
app/controllers/assets/plate_layout.rb

Overview

rubocop:todo Style/Documentation

Defined Under Namespace

Classes: PlateLayout

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

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

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Method Details

#lookupObject

JG 23/12/2020: I can't find any links to this page, and think we can probably lose it.


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

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

    case @assets.size
    when 1
      redirect_to @assets.first
    when 0
      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
end

TODO: This is currently used from the PhiX::SpikedBuffersController and PhiX::StocksController show pages. It doesn't really belong here.


46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/assets_controller.rb', line 46

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

#showObject


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

def show
  # LEGACY API FOR CGP to allow switch-over
  # In future they will use the recpetacles/:id/parent
  if request.format.xml?

    @asset = Receptacle.include_for_show.find(params[:id])
    respond_to { |format| format.xml }
    return
  end

  # Disambiguation page for legacy NPG links
  @labware = Labware.find_by(id: params[:id])
  @receptacle = Receptacle.find_by(id: params[:id])

  if @receptacle.nil? && @labware.nil?
    raise ActiveRecord::RecordNotFound
  elsif @labware.nil? || @labware.try(:receptacle) == (@receptacle || :none)
    redirect_to receptacle_path(@receptacle)
  elsif @receptacle.nil? && @labware.present?
    redirect_to labware_path(@labware)
  else
    # Things are ambiguous, we'll make you select
    render :show, status: :multiple_choices
  end
end