Class: OtusController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- OtusController
- Defined in:
- app/controllers/otus_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #api_autocomplete ⇒ Object
-
#api_content ⇒ Object
GET /api/v1/otus/:id/inventory/content.
-
#api_distribution ⇒ Object
GET /api/v1/otus/:id/inventory/distribution.
-
#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.
-
#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
-
#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 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
#api_autocomplete ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'app/controllers/otus_controller.rb', line 270 def api_autocomplete @otus = Queries::Otu::Autocomplete.new( params.require(:term), project_id: sessions_current_project_id, having_taxon_name_only: params[:having_taxon_name_only] ).autocomplete render '/otus/api/v1/autocomplete' end |
#api_content ⇒ Object
GET /api/v1/otus/:id/inventory/content
285 286 287 288 289 290 291 292 293 |
# File 'app/controllers/otus_controller.rb', line 285 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
GET /api/v1/otus/:id/inventory/distribution
311 312 313 |
# File 'app/controllers/otus_controller.rb', line 311 def api_distribution render '/otus/api/v1/distribution' 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
301 302 303 304 305 306 307 308 |
# File 'app/controllers/otus_controller.rb', line 301 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
280 281 282 |
# File 'app/controllers/otus_controller.rb', line 280 def api_taxonomy_inventory render '/otus/api/v1/inventory/taxonomy' end |
#api_type_material_inventory ⇒ Object
GET /api/v1/otus/:id/inventory/type_material
296 297 298 |
# File 'app/controllers/otus_controller.rb', line 296 def api_type_material_inventory render '/otus/api/v1/inventory/type_material' end |
#autocomplete ⇒ Object
126 127 128 |
# File 'app/controllers/otus_controller.rb', line 126 def autocomplete @otus = Queries::Otu::Autocomplete.new(params.require(:term), project_id: sessions_current_project_id).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)
326 327 328 329 330 331 332 333 334 335 336 |
# File 'app/controllers/otus_controller.rb', line 326 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
62 63 64 |
# File 'app/controllers/otus_controller.rb', line 62 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
113 114 115 |
# File 'app/controllers/otus_controller.rb', line 113 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
56 57 58 59 |
# File 'app/controllers/otus_controller.rb', line 56 def coordinate @otus = Otu.coordinate_otus(@otu.id) render :index end |
#create ⇒ Object
POST /otus POST /otus.json
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/otus_controller.rb', line 68 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
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/otus_controller.rb', line 99 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 |
#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
39 40 |
# File 'app/controllers/otus_controller.rb', line 39 def edit end |
#index ⇒ Object
GET /otus GET /otus.json
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/otus_controller.rb', line 12 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('taxon_names.cached, otus.name') } end end |
#list ⇒ Object
42 43 44 |
# File 'app/controllers/otus_controller.rb', line 42 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
52 53 |
# File 'app/controllers/otus_controller.rb', line 52 def end |
#new ⇒ Object
GET /otus/new
34 35 36 |
# File 'app/controllers/otus_controller.rb', line 34 def new @otu = Otu.new end |
#otu_params ⇒ Object (private)
322 323 324 |
# File 'app/controllers/otus_controller.rb', line 322 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
117 118 119 120 121 122 123 124 |
# File 'app/controllers/otus_controller.rb', line 117 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)
317 318 319 320 |
# File 'app/controllers/otus_controller.rb', line 317 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
30 31 |
# File 'app/controllers/otus_controller.rb', line 30 def show end |
#timeline ⇒ Object
GET /otus/1/timeline.json
47 48 49 |
# File 'app/controllers/otus_controller.rb', line 47 def timeline @catalog = Catalog::Timeline.new(targets: [@otu]) end |
#update ⇒ Object
PATCH/PUT /otus/1 PATCH/PUT /otus/1.json
85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/otus_controller.rb', line 85 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)
338 339 340 |
# File 'app/controllers/otus_controller.rb', line 338 def user_map {user_header_map: {'otu' => 'otu_name'}} end |