Class: SampleManifestUploadWithTagSequencesController

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

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



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/sample_manifest_upload_with_tag_sequences_controller.rb', line 9

def create
  if params[:upload].present?
    @uploader = create_uploader

    if @uploader.run!
      success('Sample manifest successfully uploaded.')
    else
      error('Your sample manifest couldn\'t be uploaded.')
    end
  else
    error('No file attached')
  end
end

#create_uploaderObject



23
24
25
# File 'app/controllers/sample_manifest_upload_with_tag_sequences_controller.rb', line 23

def create_uploader
  SampleManifest::Uploader.new(params[:upload], SampleManifestExcel.configuration, current_user, params[:override])
end

#error(message) ⇒ Object



34
35
36
37
38
# File 'app/controllers/sample_manifest_upload_with_tag_sequences_controller.rb', line 34

def error(message)
  flash.now[:error] = message
  prepare_manifest_pagination
  render :new
end

#newObject



5
6
7
# File 'app/controllers/sample_manifest_upload_with_tag_sequences_controller.rb', line 5

def new
  prepare_manifest_pagination
end

#prepare_manifest_paginationObject

rubocop:todo Metrics/MethodLength



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/sample_manifest_upload_with_tag_sequences_controller.rb', line 40

def prepare_manifest_pagination # rubocop:todo Metrics/MethodLength
  pending_sample_manifests =
    SampleManifest
      .pending_manifests
      .includes(:study, :supplier, :user, :uploaded_document)
      .paginate(page: params[:page])
  completed_sample_manifests =
    SampleManifest
      .completed_manifests
      .includes(:study, :supplier, :user, :uploaded_document)
      .paginate(page: params[:page])
  @display_manifests = pending_sample_manifests | completed_sample_manifests
  @sample_manifests = SampleManifest.paginate(page: params[:page])
end

#success(message) ⇒ Object



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

def success(message)
  flash[:notice] = message
  redirect_target = (@uploader.study.present? ? sample_manifests_study_path(@uploader.study) : sample_manifests_path)

  redirect_to redirect_target
end