Class: CollectionObjectsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/collection_objects_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) autocomplete



122
123
124
125
126
127
128
# File 'app/controllers/collection_objects_controller.rb', line 122

def autocomplete
  @collection_objects =
    Queries::CollectionObject::Autocomplete.new(
      params[:term],
      project_id: sessions_current_project_id
  ).autocomplete
end

- (Object) batch_load

GET collection_objects/batch_load



136
137
# File 'app/controllers/collection_objects_controller.rb', line 136

def batch_load
end

- (Object) batch_params (private)



245
246
247
248
# File 'app/controllers/collection_objects_controller.rb', line 245

def batch_params
  params.permit(:file, :import_level, :source_id, :otu_id)
      .merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).to_h.symbolize_keys
end

- (Object) by_identifier

GET /collection_objects/by_identifier/ABCD

Raises:

  • (ActiveRecord::RecordNotFound)


48
49
50
51
52
53
54
# File 'app/controllers/collection_objects_controller.rb', line 48

def by_identifier
  @identifier = params.require(:identifier)
  @request_project_id = sessions_current_project_id
  @collection_objects = CollectionObject.with_identifier(@identifier).where(project_id: @request_project_id).all

  raise ActiveRecord::RecordNotFound if @collection_objects.empty?
end

- (Object) collection_object_params (private)



233
234
235
236
237
238
239
240
241
242
243
# File 'app/controllers/collection_objects_controller.rb', line 233

def collection_object_params
  params.require(:collection_object).permit(
    :total, :preparation_type_id, :repository_id,
    :ranged_lot_category_id, :collecting_event_id,
    :buffered_collecting_event, :buffered_determinations,
    :buffered_other_labels, :deaccessioned_at, :deaccession_reason,
    :contained_in,
    collecting_event_attributes: [],  # needs to be filled out!
    data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :attribute_subject_id, :attribute_subject_type, :value ]
  )
end

- (Object) containerize



166
167
168
# File 'app/controllers/collection_objects_controller.rb', line 166

def containerize
  @container_item = ContainerItem.new(contained_object: @collection_object)
end

- (Object) create

POST /collection_objects POST /collection_objects.json



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/collection_objects_controller.rb', line 67

def create
  @collection_object = CollectionObject.new(collection_object_params)

  respond_to do |format|
    if @collection_object.save
      format.html { redirect_to url_for(@collection_object.metamorphosize), notice: 'Collection object was successfully created.' }
      format.json { render action: 'show', status: :created, location: @collection_object.metamorphosize }
    else
      format.html { render action: 'new' }
      format.json { render json: @collection_object.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) create_buffered_batch_load



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'app/controllers/collection_objects_controller.rb', line 207

def create_buffered_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :Buffered_collection_objects_md5)
    @result = BatchLoad::Import::CollectionObjects::BufferedInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} items were created."
      render 'collection_objects/batch_load/buffered/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :batch_load
end

- (Object) create_castor_batch_load



181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'app/controllers/collection_objects_controller.rb', line 181

def create_castor_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :Castor_collection_objects_md5)
    @result = BatchLoad::Import::CollectionObjects::CastorInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} items were created."
      render 'collection_objects/batch_load/castor/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :batch_load
end

- (Object) create_simple_batch_load



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/controllers/collection_objects_controller.rb', line 150

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile,
                                              :batch_collection_objects_md5)
    @result = BatchLoad::Import::CollectionObjects.new(batch_params.merge(user_map))
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} collection object-related object-sets were created."
      render 'collection_objects/batch_load/simple/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :batch_load
end

- (Object) depictions

GET /collection_objects/depictions/1 GET /collection_objects/depictions/1.json



31
32
# File 'app/controllers/collection_objects_controller.rb', line 31

def depictions
end

- (Object) destroy

DELETE /collection_objects/1 DELETE /collection_objects/1.json



98
99
100
101
102
103
104
# File 'app/controllers/collection_objects_controller.rb', line 98

def destroy
  @collection_object.destroy
  respond_to do |format|
    format.html { redirect_to collection_objects_url, notice: 'Collection object was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /collection_objects/download



131
132
133
# File 'app/controllers/collection_objects_controller.rb', line 131

def download
  send_data Download.generate_csv(CollectionObject.where(project_id: sessions_current_project_id), header_converters: []), type: 'text', filename: "collection_objects_#{DateTime.now}.csv"
end

- (Object) edit

GET /collection_objects/1/edit



62
63
# File 'app/controllers/collection_objects_controller.rb', line 62

def edit
end

- (Object) filter_params (private)



262
263
264
# File 'app/controllers/collection_objects_controller.rb', line 262

def filter_params
  params.permit(:recent)
end

- (Object) geo_json

GET /collection_objects/1/geo_json GET /collection_objects/1/geo_json.json



42
43
44
45
# File 'app/controllers/collection_objects_controller.rb', line 42

def geo_json
  ce = @collection_object.collecting_event
  @geo_json = ce.nil? ? nil : ce.to_geo_json_feature
end

- (Object) images

GET /collection_objects/1/images GET /collection_objects/1/images.json



36
37
38
# File 'app/controllers/collection_objects_controller.rb', line 36

def images
  @images = @collection_object.images
end

- (Object) index

GET /collecting_events GET /collecting_events.json



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

def index
  respond_to do |format|
    format.html do
      @recent_objects = CollectionObject.recent_from_project_id(sessions_current_project_id)
        .order(updated_at: :desc)
        .includes(:identifiers, :taxon_determinations)
        .limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @collection_objects = Queries::CollectionObject::Filter.new(filter_params).all.page(params[:page]).per(params[:per] || 500)
    }
  end
end

- (Object) list

GET /collection_objects/list



107
108
109
110
111
# File 'app/controllers/collection_objects_controller.rb', line 107

def list
  @collection_objects = CollectionObject.with_project_id(sessions_current_project_id)
    .order(:id)
    .page(params[:page]) #.per(10) #.per(3)
end

- (Object) new

GET /collection_objects/new



57
58
59
# File 'app/controllers/collection_objects_controller.rb', line 57

def new
  @collection_object = CollectionObject.new
end

- (Object) preview_buffered_batch_load



196
197
198
199
200
201
202
203
204
205
# File 'app/controllers/collection_objects_controller.rb', line 196

def preview_buffered_batch_load
  if params[:file]
    @result = BatchLoad::Import::CollectionObjects::BufferedInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :Buffered_collection_objects_md5)
    render 'collection_objects/batch_load/buffered/preview'
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

- (Object) preview_castor_batch_load



170
171
172
173
174
175
176
177
178
179
# File 'app/controllers/collection_objects_controller.rb', line 170

def preview_castor_batch_load
  if params[:file]
    @result = BatchLoad::Import::CollectionObjects::CastorInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :Castor_collection_objects_md5)
    render 'collection_objects/batch_load/castor/preview'
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

- (Object) preview_simple_batch_load



139
140
141
142
143
144
145
146
147
148
# File 'app/controllers/collection_objects_controller.rb', line 139

def preview_simple_batch_load
  if params[:file]
    @result = BatchLoad::Import::CollectionObjects.new(batch_params.merge(user_map))
    digest_cookie(params[:file].tempfile, :batch_collection_objects_md5)
    render 'collection_objects/batch_load/simple/preview'
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

- (Object) search

GET /collection_object/search



114
115
116
117
118
119
120
# File 'app/controllers/collection_objects_controller.rb', line 114

def search
  if params[:id].blank?
    redirect_to collection_object_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to collection_object_path(params[:id])
  end
end

- (Object) select_options



222
223
224
# File 'app/controllers/collection_objects_controller.rb', line 222

def select_options
  @collection_objects = CollectionObject.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target])
end

- (Object) set_collection_object (private)



228
229
230
231
# File 'app/controllers/collection_objects_controller.rb', line 228

def set_collection_object
  @collection_object = CollectionObject.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object     = @collection_object
end

- (Object) show

GET /collection_objects/1 GET /collection_objects/1.json



26
27
# File 'app/controllers/collection_objects_controller.rb', line 26

def show
end

- (Object) update

PATCH/PUT /collection_objects/1 PATCH/PUT /collection_objects/1.json



83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/collection_objects_controller.rb', line 83

def update
  respond_to do |format|
    if @collection_object.update(collection_object_params)
      @collection_object = @collection_object.metamorphosize
      format.html { redirect_to url_for(@collection_object), notice: 'Collection object was successfully updated.' }
      format.json { render :show, status: :ok, location: @collection_object }
    else
      format.html { render action: 'edit' }
      format.json { render json: @collection_object.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) user_map (private)



250
251
252
253
254
255
256
257
258
259
260
# File 'app/controllers/collection_objects_controller.rb', line 250

def user_map
  {
    user_header_map: {
      'otu'         => 'otu_name',
      'start_day'   => 'start_date_day',
      'start_month' => 'start_date_month',
      'start_year'  => 'start_date_year',
      'end_day'     => 'end_date_day',
      'end_month'   => 'end_date_month',
      'end_year'    => 'end_date_year'}}
end