Class: OtusController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- OtusController
- Defined in:
- app/controllers/otus_controller.rb
Instance Method Summary collapse
-
#api_autocomplete ⇒ Object
GET /api/v1/otus/autocomplete.
-
#api_content ⇒ Object
GET /api/v1/otus/:id/inventory/content.
-
#api_distribution ⇒ Object
TODO: Considerations .json * Scope Genus, Family by default * * 404 when no CachedMap computable.
-
#api_dwc_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/dwc.
-
#api_index ⇒ Object
GET /api/v1/otus.
-
#api_nomenclature_citations ⇒ Object
GET /api/v1/otus/:id/inventory/nomenclature_citations.
-
#api_show ⇒ Object
GET /api/v1/otus/:id.
-
#api_taxonomy_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/taxonomy.
-
#api_type_material_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/type_material.
- #autocomplete ⇒ Object
- #batch_load ⇒ Object
- #batch_params ⇒ Object private
-
#breadcrumbs ⇒ Object
GET /otus/1/navigation.json.
-
#by_name ⇒ Object
GET api/v1/otus/by_name/:name?token=:token&project_id=:id.
-
#collection_objects ⇒ Object
GET /otus/1/collection_objects.
-
#coordinate ⇒ Object
GET /otus/1/coordinate.json.
-
#create ⇒ Object
POST /otus POST /otus.json.
-
#create_data_attributes_batch_load ⇒ Object
TODO: AUTOGENERATED STUB, check and update.
- #create_identifiers_batch_load ⇒ Object
- #create_simple_batch_file_load ⇒ Object
- #create_simple_batch_load ⇒ Object
-
#destroy ⇒ Object
DELETE /otus/1 DELETE /otus/1.json.
-
#distribution ⇒ Object
TODO: Redirect to json if too big? GET /otus/:id/inventory/distribution.json GET /otus/:id/inventory/distribution.geojson.
-
#download ⇒ Object
GET /otus/download.
-
#edit ⇒ Object
GET /otus/1/edit.
-
#index ⇒ Object
GET /otus GET /otus.json.
- #list ⇒ Object
-
#navigation ⇒ Object
GET /otus/1/navigation.json.
-
#new ⇒ Object
GET /otus/new.
-
#otu_params ⇒ Object
private
end end.
-
#preview_data_attributes_batch_load ⇒ Object
TODO: AUTOGENERATED STUB, check and update.
- #preview_identifiers_batch_load ⇒ Object
- #preview_simple_batch_file_load ⇒ Object
- #preview_simple_batch_load ⇒ Object
- #search ⇒ Object
-
#select_options ⇒ Object
GET /otus/select_options?target=TaxonDetermination.
- #set_otu ⇒ Object private
-
#show ⇒ Object
GET /otus/1 GET /otus/1.json.
-
#timeline ⇒ Object
GET /otus/1/timeline.json.
-
#update ⇒ Object
PATCH/PUT /otus/1 PATCH/PUT /otus/1.json.
- #user_map ⇒ Object private
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 Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_autocomplete ⇒ Object
GET /api/v1/otus/autocomplete
280 281 282 283 284 285 286 287 288 |
# File 'app/controllers/otus_controller.rb', line 280 def api_autocomplete @otus = ::Queries::Otu::Autocomplete.new( params.require(:term), with_taxon_name: params[:with_taxon_name], project_id: sessions_current_project_id, ).api_autocomplete render '/otus/api/v1/autocomplete' end |
#api_content ⇒ Object
GET /api/v1/otus/:id/inventory/content
305 306 307 308 309 310 311 312 |
# File 'app/controllers/otus_controller.rb', line 305 def api_content topic_ids = [params[:topic_id]].flatten.compact.uniq @public_content = PublicContent.where(otu: @otu, project_id: sessions_current_project_id) @public_content = @public_content.joins(:topic).where(topic_id: topic_ids) unless topic_ids.empty? render '/otus/api/v1/inventory/content' end |
#api_distribution ⇒ Object
TODO: Considerations .json
* Scope Genus, Family by default
*
* 404 when no CachedMap computable
.geo_json
* Always returns result, could be empty
GET /api/v1/otus/:id/inventory/distribution.json GET /api/v1/otus/:id/inventory/distribution.geojson
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'app/controllers/otus_controller.rb', line 358 def api_distribution respond_to do |format| format.json do @cached_map_type = params[:cached_map_type] || 'CachedMapItem::WebLevel1' @quicker_cached_map = @otu.quicker_cached_map(@cached_map_type) if @quicker_cached_map.blank? render json: { error: 'no map available'}, status: :not_found and return end render '/otus/api/v1/inventory/distribution' end format.geojson do render '/otus/api/v1/inventory/distribution' end end end |
#api_dwc_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/dwc
296 297 298 299 300 301 302 |
# File 'app/controllers/otus_controller.rb', line 296 def api_dwc_inventory send_data Export::Download.generate_csv( DwcOccurrence.scoped_by_otu(@otu), exclude_columns: ['id', 'created_by_id', 'updated_by_id', 'project_id', 'updated_at']), type: 'text', filename: "dwc_#{helpers.label_for_otu(@otu).gsub(/\W/,'_')}_#{DateTime.now}.csv" end |
#api_index ⇒ Object
GET /api/v1/otus
256 257 258 259 260 261 262 263 |
# File 'app/controllers/otus_controller.rb', line 256 def api_index @otus = ::Queries::Otu::Filter.new(params.merge!(api: true)).all .where(project_id: sessions_current_project_id) .order('otus.id') .page(params[:page]) .per(params[:per]) render '/otus/api/v1/index' end |
#api_nomenclature_citations ⇒ Object
GET /api/v1/otus/:id/inventory/nomenclature_citations
320 321 322 323 324 325 326 327 |
# File 'app/controllers/otus_controller.rb', line 320 def api_nomenclature_citations if @otu.taxon_name @data = ::Catalog::Nomenclature::Entry.new(@otu.taxon_name) render '/otus/api/v1/inventory/nomenclature_citations' else render json: {}, status: :unprocessable_entity end end |
#api_show ⇒ Object
GET /api/v1/otus/:id
266 267 268 |
# File 'app/controllers/otus_controller.rb', line 266 def api_show render '/otus/api/v1/show' end |
#api_taxonomy_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/taxonomy
291 292 293 |
# File 'app/controllers/otus_controller.rb', line 291 def api_taxonomy_inventory render '/otus/api/v1/inventory/taxonomy' end |
#api_type_material_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/type_material
315 316 317 |
# File 'app/controllers/otus_controller.rb', line 315 def api_type_material_inventory render '/otus/api/v1/inventory/type_material' end |
#autocomplete ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'app/controllers/otus_controller.rb', line 270 def autocomplete @otus = ::Queries::Otu::Autocomplete.new( params.require(:term), project_id: sessions_current_project_id, with_taxon_name: params[:with_taxon_name], having_taxon_name_only: params[:having_taxon_name_only], ).autocomplete end |
#batch_load ⇒ Object
130 131 132 |
# File 'app/controllers/otus_controller.rb', line 130 def batch_load # see app/views/otus/batch_load.html.erb end |
#batch_params ⇒ Object (private)
393 394 395 396 397 398 399 400 401 402 403 |
# File 'app/controllers/otus_controller.rb', line 393 def batch_params params.permit( :name, :file, :import_level, :create_new_otu, :source_id, :type_select, :create_new_predicate, files: []) .merge( user_id: sessions_current_user_id, project_id: sessions_current_project_id) .to_h .symbolize_keys end |
#breadcrumbs ⇒ Object
GET /otus/1/navigation.json
64 65 66 |
# File 'app/controllers/otus_controller.rb', line 64 def render json: :not_found and return if @otu.nil? end |
#by_name ⇒ Object
GET api/v1/otus/by_name/:name?token=:token&project_id=:id
245 246 247 248 |
# File 'app/controllers/otus_controller.rb', line 245 def by_name @otu_name = params.require(:name) @otu_ids = Queries::Otu::Autocomplete.new(@otu_name, project_id: params.require(:project_id)).all.pluck(:id) end |
#collection_objects ⇒ Object
GET /otus/1/collection_objects
115 116 117 |
# File 'app/controllers/otus_controller.rb', line 115 def collection_objects @collection_objects = Otu.where(project_id: sessions_current_project_id).find(params[:id]).collection_objects.pluck(:id) end |
#coordinate ⇒ Object
GET /otus/1/coordinate.json
58 59 60 61 |
# File 'app/controllers/otus_controller.rb', line 58 def coordinate @otus = Otu.coordinate_otus(@otu.id) render :index end |
#create ⇒ Object
POST /otus POST /otus.json
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/otus_controller.rb', line 70 def create @otu = Otu.new(otu_params) respond_to do |format| if @otu.save format.html { redirect_to @otu, notice: "Otu '#{@otu.name}' was successfully created." } format.json { render action: :show, status: :created, location: @otu } else format.html { render action: 'new' } format.json { render json: @otu.errors, status: :unprocessable_entity } end end end |
#create_data_attributes_batch_load ⇒ Object
TODO: AUTOGENERATED STUB, check and update
222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'app/controllers/otus_controller.rb', line 222 def create_data_attributes_batch_load if params[:file] && (params[:file].tempfile, :data_attributes_batch_load_otus_md5) @result = BatchLoad::Import::Otus::DataAttributesInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} TODO RECORD TYPES were created." render 'otus/batch_load/data_attributes/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_identifiers_batch_load ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/controllers/otus_controller.rb', line 169 def create_identifiers_batch_load if params[:file] && (params[:file].tempfile, :batch_load_otus_identifiers_md5) @result = BatchLoad::Import::Otus::IdentifiersInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully processed file, #{@result.total_records_created} otus were created." render('otus/batch_load/identifiers/create') return else flash[:alert] = 'Batch import failed.' end render(:batch_load) end end |
#create_simple_batch_file_load ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'app/controllers/otus_controller.rb', line 194 def create_simple_batch_file_load if params[:files] && (params[:files][0].tempfile, :batch_file_load_simple_md5) @result = BatchFileLoad::Import::Otus::SimpleInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully processed #{@result.total_files_processed} file(s), #{@result.total_records_created} otus were created." render 'otus/batch_file_load/simple/create' return else flash[:alert] = 'Batch import failed.' render :batch_load end end end |
#create_simple_batch_load ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/otus_controller.rb', line 145 def create_simple_batch_load if params[:file] && (params[:file].tempfile, :batch_otus_md5) @result = BatchLoad::Import::Otus.new(**batch_params.merge(user_map)) if @result.create flash[:notice] = "Successfully processed file, #{@result.total_records_created} otus were created." render('otus/batch_load/simple/create') and return else flash[:alert] = 'Batch import failed.' end render(:batch_load) end end |
#destroy ⇒ Object
DELETE /otus/1 DELETE /otus/1.json
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/otus_controller.rb', line 101 def destroy @otu.destroy respond_to do |format| if @otu.destroyed? format.html { destroy_redirect @otu, notice: 'OTU was successfully destroyed.' } format.json { head :no_content} else format.html { destroy_redirect @otu, notice: 'OTU was not destroyed, ' + @otu.errors..join('; ') } format.json { render json: @otu.errors, status: :unprocessable_entity } end end end |
#distribution ⇒ Object
TODO: Redirect to json if too big? GET /otus/:id/inventory/distribution.json GET /otus/:id/inventory/distribution.geojson
332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'app/controllers/otus_controller.rb', line 332 def distribution respond_to do |format| format.json do @cached_map_type = params[:cached_map_type] || 'CachedMapItem::WebLevel1' @quicker_cached_map = @otu.quicker_cached_map(@cached_map_type) render json: { error: 'no map available'}, status: :not_found unless @quicker_cached_map.present? and return end format.geojson do end end end |
#download ⇒ Object
GET /otus/download
238 239 240 241 242 |
# File 'app/controllers/otus_controller.rb', line 238 def download send_data Export::Download.generate_csv(Otu.where(project_id: sessions_current_project_id)), type: 'text', filename: "otus_#{DateTime.now}.csv" end |
#edit ⇒ Object
GET /otus/1/edit
41 42 |
# File 'app/controllers/otus_controller.rb', line 41 def edit end |
#index ⇒ Object
GET /otus GET /otus.json
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/otus_controller.rb', line 14 def index respond_to do |format| format.html do @recent_objects = Otu.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @otus = ::Queries::Otu::Filter.new(params).all .page(params[:page]) .per(params[:per]) .eager_load(:taxon_name) .order(:cached, 'otus.name') } end end |
#list ⇒ Object
44 45 46 |
# File 'app/controllers/otus_controller.rb', line 44 def list @otus = Otu.with_project_id(sessions_current_project_id).page(params[:page]).per(params[:per]) end |
#navigation ⇒ Object
GET /otus/1/navigation.json
54 55 |
# File 'app/controllers/otus_controller.rb', line 54 def end |
#new ⇒ Object
GET /otus/new
36 37 38 |
# File 'app/controllers/otus_controller.rb', line 36 def new @otu = Otu.new end |
#otu_params ⇒ Object (private)
end end
389 390 391 |
# File 'app/controllers/otus_controller.rb', line 389 def otu_params params.require(:otu).permit(:name, :taxon_name_id) end |
#preview_data_attributes_batch_load ⇒ Object
TODO: AUTOGENERATED STUB, check and update
210 211 212 213 214 215 216 217 218 219 |
# File 'app/controllers/otus_controller.rb', line 210 def preview_data_attributes_batch_load if params[:file] @result = BatchLoad::Import::Otus::DataAttributesInterpreter.new(**batch_params) (params[:file].tempfile, :data_attributes_batch_load_otus_md5) render 'otus/batch_load/data_attributes/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#preview_identifiers_batch_load ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'app/controllers/otus_controller.rb', line 158 def preview_identifiers_batch_load if params[:file] @result = BatchLoad::Import::Otus::IdentifiersInterpreter.new(**batch_params) (params[:file].tempfile, :batch_load_otus_identifiers_md5) render('otus/batch_load/identifiers/preview') else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#preview_simple_batch_file_load ⇒ Object
183 184 185 186 187 188 189 190 191 192 |
# File 'app/controllers/otus_controller.rb', line 183 def preview_simple_batch_file_load if params[:files] @result = BatchFileLoad::Import::Otus::SimpleInterpreter.new(**batch_params) (params[:files][0].tempfile, :batch_file_load_simple_md5) render 'otus/batch_file_load/simple/preview' else flash[:notice] = 'No file(s) provided!' redirect_to action: :batch_load end end |
#preview_simple_batch_load ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/otus_controller.rb', line 134 def preview_simple_batch_load if params[:file] @result = BatchLoad::Import::Otus.new(**batch_params.merge(user_map)) (params[:file].tempfile, :batch_otus_md5) render('otus/batch_load/simple/preview') else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#search ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'app/controllers/otus_controller.rb', line 119 def search if params[:id].blank? redirect_to(otus_path, alert: 'You must select an item from the list with a click or tab press before clicking show.') else redirect_to otu_path(params[:id]) end end |
#select_options ⇒ Object
GET /otus/select_options?target=TaxonDetermination
251 252 253 |
# File 'app/controllers/otus_controller.rb', line 251 def @otus = Otu.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:target)) end |
#set_otu ⇒ Object (private)
377 378 379 380 |
# File 'app/controllers/otus_controller.rb', line 377 def set_otu @otu = Otu.where(project_id: sessions_current_project_id).eager_load(:taxon_name).find(params[:id]) @recent_object = @otu end |
#show ⇒ Object
GET /otus/1 GET /otus/1.json
32 33 |
# File 'app/controllers/otus_controller.rb', line 32 def show end |
#timeline ⇒ Object
GET /otus/1/timeline.json
49 50 51 |
# File 'app/controllers/otus_controller.rb', line 49 def timeline @catalog = Catalog::Timeline.new(targets: [@otu]) end |
#update ⇒ Object
PATCH/PUT /otus/1 PATCH/PUT /otus/1.json
87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/otus_controller.rb', line 87 def update respond_to do |format| if @otu.update(otu_params) format.html { redirect_to @otu, notice: 'Otu was successfully updated.' } format.json { render :show, location: @otu } else format.html { render action: 'edit' } format.json { render json: @otu.errors, status: :unprocessable_entity } end end end |
#user_map ⇒ Object (private)
405 406 407 |
# File 'app/controllers/otus_controller.rb', line 405 def user_map {user_header_map: {'otu' => 'otu_name'}} end |