Class: AssetsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- AssetsController
- Defined in:
- app/controllers/assets_controller.rb
Overview
Labware and Receptacle used to both be grouped under Asset and this controller handled them. Now the majority of the behaviour has moved off into the respective controllers. This remains to handle a few legacy endpoints:
show: Kept in place for CGP who were supposed to migrate off, but as of 23/12/2020 I’m (JG) still seeing activity. It might be we have another user who hasn’t migrated. Currently it just mimics the receptacle show behaviour for xml requests. We also have a disambiguation page to handle links in from NPG, until they update to use the receptacles endpoint. Again, we’re still getting activity here, so it looks like that hasn’t happened yet. print_labels: This is used by the PhiX tubes created in the PhiX::SpikedBuffersController and PhiX::StocksController. It doesn’t belong here. lookup: I can’t find any links to this page, and it doesn’t appear to have been used recently. However our logs don’t go back all that far. Provides a page for scanning in barcodes. It appears to be supposed to redirect to the labware page, but it blows up for tubes and shows the qc information for plates.
Constant Summary
Constants included from FlashTruncation
FlashTruncation::STRING_OVERHEAD
Instance Method Summary collapse
-
#lookup ⇒ Object
JG 23/12/2020: I can’t find any links to this page, and think we can probably lose it.
-
#print_labels ⇒ Object
TODO: This is currently used from the PhiX::SpikedBuffersController and PhiX::StocksController show pages.
-
#show ⇒ Object
rubocop:todo Metrics/PerceivedComplexity, Metrics/AbcSize.
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
#lookup ⇒ Object
JG 23/12/2020: I can’t find any links to this page, and think we can probably lose it.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/assets_controller.rb', line 62 def lookup # rubocop:todo Metrics/AbcSize, Metrics/MethodLength if params[:asset] && params[:asset][:barcode] @assets = Labware.(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 |
#print_labels ⇒ Object
TODO: This is currently used from the PhiX::SpikedBuffersController and PhiX::StocksController show pages. It doesn’t really belong here.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/assets_controller.rb', line 49 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..join('; ') end redirect_to phi_x_url end |
#show ⇒ Object
rubocop:todo Metrics/PerceivedComplexity, Metrics/AbcSize
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/assets_controller.rb', line 20 def show # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength # 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 |