Class: Studies::AssetGroupsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/studies/asset_groups_controller.rb

Overview

rubocop:todo Metrics/ClassLength

Instance Method Summary collapse

Instance Method Details

#addObject

rubocop:enable Metrics/MethodLength



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/studies/asset_groups_controller.rb', line 111

def add # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  @asset_group = AssetGroup.find(params[:id])
  @study = Study.find(params[:study_id])
  if params[:asset]
    ids = params[:asset].select { |_asset_id, checked| checked == '1' }.keys
    @assets = Asset.find(ids)
    @asset_group.assets << @assets
  end

  respond_to do |format|
    format.html { redirect_to(study_asset_group_url(@study, @asset_group)) }
    format.xml { render xml: @assets }
    format.json { render json: @assets }
  end
end

#createObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/studies/asset_groups_controller.rb', line 43

def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  @study = Study.find(params[:study_id])
  @asset_group = AssetGroup.new(params[:asset_group])
  @asset_group.study = @study

  respond_to do |format|
    if @asset_group.save
      flash[:notice] = 'AssetGroup was successfully created.'
      format.html { redirect_to study_asset_group_path(@study, @asset_group) }
      format.xml { render xml: @asset_group, status: :created, location: @asset_group }
      format.json { render json: @asset_group, status: :created, location: @asset_group }
    else
      format.html { render action: 'new' }
      format.xml { render xml: @asset_group.errors, status: :unprocessable_entity }
      format.json { render json: @asset_group.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject



78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/studies/asset_groups_controller.rb', line 78

def destroy
  @asset_group = AssetGroup.find(params[:id])
  @asset_group.destroy
  @study = Study.find(params[:study_id])

  respond_to do |format|
    format.html { redirect_to(study_asset_groups_url(@study)) }
    format.xml { head :ok }
  end
end

#editObject



38
39
40
41
# File 'app/controllers/studies/asset_groups_controller.rb', line 38

def edit
  @asset_group = AssetGroup.find(params[:id])
  @study = Study.find(params[:study_id])
end

#indexObject



8
9
10
11
12
13
14
15
16
# File 'app/controllers/studies/asset_groups_controller.rb', line 8

def index
  @study = Study.find(params[:study_id])
  @asset_groups = @study.asset_groups

  respond_to do |format|
    format.html # index.html.erb
    format.xml { render xml: @asset_groups }
  end
end

#newObject



28
29
30
31
32
33
34
35
36
# File 'app/controllers/studies/asset_groups_controller.rb', line 28

def new
  @asset_group = AssetGroup.new
  @study = Study.find(params[:study_id])

  respond_to do |format|
    format.html # new.html.erb
    format.xml { render xml: @asset_group }
  end
end


132
133
134
135
136
137
# File 'app/controllers/studies/asset_groups_controller.rb', line 132

def print
  @asset_group = AssetGroup.find(params[:id])
  @study = Study.find(params[:study_id])

  @labware = @asset_group.labware.select { |asset| asset.is_a?(Barcode::Barcodeable) }
end

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/controllers/studies/asset_groups_controller.rb', line 139

def print_labels # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  @asset_group = AssetGroup.find(params[:id])
  @study = Study.find(params[:study_id])

  print_job =
    LabelPrinter::PrintJob.new(params[:printer], LabelPrinter::Label::AssetRedirect, printables: params[:printables])
  if print_job.execute
    flash[:notice] = print_job.success
    redirect_to study_asset_groups_path(@study)
  else
    flash[:error] = print_job.errors.full_messages.join('; ')
    redirect_to print_study_asset_group_path(@study, @asset_group)
  end
end

#printingObject



127
128
129
130
# File 'app/controllers/studies/asset_groups_controller.rb', line 127

def printing
  @study = Study.find(params[:study_id])
  @asset_groups = @study.asset_groups
end

#searchObject

rubocop:todo Metrics/MethodLength



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/studies/asset_groups_controller.rb', line 90

def search # rubocop:todo Metrics/AbcSize
  @study = Study.find(params[:study_id])
  query = params[:q]
  if query.blank? || (query.length < 2)
    # We should not blame the user, we should instead help.
    # - By returning the X most recent ones together with an explanation.
    flash[:error] = 'Search too wide. Please make your query more specific.'
    redirect_to study_asset_groups_path(@study)
    return
  else
    @assets = Labware.where(['name like ?', "%#{query}%"])
  end
  @asset_group = AssetGroup.find(params[:id])
  respond_to do |format|
    format.html # index.html.erb
    format.xml { render xml: @assets }
  end
end

#showObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/studies/asset_groups_controller.rb', line 18

def show
  @asset_group = AssetGroup.find(params[:id])
  @study = Study.find(params[:study_id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml { render xml: @asset_group }
  end
end

#updateObject

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/studies/asset_groups_controller.rb', line 62

def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  @asset_group = AssetGroup.find(params[:id])
  @study = Study.find(params[:study_id])

  respond_to do |format|
    if @asset_group.update(params[:asset_group])
      flash[:notice] = 'AssetGroup was successfully updated.'
      format.html { redirect_to study_asset_group_path(@study, @asset_group) }
      format.xml { head :ok }
    else
      format.html { render action: 'edit' }
      format.xml { render xml: @asset_group.errors, status: :unprocessable_entity }
    end
  end
end