Class: CollectionObjectsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CollectionObjectsController
- Defined in:
- app/controllers/collection_objects_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #after_destroy_path ⇒ Object private
- #api_autocomplete ⇒ Object
-
#api_dwc ⇒ Object
GET /api/v1/collection_objects/123/dwc.
-
#api_index ⇒ Object
GET /api/v1/collection_objects.
-
#api_show ⇒ Object
GET /api/v1/collection_objects/:id.
- #autocomplete ⇒ Object
-
#batch_load ⇒ Object
GET collection_objects/batch_load.
- #batch_params ⇒ Object private
- #biocuration_classifications ⇒ Object
-
#by_identifier ⇒ Object
GET /collection_objects/by_identifier/ABCD TODO: remove for filter.
- #collection_object_params ⇒ Object private
- #containerize ⇒ Object
-
#create ⇒ Object
POST /collection_objects POST /collection_objects.json.
- #create_buffered_batch_load ⇒ Object
- #create_castor_batch_load ⇒ Object
- #create_simple_batch_load ⇒ Object
-
#depictions ⇒ Object
GET /collection_objects/depictions/1 GET /collection_objects/depictions/1.html This is.
-
#destroy ⇒ Object
DELETE /collection_objects/1 DELETE /collection_objects/1.json.
-
#download ⇒ Object
GET /collection_objects/download.
-
#dwc ⇒ Object
GET /collection_objects/123/dwc.
-
#dwc_index ⇒ Object
Render DWC fields only.
-
#dwc_verbose ⇒ Object
GET /collection_objects/123/dwc_verbose.
-
#dwca ⇒ Object
DEPRECATED GET /collection_objects/dwca/123 # SHOULD BE dwc.
-
#edit ⇒ Object
GET /collection_objects/1/edit.
-
#geo_json ⇒ Object
TODO: render in view GET /collection_objects/1/geo_json GET /collection_objects/1/geo_json.json.
-
#images ⇒ Object
GET /collection_objects/1/inventory/images.html GET /collection_objects/1/images.json.
-
#index ⇒ Object
GET /collecting_events GET /collecting_events.json.
-
#index_metadata ⇒ Object
/collection_objects/index_metadata/.json.
-
#list ⇒ Object
GET /collection_objects/list.
- #metadata_badge ⇒ Object
-
#metadata_index(models = {}) ⇒ Object
TODO: probably some deep clean TODO: Move.
- #navigation ⇒ Object
-
#new ⇒ Object
GET /collection_objects/new.
-
#preview ⇒ Object
/collection_objects/preview?<filter params>.
- #preview_buffered_batch_load ⇒ Object
- #preview_castor_batch_load ⇒ Object
- #preview_simple_batch_load ⇒ Object
-
#report ⇒ Object
Intent is DWC fields + quick summary fields for reports !! As currently implemented rebuilds DWC all.
-
#search ⇒ Object
GET /collection_object/search.
- #select_options ⇒ Object
- #set_collection_object ⇒ Object private
-
#show ⇒ Object
GET /collection_objects/1 GET /collection_objects/1.json.
-
#timeline ⇒ Object
GET /collection_objects/1/timeline.json.
-
#update ⇒ Object
PATCH/PUT /collection_objects/1 PATCH/PUT /collection_objects/1.json.
-
#user_map ⇒ Object
private
TODO: not used?.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#after_destroy_path ⇒ Object (private)
391 392 393 394 395 396 397 398 399 400 401 |
# File 'app/controllers/collection_objects_controller.rb', line 391 def after_destroy_path if request.referer =~ /tasks\/collection_objects\/browse/ if o = @collection_object.next_by_identifier browse_collection_objects_path(collection_object_id: o.id) else browse_collection_objects_path end else collection_objects_path end end |
#api_autocomplete ⇒ Object
375 376 377 378 379 |
# File 'app/controllers/collection_objects_controller.rb', line 375 def api_autocomplete render json: {} and return if params[:term].blank? @collection_objects = ::Queries::CollectionObject::Autocomplete.new(params[:term], project_id: sessions_current_project_id).autocomplete render '/collection_objects/api/v1/autocomplete' end |
#api_dwc ⇒ Object
GET /api/v1/collection_objects/123/dwc
382 383 384 385 386 387 |
# File 'app/controllers/collection_objects_controller.rb', line 382 def api_dwc ActiveRecord::Base.connection_pool.with_connection do @collection_object.get_dwc_occurrence render json: @collection_object.dwc_occurrence_attributes end end |
#api_index ⇒ Object
GET /api/v1/collection_objects
362 363 364 365 366 367 368 |
# File 'app/controllers/collection_objects_controller.rb', line 362 def api_index @collection_objects = ::Queries::CollectionObject::Filter.new(params.merge!(api: true)).all .where(project_id: sessions_current_project_id) .order('collection_objects.id') .page(params[:page]).per(params[:per]) render '/collection_objects/api/v1/index' end |
#api_show ⇒ Object
GET /api/v1/collection_objects/:id
371 372 373 |
# File 'app/controllers/collection_objects_controller.rb', line 371 def api_show render '/collection_objects/api/v1/show' end |
#autocomplete ⇒ Object
353 354 355 356 357 358 359 |
# File 'app/controllers/collection_objects_controller.rb', line 353 def autocomplete @collection_objects = ::Queries::CollectionObject::Autocomplete.new( params[:term], project_id: sessions_current_project_id ).autocomplete end |
#batch_load ⇒ Object
GET collection_objects/batch_load
262 263 |
# File 'app/controllers/collection_objects_controller.rb', line 262 def batch_load end |
#batch_params ⇒ Object (private)
435 436 437 438 |
# File 'app/controllers/collection_objects_controller.rb', line 435 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 |
#biocuration_classifications ⇒ Object
69 70 71 72 |
# File 'app/controllers/collection_objects_controller.rb', line 69 def biocuration_classifications @biocuration_classifications = @collection_object.biocuration_classifications render '/biocuration_classifications/index' end |
#by_identifier ⇒ Object
GET /collection_objects/by_identifier/ABCD TODO: remove for filter
177 178 179 180 181 182 183 |
# File 'app/controllers/collection_objects_controller.rb', line 177 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 |
#collection_object_params ⇒ Object (private)
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'app/controllers/collection_objects_controller.rb', line 408 def collection_object_params params.require(:collection_object).permit( :total, :preparation_type_id, :repository_id, :current_repository_id, :ranged_lot_category_id, :collecting_event_id, :buffered_collecting_event, :buffered_determinations, :buffered_other_labels, :accessioned_at, :deaccessioned_at, :deaccession_reason, :contained_in, :taxon_determination_id, collecting_event_attributes: [], # needs to be filled out! data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :value ], tags_attributes: [:id, :_destroy, :keyword_id], identifiers_attributes: [ :id, :_destroy, :identifier, :namespace_id, :type, labels_attributes: [ :text, :type, :text_method, :total ] ] ) end |
#containerize ⇒ Object
293 294 295 |
# File 'app/controllers/collection_objects_controller.rb', line 293 def containerize @container_item = ContainerItem.new(contained_object: @collection_object) end |
#create ⇒ Object
POST /collection_objects POST /collection_objects.json
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'app/controllers/collection_objects_controller.rb', line 196 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.), notice: 'Collection object was successfully created.' } format.json { render action: 'show', status: :created, location: @collection_object. } else format.html { render action: 'new' } format.json { render json: @collection_object.errors, status: :unprocessable_entity } end end end |
#create_buffered_batch_load ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'app/controllers/collection_objects_controller.rb', line 334 def create_buffered_batch_load if params[:file] && (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 |
#create_castor_batch_load ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'app/controllers/collection_objects_controller.rb', line 308 def create_castor_batch_load if params[:file] && (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 |
#create_simple_batch_load ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'app/controllers/collection_objects_controller.rb', line 276 def create_simple_batch_load if params[:file] && ( 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 |
#depictions ⇒ Object
GET /collection_objects/depictions/1 GET /collection_objects/depictions/1.html This is
144 145 |
# File 'app/controllers/collection_objects_controller.rb', line 144 def depictions end |
#destroy ⇒ Object
DELETE /collection_objects/1 DELETE /collection_objects/1.json
227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'app/controllers/collection_objects_controller.rb', line 227 def destroy @collection_object.destroy respond_to do |format| if @collection_object.destroyed? format.html { redirect_to after_destroy_path, notice: 'CollectionObject was successfully destroyed.' } format.json { head :no_content } else format.html { destroy_redirect @collection_object, notice: 'CollectionObject was not destroyed, ' + @collection_object.errors..join('; ') } format.json { render json: @collection_object.errors, status: :unprocessable_entity } end end end |
#download ⇒ Object
GET /collection_objects/download
257 258 259 |
# File 'app/controllers/collection_objects_controller.rb', line 257 def download send_data Export::Download.generate_csv(CollectionObject.where(project_id: sessions_current_project_id), header_converters: []), type: 'text', filename: "collection_objects_#{DateTime.now}.csv" end |
#dwc ⇒ Object
GET /collection_objects/123/dwc
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/collection_objects_controller.rb', line 97 def dwc o = nil ActiveRecord::Base.connection_pool.with_connection do o = CollectionObject.find(params[:id]) if params[:rebuild] == 'true' # get does not rebuild, but does set if it doesn't exist o.set_dwc_occurrence else o.get_dwc_occurrence end # Default to *exclude* some fields that include large text, like geospatial mode = params[:mode] || :view render json: o.dwc_occurrence_attribute_values(mode) end end |
#dwc_index ⇒ Object
Render DWC fields only
85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/collection_objects_controller.rb', line 85 def dwc_index objects = ::Queries::CollectionObject::Filter.new(params).all.order('collection_objects.id').includes(:dwc_occurrence).page(params[:page]).per(params[:per]).all assign_pagination(objects) # Default to *exclude* some big fields, like geo-spatial wkt mode = params[:mode] || :view @objects = objects.pluck(*::CollectionObject.dwc_attribute_vector(mode)) @headers = ::CollectionObject.dwc_attribute_vector_names(mode) render '/dwc_occurrences/dwc_index' end |
#dwc_verbose ⇒ Object
GET /collection_objects/123/dwc_verbose
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/collection_objects_controller.rb', line 115 def dwc_verbose o = nil ActiveRecord::Base.connection_pool.with_connection do o = CollectionObject.find(params[:id]) if params[:rebuild] == 'true' # get does not rebuild o.set_dwc_occurrence else o.get_dwc_occurrence end end render json: o.dwc_occurrence_attributes end |
#dwca ⇒ Object
DEPRECATED GET /collection_objects/dwca/123 # SHOULD BE dwc
79 80 81 82 |
# File 'app/controllers/collection_objects_controller.rb', line 79 def dwca @dwc_occurrence = CollectionObject.includes(:dwc_occurrence).find(params[:id]).get_dwc_occurrence # find or compute for render json: @dwc_occurrence.to_json end |
#edit ⇒ Object
GET /collection_objects/1/edit
191 192 |
# File 'app/controllers/collection_objects_controller.rb', line 191 def edit end |
#geo_json ⇒ Object
TODO: render in view GET /collection_objects/1/geo_json GET /collection_objects/1/geo_json.json
170 171 172 173 |
# File 'app/controllers/collection_objects_controller.rb', line 170 def geo_json ce = @collection_object.collecting_event @geo_json = ce.nil? ? nil : ce.to_geo_json_feature end |
#images ⇒ Object
GET /collection_objects/1/inventory/images.html GET /collection_objects/1/images.json
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/controllers/collection_objects_controller.rb', line 152 def images @images = ::Queries::Image::Filter.new( collection_object_id: [ params.require(:id)], collection_object_scope: [:all] ) respond_to do |format| format.html { @images = @images.all } format.json do # rendered as Depictions for now @depictions = @iamges.derived_depictions render '/depictions/index' and return end end end |
#index ⇒ Object
GET /collecting_events GET /collecting_events.json
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/collection_objects_controller.rb', line 13 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(params).all .order('collection_objects.id') .page(params[:page]) .per(params[:per]) } end end |
#index_metadata ⇒ Object
/collection_objects/index_metadata/.json
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/collection_objects_controller.rb', line 32 def render json: ( { repository: Repository, current_respository: Repository, collecting_event: CollectingEvent, taxon_determinations: TaxonDetermination }) .merge( dwc_occurrence: DwcOccurrence.target_columns.inject({}){|hsh,p| hsh[p] = nil; hsh}.delete_if{|k,v| k =~ /(_id|_type)\z/} ) .merge( CollectionObject.core_attributes.inject({}){|hsh,p| hsh[p] = nil; hsh}) .merge( identifiers: nil, object_tag: nil, object_label: nil, ).delete_if{|k,v| k =~ /(_id|_type)\z/} end |
#list ⇒ Object
GET /collection_objects/list
241 242 243 244 245 |
# File 'app/controllers/collection_objects_controller.rb', line 241 def list @collection_objects = CollectionObject.with_project_id(sessions_current_project_id) .order(:id) .page(params[:page]) #.per(10) #.per(3) end |
#metadata_badge ⇒ Object
147 148 |
# File 'app/controllers/collection_objects_controller.rb', line 147 def end |
#metadata_index(models = {}) ⇒ Object
TODO: probably some deep clean TODO: Move
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/collection_objects_controller.rb', line 49 def (models = {}) h = {} models.each do |l, m| h.merge!( l => m.core_attributes.inject({}){|hsh,p| hsh[p] = nil; hsh} ) end h end |
#navigation ⇒ Object
74 75 |
# File 'app/controllers/collection_objects_controller.rb', line 74 def end |
#new ⇒ Object
GET /collection_objects/new
186 187 188 |
# File 'app/controllers/collection_objects_controller.rb', line 186 def new @collection_object = CollectionObject.new end |
#preview ⇒ Object
/collection_objects/preview?<filter params>
137 138 139 |
# File 'app/controllers/collection_objects_controller.rb', line 137 def preview @collection_objects = ::Queries::CollectionObject::Filter.new(params).all.order('collection_objects.id').includes(:dwc_occurrence).page(params[:page]).per(params[:per] || 500) end |
#preview_buffered_batch_load ⇒ Object
323 324 325 326 327 328 329 330 331 332 |
# File 'app/controllers/collection_objects_controller.rb', line 323 def preview_buffered_batch_load if params[:file] @result = BatchLoad::Import::CollectionObjects::BufferedInterpreter.new(**batch_params) (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 |
#preview_castor_batch_load ⇒ Object
297 298 299 300 301 302 303 304 305 306 |
# File 'app/controllers/collection_objects_controller.rb', line 297 def preview_castor_batch_load if params[:file] @result = BatchLoad::Import::CollectionObjects::CastorInterpreter.new(**batch_params) (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 |
#preview_simple_batch_load ⇒ Object
265 266 267 268 269 270 271 272 273 274 |
# File 'app/controllers/collection_objects_controller.rb', line 265 def preview_simple_batch_load if params[:file] @result = BatchLoad::Import::CollectionObjects.new(**batch_params.merge(user_map)) (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 |
#report ⇒ Object
Intent is DWC fields + quick summary fields for reports !! As currently implemented rebuilds DWC all
132 133 134 |
# File 'app/controllers/collection_objects_controller.rb', line 132 def report @collection_objects = ::Queries::CollectionObject::Filter.new(params).all.order('collection_objects.id').includes(:dwc_occurrence).page(params[:page]).per(params[:per] || 500) end |
#search ⇒ Object
GET /collection_object/search
248 249 250 251 252 253 254 |
# File 'app/controllers/collection_objects_controller.rb', line 248 def search if params[:id].blank? redirect_to collection_object_path, alert: '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 |
#select_options ⇒ Object
349 350 351 |
# File 'app/controllers/collection_objects_controller.rb', line 349 def @collection_objects = CollectionObject.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target]) end |
#set_collection_object ⇒ Object (private)
403 404 405 406 |
# File 'app/controllers/collection_objects_controller.rb', line 403 def set_collection_object @collection_object = CollectionObject.with_project_id(sessions_current_project_id).find(params[:id]) @recent_object = @collection_object end |
#show ⇒ Object
GET /collection_objects/1 GET /collection_objects/1.json
61 62 |
# File 'app/controllers/collection_objects_controller.rb', line 61 def show end |
#timeline ⇒ Object
GET /collection_objects/1/timeline.json
65 66 67 |
# File 'app/controllers/collection_objects_controller.rb', line 65 def timeline @data = ::Catalog::CollectionObject.data_for(@collection_object) end |
#update ⇒ Object
PATCH/PUT /collection_objects/1 PATCH/PUT /collection_objects/1.json
212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'app/controllers/collection_objects_controller.rb', line 212 def update respond_to do |format| if @collection_object.update(collection_object_params) @collection_object = @collection_object. 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 |
#user_map ⇒ Object (private)
TODO: not used?
441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'app/controllers/collection_objects_controller.rb', line 441 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 |