Class: ReceptaclesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ReceptaclesController
- Defined in:
- app/controllers/receptacles_controller.rb
Overview
View information about Receptacle
Constant Summary
Constants included from FlashTruncation
FlashTruncation::STRING_OVERHEAD
Instance Method Summary collapse
- #close ⇒ Object
-
#create_request ⇒ Object
rubocop:todo Metrics/MethodLength.
- #edit ⇒ Object
- #history ⇒ Object
-
#index ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength.
-
#lookup ⇒ Object
rubocop:enable Metrics/MethodLength.
- #new_request ⇒ Object
- #print ⇒ Object
- #print_assets ⇒ Object
- #print_labels ⇒ Object
-
#show ⇒ Object
rubocop:todo Metrics/MethodLength.
- #show_plate ⇒ Object
- #summary ⇒ Object
-
#update ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength.
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
#close ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/receptacles_controller.rb', line 77 def close @asset.closed = !@asset.closed @asset.save respond_to do |format| flash[:notice] = @asset.closed ? "Receptacle #{@asset.name} was closed." : "Receptacle #{@asset.name} was opened." format.html { redirect_to(receptacle_path(@asset)) } format.xml { head :ok } end end |
#create_request ⇒ Object
rubocop:todo Metrics/MethodLength
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/controllers/receptacles_controller.rb', line 141 def create_request # rubocop:todo Metrics/AbcSize @request_type = RequestType.find(params[:request_type_id]) @study = Study.find(params[:study_id]) if params[:cross_study_request].blank? @project = Project.find(params[:project_id]) if params[:cross_project_request].blank? = params.fetch(:request, {}).fetch(:request_metadata_attributes, {}) [:multiplier] = { @request_type.id => params[:count].to_i } if params[:count].present? submission = Submission.new(priority: params[:priority], name: @study.try(:name), user: current_user) # Despite its name, this is actually an order. resubmission_order = ReRequestSubmission.new( study: @study, project: @project, user: current_user, assets: [@asset], request_types: [@request_type.id], request_options: .to_unsafe_h, submission: submission, comments: params[:comments] ) resubmission_order.save! submission.built! respond_to do |format| flash[:notice] = 'Created request' format.html { redirect_to receptacle_path(@asset) } format.json { render json: submission.requests, status: :created } end rescue Submission::ProjectValidation::Error, ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid => e respond_to do |format| # Using 'flash' instead of 'flash.now' to ensure the message persists after the redirect. # See: https://guides.rubyonrails.org/action_controller_overview.html#the-flash flash[:error] = e..truncate(2000, separator: ' ') format.html { redirect_to new_request_for_current_asset } format.json { render json: e., status: :unprocessable_entity } end end |
#edit ⇒ Object
47 48 49 |
# File 'app/controllers/receptacles_controller.rb', line 47 def edit @valid_purposes_options = @asset.compatible_purposes.pluck(:name, :id) end |
#history ⇒ Object
51 52 53 |
# File 'app/controllers/receptacles_controller.rb', line 51 def history respond_to { |format| format.html } end |
#index ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/receptacles_controller.rb', line 12 def index # rubocop:todo Metrics/AbcSize, Metrics/MethodLength if params[:study_id] @study = Study.find(params[:study_id]) @assets = @study.assets_through_aliquots.order(created_at: :desc).page(params[:page]) else @assets = Receptacle.page(params[:page]) end respond_to do |format| format.html if params[:study_id] format.xml { render xml: @study.assets_through_requests.to_xml } elsif params[:sample_id] format.xml { render xml: Sample.find(params[:sample_id]).assets.to_xml } end end end |
#lookup ⇒ Object
rubocop:enable Metrics/MethodLength
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/controllers/receptacles_controller.rb', line 183 def lookup # rubocop:todo Metrics/AbcSize, Metrics/MethodLength return unless params[:asset] && params[:asset][:barcode] @assets = Labware.(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 |
#new_request ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/receptacles_controller.rb', line 124 def new_request @request_types = RequestType.standard.active.applicable_for_asset(@asset) # In rare cases the user links in to the 'new request' page # with a specific study specified. In even rarer cases this may # conflict with the assets primary study. # ./features/7711055_new_request_links_broken.feature:29 # This resolves the issue, but the code could do with a significant # refactor. I'm delaying this currently as we NEED to get SS434 completed. # 1. This should probably be RequestsController::new # 2. We should use Request.new(...) and form helpers # 3. This will allow us to instance_variable_or_id_param helpers. @study = params[:study_id] ? Study.find(params[:study_id]) : @asset.studies.first @project = @asset.projects.first || @asset.studies.first&.projects&.first end |
#print ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/receptacles_controller.rb', line 87 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 receptacle_path(@asset) end end |
#print_assets ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/receptacles_controller.rb', line 109 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..join('; ') end redirect_to receptacle_path(@asset) end |
#print_labels ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/receptacles_controller.rb', line 97 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/MethodLength
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/receptacles_controller.rb', line 30 def show # rubocop:todo Metrics/MethodLength @page_name = @asset.display_name @source_plates = @asset.source_plates respond_to do |format| format.html do @aliquots = if @asset.is_a?(AliquotIndexer::Indexable) @asset.aliquots.include_summary # NPG Aliquot Indexing else @asset.aliquots.include_summary.paginate(page: params[:page], per_page: 384) end end format.xml format.json { render json: @asset } end end |
#show_plate ⇒ Object
119 120 121 122 |
# File 'app/controllers/receptacles_controller.rb', line 119 def show_plate @asset = Plate.find(params[:id]) @page_name = @asset.display_name end |
#summary ⇒ Object
72 73 74 75 |
# File 'app/controllers/receptacles_controller.rb', line 72 def summary @summary = UiHelper::Summary.new(per_page: 25, page: params[:page]) @summary.load_asset(@asset) end |
#update ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/receptacles_controller.rb', line 55 def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength respond_to do |format| if @asset.update(asset_params.merge(params.to_unsafe_h.fetch(:lane, {}))) flash[:notice] = 'Receptacle was successfully updated.' if params[:lab_view] format.html { redirect_to(action: :lab_view, barcode: @asset.) } 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 |