Class: PlateTemplatesController

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

Overview

rubocop:todo Style/Documentation

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #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


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/plate_templates_controller.rb', line 26

def create
  if params[:name].blank?
    flash[:error] = 'Please enter a name'
    redirect_to new_plate_template_path
    return
  end

  pattern = PlateTemplate.new
  pattern.update_params!(name: params[:name], user_id: current_user.id, wells: params[:empty_well],
                         rows: params[:rows], cols: params[:cols])
  flash[:notice] = 'Template saved'
  redirect_to plate_templates_path
end

#destroyObject


54
55
56
57
58
59
60
61
# File 'app/controllers/plate_templates_controller.rb', line 54

def destroy
  pattern = PlateTemplate.find(params[:id])
  pattern.destroy

  respond_to do |format|
    format.html { redirect_to(plate_templates_path) }
  end
end

#editObject


40
41
42
43
44
# File 'app/controllers/plate_templates_controller.rb', line 40

def edit
  @pattern = PlateTemplate.find(params[:id])
  @plate_rows = Map::Coordinate.plate_length(@pattern.size)
  @plate_cols = Map::Coordinate.plate_width(@pattern.size)
end

#indexObject


7
8
9
# File 'app/controllers/plate_templates_controller.rb', line 7

def index
  @patterns = PlateTemplate.paginate(page: params[:page], per_page: 50)
end

#newObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/plate_templates_controller.rb', line 11

def new
  @plate_rows = params[:rows].to_i
  @plate_cols = params[:cols].to_i
  if @plate_rows == 0
    @plate_rows = Map::Coordinate.plate_length(96)
  end
  if @plate_cols == 0
    @plate_cols = Map::Coordinate.plate_width(96)
  end

  respond_to do |format|
    format.html # new.html.erb
  end
end

#updateObject


46
47
48
49
50
51
52
# File 'app/controllers/plate_templates_controller.rb', line 46

def update
  pattern = PlateTemplate.find(params[:id])
  pattern.update_params!(name: params[:name], user_id: current_user.id, wells: params[:empty_well],
                         rows: params[:rows], cols: params[:cols])
  flash[:notice] = 'Template updated'
  redirect_to plate_templates_path
end