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 inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/collection_objects_controller.rb', line 115

def autocomplete
  @collection_objects = CollectionObject.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)) # in model
  data                = @collection_objects.collect do |t|
    {id:              t.id,
     label:           ApplicationController.helpers.collection_object_tag(t),
     gid: t.to_global_id.to_s,
     response_values: {
       params[:method] => t.id
     },
     label_html:      ApplicationController.helpers.collection_object_tag(t) # render_to_string(:partial => 'shared/autocomplete/taxon_name.html', :object => t)
    }
  end
  render :json => data
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)



188
189
190
# File 'app/controllers/collection_objects_controller.rb', line 188

def batch_params
  params.permit(:namespace, :file, :import_level).merge(user_id: sessions_current_user_id, project_id: $project_id).symbolize_keys
end

- (Object) by_identifier

GET /collection_objects/by_identifier/ABCD

Raises:

  • (ActiveRecord::RecordNotFound)


43
44
45
46
47
48
49
# File 'app/controllers/collection_objects_controller.rb', line 43

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)



177
178
179
180
181
182
183
184
185
186
# File 'app/controllers/collection_objects_controller.rb', line 177

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_deteriminations,
    :buffered_other_labels, :deaccessioned_at, :deaccession_reason,
    :contained_in,
    collecting_event_attributes: []
  )
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



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

def create
  @collection_object = CollectionObject.new(collection_object_params)

  respond_to do |format|
    if @collection_object.save
      format.html { redirect_to @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_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



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

def depictions
end

- (Object) destroy

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



93
94
95
96
97
98
99
# File 'app/controllers/collection_objects_controller.rb', line 93

def destroy
  @collection_object.destroy
  respond_to do |format|
    format.html { redirect_to collection_objects_url }
    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.to_s}.csv"
end

- (Object) edit

GET /collection_objects/1/edit



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

def edit
end

- (Object) geo_json

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



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

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



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

def images
  @images = @collection_object.images
end

- (Object) index

GET /collection_objects GET /collection_objects.json



9
10
11
12
13
14
15
# File 'app/controllers/collection_objects_controller.rb', line 9

def index
  @recent_objects = CollectionObject.recent_from_project_id($project_id)
                      .order(updated_at: :desc)
                      .includes(:identifiers, :taxon_determinations)
                      .limit(10)
  render '/shared/data/all/index'
end

- (Object) list

GET /collection_objects/list



102
103
104
# File 'app/controllers/collection_objects_controller.rb', line 102

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

- (Object) new

GET /collection_objects/new



52
53
54
# File 'app/controllers/collection_objects_controller.rb', line 52

def new
  @collection_object = CollectionObject.new
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



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

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) set_collection_object (private)



172
173
174
175
# File 'app/controllers/collection_objects_controller.rb', line 172

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

- (Object) show

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



19
20
21
22
# File 'app/controllers/collection_objects_controller.rb', line 19

def show
  # TODO: With the separation of images and geo_json, this path is no longer required.
  @images = params['include'] == ['images'] ? @collection_object.images : nil
end

- (Object) update

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



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

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

- (Object) user_map (private)



192
193
194
195
196
197
198
199
200
# File 'app/controllers/collection_objects_controller.rb', line 192

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