Class: LocationReportsController

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

Overview

This class handles creating and viewing Location Reports, which match up plates to their recorded physical location, and to their Studies and Faculty Sponser (can be multiple per plate). These reports are used by the Sample Management team to manage storage space in freezers and to locate old plates for return to their owners or disposal.

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

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

#createObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/location_reports_controller.rb', line 30

def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  @location_report_form = LocationReport::LocationReportForm.new(location_report_params)
  @location_report_form.user = @current_user

  respond_to do |format|
    if @location_report_form.save
      flash[:notice] = I18n.t('location_reports.success')
      format.html { redirect_to location_reports_path }
    else
      error_messages = @location_report_form.errors.full_messages.join('; ')
      flash.now[:error] = "Failed to create report: #{error_messages}"
      @location_reports = LocationReport.order(id: :desc).page(params[:page])
      format.html { render action: 'index' }
    end
  end
end

#indexObject



11
12
13
14
15
16
17
# File 'app/controllers/location_reports_controller.rb', line 11

def index
  @location_reports = LocationReport.order(id: :desc).page(params[:page])
  @location_report_form = LocationReport::LocationReportForm.new
  @location_report_form.user = @current_user

  respond_to { |format| format.html }
end

#showObject



19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/location_reports_controller.rb', line 19

def show
  @location_report = LocationReport.find(params[:id])

  send_data(
    @location_report.report.read,
    type: 'text/plain',
    filename: "location_report_#{@location_report.name}.csv",
    disposition: 'attachment'
  )
end