Class: CollectingEventsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CollectingEventsController
- Defined in:
- app/controllers/collecting_events_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #api_autocomplete ⇒ Object
- #api_index ⇒ Object
- #api_show ⇒ Object
- #attributes ⇒ Object
- #autocomplete ⇒ Object
-
#autocomplete_collecting_event_verbatim_locality ⇒ Object
GET /collecting_events/autocomplete_collecting_event_verbatim_locality?term=asdf see rails-jquery-autocomplete.
-
#batch_load ⇒ Object
GET collecting_events/batch_load.
- #batch_params ⇒ Object private
-
#batch_update ⇒ Object
PATCH /collecting_events/batch_update.json?collecting_event_query=<>&collecting_event={}.
- #card ⇒ Object
-
#clone ⇒ Object
POST /collecting_events/1/clone.json.
- #collecting_event_params ⇒ Object private
-
#create ⇒ Object
POST /collecting_events POST /collecting_events.json.
- #create_castor_batch_load ⇒ Object
- #create_gpx_batch_load ⇒ Object
- #create_simple_batch_load ⇒ Object
-
#destroy ⇒ Object
DELETE /collecting_events/1 DELETE /collecting_events/1.json.
-
#download ⇒ Object
GET /collecting_events/download.
-
#edit ⇒ Object
GET /collecting_events/1/edit.
-
#index ⇒ Object
GET /collecting_events GET /collecting_events.json.
- #list ⇒ Object
- #navigation ⇒ Object
-
#new ⇒ Object
GET /collecting_events/new.
-
#parse_verbatim_label ⇒ Object
parse verbatim label, return date and coordinates.
- #preview_castor_batch_load ⇒ Object
- #preview_gpx_batch_load ⇒ Object
- #preview_simple_batch_load ⇒ Object
-
#search ⇒ Object
GET /collecting_events/search.
-
#select_options ⇒ Object
GET /collecting_events/select_options.
- #set_collecting_event ⇒ Object private
-
#show ⇒ Object
GET /collecting_events/1 GET /collecting_events/1.json.
- #test ⇒ Object
-
#update ⇒ Object
PATCH/PUT /collecting_events/1 PATCH/PUT /collecting_events/1.json.
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, #cumulative_projects_created_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, #sound_cumulative_gb_per_year, #sound_gb_per_year, #taxonworks_classification, #week_in_review_graphs
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
273 274 275 276 277 |
# File 'app/controllers/collecting_events_controller.rb', line 273 def api_autocomplete render json: {} and return if params[:term].blank? @collecting_events = Queries::CollectingEvent::Autocomplete.new(params[:term], project_id: sessions_current_project_id).autocomplete render '/collecting_events/api/v1/autocomplete' end |
#api_index ⇒ Object
260 261 262 263 264 265 266 |
# File 'app/controllers/collecting_events_controller.rb', line 260 def api_index @collecting_events = Queries::CollectingEvent::Filter.new(params.merge!(api: true)).all .where(project_id: sessions_current_project_id) .order('collecting_events.id') .page(params[:page]).per(params[:per]) render 'collecting_events/api/v1/index' end |
#api_show ⇒ Object
268 269 270 271 |
# File 'app/controllers/collecting_events_controller.rb', line 268 def api_show @collecting_event = CollectingEvent.where(project_id: sessions_current_project_id).find(params[:id]) render '/collecting_events/api/v1/show' end |
#attributes ⇒ Object
112 113 114 115 116 117 |
# File 'app/controllers/collecting_events_controller.rb', line 112 def attributes render json: ::CollectingEvent.columns.select{ |a| ([:cached_level0_geographic_name, :cached_level1_geographic_name, :cached_level2_geographic_name ] + Queries::CollectingEvent::Filter::ATTRIBUTES).include?( a.name.to_sym) }.collect{|b| {'name' => b.name, 'type' => b.type } } end |
#autocomplete ⇒ Object
128 129 130 |
# File 'app/controllers/collecting_events_controller.rb', line 128 def autocomplete @collecting_events = Queries::CollectingEvent::Autocomplete.new(params[:term], project_id: sessions_current_project_id).autocomplete end |
#autocomplete_collecting_event_verbatim_locality ⇒ Object
GET /collecting_events/autocomplete_collecting_event_verbatim_locality?term=asdf see rails-jquery-autocomplete
148 149 150 151 152 |
# File 'app/controllers/collecting_events_controller.rb', line 148 def autocomplete_collecting_event_verbatim_locality term = params[:term] values = CollectingEvent.where(project_id: sessions_current_project_id).where('verbatim_locality ILIKE ?', term + '%').select(:verbatim_locality, 'length(verbatim_locality)').distinct.limit(20).order('length(verbatim_locality)').order('verbatim_locality ASC').all render json: values.map { |v| { label: v.verbatim_locality, value: v.verbatim_locality} } end |
#batch_load ⇒ Object
GET collecting_events/batch_load
173 174 |
# File 'app/controllers/collecting_events_controller.rb', line 173 def batch_load end |
#batch_params ⇒ Object (private)
311 312 313 314 315 316 317 318 319 |
# File 'app/controllers/collecting_events_controller.rb', line 311 def batch_params params.permit( :ce_namespace, :ce_geographic_area_id, :file, :import_level).merge( user_id: sessions_current_user_id, project_id: sessions_current_project_id).to_h.symbolize_keys end |
#batch_update ⇒ Object
PATCH /collecting_events/batch_update.json?collecting_event_query=<>&collecting_event={}
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/collecting_events_controller.rb', line 133 def batch_update if r = CollectingEvent.batch_update( preview: params[:preview], collecting_event: collecting_event_params, collecting_event_query: params[:collecting_event_query], user_id: sessions_current_user_id, project_id: sessions_current_project_id) render json: r.to_json, status: :ok else render json: {}, status: :unprocessable_entity end end |
#card ⇒ Object
100 101 102 |
# File 'app/controllers/collecting_events_controller.rb', line 100 def card @target = params[:target] end |
#clone ⇒ Object
POST /collecting_events/1/clone.json
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/collecting_events_controller.rb', line 54 def clone @collecting_event = @collecting_event.clone( annotations: params[:annotations], incremented_identifier_id: params[:incremented_identifier_id] ) respond_to do |format| if @collecting_event.persisted? format.html { redirect_to new_collecting_event_task_path(@collecting_event), notice: 'Clone successful, editing new record.' } format.json { render :show } else format.html { redirect_to new_collecting_event_task_path(@collecting_event), notice: 'Failed to clone the collecting event..' } format.json {render json: @collecting_event.errors, status: :unprocessable_entity} end end end |
#collecting_event_params ⇒ Object (private)
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'app/controllers/collecting_events_controller.rb', line 289 def collecting_event_params params.require(:collecting_event).permit( :verbatim_label, :print_label, :print_label_number_to_print, :document_label, :verbatim_locality, :verbatim_date, :verbatim_longitude, :verbatim_latitude, :verbatim_geolocation_uncertainty, :verbatim_field_number, :verbatim_collectors, :verbatim_method, :geographic_area_id, :minimum_elevation, :maximum_elevation, :elevation_precision, :time_start_hour, :time_start_minute, :time_start_second, :time_end_hour, :time_end_minute, :time_end_second, :start_date_day, :start_date_month, :start_date_year, :end_date_day, :end_date_month, :group, :member, :formation, :lithology, :max_ma, :min_ma, :end_date_year, :verbatim_habitat, :field_notes, :verbatim_datum, :verbatim_elevation, :meta_prioritize_geographic_area, georeferences_attributes: [:type, :geographic_item_id, :error_radius, :error_depth, :error_geographic_item, :is_public, :api_request, :year_georeferenced, :month_georeferenced, :day_georeferenced], # batch add only use right now roles_attributes: [:id, :_destroy, :type, :person_id, :position, :by, person_attributes: [:last_name, :first_name, :suffix, :prefix, :by]], identifiers_attributes: [:id, :namespace_id, :identifier, :type, :_destroy], data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :attribute_subject_id, :attribute_subject_type, :value ] ) end |
#create ⇒ Object
POST /collecting_events POST /collecting_events.json
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/collecting_events_controller.rb', line 40 def create @collecting_event = CollectingEvent.new(collecting_event_params) respond_to do |format| if @collecting_event.save format.html { redirect_to @collecting_event, notice: 'Collecting event was successfully created.' } format.json { render action: 'show', status: :created, location: @collecting_event } else format.html { render action: 'new' } format.json { render json: @collecting_event.errors, status: :unprocessable_entity } end end end |
#create_castor_batch_load ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'app/controllers/collecting_events_controller.rb', line 213 def create_castor_batch_load if params[:file] && (params[:file].tempfile, :Castor_collecting_events_md5) @result = BatchLoad::Import::CollectingEvents::CastorInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} collecting events were created." render 'collecting_events/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_gpx_batch_load ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'app/controllers/collecting_events_controller.rb', line 240 def create_gpx_batch_load if params[:file] && (params[:file].tempfile, :gpx_batch_load_collecting_events_md5) @result = BatchLoad::Import::CollectingEvents::GPXInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} collecting events w/georeferences were created." render 'collecting_events/batch_load/gpx/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
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/controllers/collecting_events_controller.rb', line 187 def create_simple_batch_load if params[:file] && (params[:file].tempfile, :batch_collecting_events_md5) @result = BatchLoad::Import::CollectingEvent.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} collecting events were created." render 'collecting_events/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 |
#destroy ⇒ Object
DELETE /collecting_events/1 DELETE /collecting_events/1.json
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/collecting_events_controller.rb', line 87 def destroy @collecting_event.destroy respond_to do |format| if @collecting_event.destroyed? format.html { destroy_redirect @collecting_event, notice: 'CollectingEvent was successfully destroyed.' } format.json { head :no_content } else format.html { destroy_redirect @collecting_event, notice: 'CollectingEvent was not destroyed: ' + @collecting_event.errors..join('; ') } format.json { render json: @collecting_event.errors, status: :unprocessable_entity } end end end |
#download ⇒ Object
GET /collecting_events/download
155 156 157 158 159 |
# File 'app/controllers/collecting_events_controller.rb', line 155 def download send_data(Export::CSV.generate_csv(CollectingEvent.where(project_id: sessions_current_project_id)), type: 'text', filename: "collecting_events_#{DateTime.now}.tsv") end |
#edit ⇒ Object
GET /collecting_events/1/edit
34 35 36 |
# File 'app/controllers/collecting_events_controller.rb', line 34 def edit redirect_to new_collecting_event_task_path(collecting_event_id: @collecting_event.id), notice: 'Editing in new interface.' end |
#index ⇒ Object
GET /collecting_events GET /collecting_events.json
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/collecting_events_controller.rb', line 9 def index respond_to do |format| format.html do @recent_objects = CollectingEvent.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @collecting_events = Queries::CollectingEvent::Filter.new(params).all .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
108 109 110 |
# File 'app/controllers/collecting_events_controller.rb', line 108 def list @collecting_events = CollectingEvent.where(project_id: sessions_current_project_id).order(:id).page(params[:page]) end |
#navigation ⇒ Object
279 280 |
# File 'app/controllers/collecting_events_controller.rb', line 279 def end |
#new ⇒ Object
GET /collecting_events/new
29 30 31 |
# File 'app/controllers/collecting_events_controller.rb', line 29 def new redirect_to new_collecting_event_task_path, notice: 'Redirected to new interface.' end |
#parse_verbatim_label ⇒ Object
parse verbatim label, return date and coordinates
162 163 164 165 166 167 168 169 170 |
# File 'app/controllers/collecting_events_controller.rb', line 162 def parse_verbatim_label if params[:verbatim_label] render json: {date: Utilities::Dates.date_regex_from_verbatim_label(params[:verbatim_label]), geo: Utilities::Geo.coordinates_regex_from_verbatim_label(params[:verbatim_label]), elevation: Utilities::Elevation.elevation_regex_from_verbatim_label(params[:verbatim_label]), collecting_method: Utilities::CollectingMethods.method_regex_from_verbatim_label(params[:verbatim_label]), }.to_json end end |
#preview_castor_batch_load ⇒ Object
202 203 204 205 206 207 208 209 210 211 |
# File 'app/controllers/collecting_events_controller.rb', line 202 def preview_castor_batch_load if params[:file] @result = BatchLoad::Import::CollectingEvents::CastorInterpreter.new(**batch_params) (params[:file].tempfile, :Castor_collecting_events_md5) render 'collecting_events/batch_load/castor/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#preview_gpx_batch_load ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 |
# File 'app/controllers/collecting_events_controller.rb', line 228 def preview_gpx_batch_load if params[:file] @result = BatchLoad::Import::CollectingEvents::GPXInterpreter.new(**batch_params) (params[:file].tempfile, :gpx_batch_load_collecting_events_md5) render 'collecting_events/batch_load/gpx/preview' # render '/shared/data/all/batch_load/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#preview_simple_batch_load ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'app/controllers/collecting_events_controller.rb', line 176 def preview_simple_batch_load if params[:file] @result = BatchLoad::Import::CollectingEvents.new(**batch_params) (params[:file].tempfile, :batch_collecting_events_md5) render 'collecting_events/batch_load/simple/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#search ⇒ Object
GET /collecting_events/search
120 121 122 123 124 125 126 |
# File 'app/controllers/collecting_events_controller.rb', line 120 def search if params[:id].blank? redirect_to collecting_event_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to collecting_event_path(params[:id]) end end |
#select_options ⇒ Object
GET /collecting_events/select_options
256 257 258 |
# File 'app/controllers/collecting_events_controller.rb', line 256 def @collecting_events = CollectingEvent.select_optimized(sessions_current_user_id, sessions_current_project_id) end |
#set_collecting_event ⇒ Object (private)
284 285 286 287 |
# File 'app/controllers/collecting_events_controller.rb', line 284 def set_collecting_event @collecting_event = CollectingEvent.where(project_id: sessions_current_project_id).find(params[:id]) @recent_object = @collecting_event end |
#show ⇒ Object
GET /collecting_events/1 GET /collecting_events/1.json
25 26 |
# File 'app/controllers/collecting_events_controller.rb', line 25 def show end |
#test ⇒ Object
104 105 106 |
# File 'app/controllers/collecting_events_controller.rb', line 104 def test @geo = CollectingEvent.test end |
#update ⇒ Object
PATCH/PUT /collecting_events/1 PATCH/PUT /collecting_events/1.json
73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/collecting_events_controller.rb', line 73 def update respond_to do |format| if @collecting_event.update(collecting_event_params) format.html { redirect_to @collecting_event, notice: 'Collecting event was successfully updated.' } format.json { render :show, status: :ok, location: @collecting_event } else format.html { render action: 'edit' } format.json { render json: @collecting_event.errors, status: :unprocessable_entity } end end end |