Class: AssetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/assets_controller.rb,
app/controllers/assets/plate_layout.rb

Defined Under Namespace

Classes: PlateLayout

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Instance Method Details

#closeObject


97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/assets_controller.rb', line 97

def close
  @asset.closed = !@asset.closed
  @asset.save
  respond_to do |format|
    if @asset.closed
      flash[:notice] = "Asset #{@asset.name} was closed."
    else
      flash[:notice] = "Asset #{@asset.name} was opened."
    end
    format.html { redirect_to(asset_url(@asset)) }
    format.xml  { head :ok }
  end
end

#editObject


56
57
58
# File 'app/controllers/assets_controller.rb', line 56

def edit
  @valid_purposes_options = @asset.compatible_purposes.pluck(:name, :id)
end

#historyObject


60
61
62
63
64
65
66
# File 'app/controllers/assets_controller.rb', line 60

def history
  respond_to do |format|
    format.html
    format.xml  { @request.events.to_xml }
    format.json { @request.events.to_json }
  end
end

#indexObject


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

def index
  if params[:study_id]
    @study = Study.find(params[:study_id])
    @assets = @study.assets_through_aliquots.order(:name).page(params[:page])
  else
    @assets = Asset.page(params[:page])
  end

  respond_to do |format|
    format.html
    if params[:study_id]
      format.xml { render xml: Study.find(params[:study_id]).assets_through_requests.to_xml }
    elsif params[:sample_id]
      format.xml { render xml: Sample.find(params[:sample_id]).assets.to_xml }
    elsif params[:asset_id]
      @asset = Asset.find(params[:asset_id])
      format.xml { render xml: ['relations' => { 'parents' => @asset.parents, 'children' => @asset.children }].to_xml }
    end
  end
end

#lookupObject


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/controllers/assets_controller.rb', line 150

def lookup
  if params[:asset] && params[:asset][:barcode]
    @assets = Labware.with_barcode(params[:asset][:barcode]).limit(50).page(params[:page])

    if @assets.size == 1
      redirect_to @assets.first
    elsif @assets.size == 0
      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
end

111
112
113
114
115
116
117
118
119
# File 'app/controllers/assets_controller.rb', line 111

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 asset_path(@asset)
  end
end

134
135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/assets_controller.rb', line 134

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.full_messages.join('; ')
  end
  redirect_to asset_url(@asset)
end

121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/controllers/assets_controller.rb', line 121

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.full_messages.join('; ')
  end

  redirect_to phi_x_url
end

#reset_values_for_moveObject


171
172
173
# File 'app/controllers/assets_controller.rb', line 171

def reset_values_for_move
  render layout: false
end

#showObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/assets_controller.rb', line 29

def show
  # This block is disabled when we have the labware table present as part of the AssetRefactor
  # Ie. This is what will happens now
  # LEGACY API FOR CGP to allow switch-over
  AssetRefactor.when_not_refactored do
    next unless request.format.xml?

    @asset = Asset.include_for_show.find(params[:id])
    respond_to { |format| format.xml }
    return
  end

  @labware = Labware.find_by(id: params[:id])
  @receptacle = Receptacle.find_by(id: params[:id])

  if @receptacle.nil? && @labware.nil?
    raise ActiveRecord::RecordNotFound
  elsif @labware.nil? || @labware.try(:receptacle) == (@receptacle || :none)
    redirect_to receptacle_path(@receptacle)
  elsif @receptacle.nil? && @labware.present?
    redirect_to labware_path(@labware)
  else
    # Things are ambiguous, we'll make you select
    render :show, status: :multiple_choices
  end
end

#show_plateObject


146
147
148
# File 'app/controllers/assets_controller.rb', line 146

def show_plate
  @asset = Plate.find(params[:id])
end

#summaryObject


92
93
94
95
# File 'app/controllers/assets_controller.rb', line 92

def summary
  @summary = UiHelper::Summary.new(per_page: 25, page: params[:page])
  @summary.load_asset(@asset)
end

#updateObject


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/assets_controller.rb', line 68

def update
  respond_to do |format|
    if @asset.update(asset_params.merge(params.to_unsafe_h.fetch(:lane, {})))
      flash[:notice] = 'Asset was successfully updated.'
      if params[:lab_view]
        format.html { redirect_to(action: :lab_view, barcode: @asset.human_barcode) }
      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