Class: BulkSubmissionExcel::DownloadsController

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

Overview

Generate a bulk submission excel template from basic user provided data

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


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/bulk_submission_excel/downloads_controller.rb', line 6

def create # rubocop:todo Metrics/AbcSize
  finder = Asset::Finder.new(submission_parameters.fetch(:asset_barcodes, '').split(/\s+/))
  download =
    BulkSubmissionExcel::Download.new(
      column_list: BulkSubmissionExcel.configuration.columns.all,
      range_list: BulkSubmissionExcel.configuration.ranges,
      defaults: params[:defaults],
      assets: finder.resolve
    )
  file = Tempfile.new
  download.save(file)
  send_file file.path,
            content_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            filename: "#{finder.barcodes.join('_')}_#{Time.current.strftime('%Y%m%d')}.xlsx"
rescue Asset::Finder::InvalidInputException => e
  flash[:error] = e.message
  redirect_back fallback_location: bulk_submissions_path
ensure
  file&.close
end

#newObject


27
28
29
30
31
32
# File 'app/controllers/bulk_submission_excel/downloads_controller.rb', line 27

def new
  @submission_template = SubmissionTemplate.find_by(id: params[:submission_template_id])
  @input_field_infos = @submission_template&.input_field_infos || []
  @input_field_infos.reject! { |k| k.key == :customer_accepts_responsibility }
  render 'new', layout: !request.xhr?
end

#submission_parametersObject


34
35
36
# File 'app/controllers/bulk_submission_excel/downloads_controller.rb', line 34

def submission_parameters
  params.require(:bulk_submission_excel_download).permit(:asset_barcodes)
end