Class: CollectingEventsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/collecting_events_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 included from DataControllerConfiguration::ProjectDataControllerConfiguration

#polymorphic_filter_params

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/collecting_events_controller.rb', line 87

def autocomplete
  @collecting_events = CollectingEvent.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))

  data = @collecting_events.collect do |t|
    str = render_to_string(partial: 'tag', locals: {collecting_event: t})
    {id:              t.id,
     label:           str,
     response_values: {
       params[:method] => t.id
     },
     label_html:      str
    }
  end

  render :json => data
end

- (Object) autocomplete_collecting_event_verbatim_locality

see rails-jquery-autocomplete



106
107
108
109
110
# File 'app/controllers/collecting_events_controller.rb', line 106

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

- (Object) batch_load

GET collecting_events/batch_load



118
119
# File 'app/controllers/collecting_events_controller.rb', line 118

def batch_load
end

- (Object) batch_params (private)



200
201
202
# File 'app/controllers/collecting_events_controller.rb', line 200

def batch_params
  params.permit(:ce_namespace, :file, :import_level).merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).to_h.symbolize_keys
end

- (Object) card



66
67
68
# File 'app/controllers/collecting_events_controller.rb', line 66

def card
 @target = params[:target] 
end

- (Object) collecting_event_params (private)

Never trust parameters from the scary internet, only allow the white list through.



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'app/controllers/collecting_events_controller.rb', line 182

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_trip_identifier, :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,
    roles_attributes: [:id, :_destroy, :type, :person_id, :position,
                       person_attributes: [:last_name, :first_name, :suffix, :prefix]],
    identifiers_attributes: [:id, :namespace_id, :identifier, :type, :_destroy]
  )
end

- (Object) create

POST /collecting_events POST /collecting_events.json



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/collecting_events_controller.rb', line 29

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

- (Object) create_castor_batch_load



158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/controllers/collecting_events_controller.rb', line 158

def create_castor_batch_load
  if params[:file] && digested_cookie_exists?(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

- (Object) create_simple_batch_load



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/controllers/collecting_events_controller.rb', line 132

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(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

- (Object) destroy

DELETE /collecting_events/1 DELETE /collecting_events/1.json



58
59
60
61
62
63
64
# File 'app/controllers/collecting_events_controller.rb', line 58

def destroy
  @collecting_event.destroy
  respond_to do |format|
    format.html { redirect_to collecting_events_url }
    format.json { head :no_content }
  end
end

- (Object) download

GET /collecting_events/download



113
114
115
# File 'app/controllers/collecting_events_controller.rb', line 113

def download
  send_data CollectingEvent.generate_download(CollectingEvent.where(project_id: sessions_current_project_id)), type: 'text', filename: "collecting_events_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /collecting_events/1/edit



24
25
# File 'app/controllers/collecting_events_controller.rb', line 24

def edit
end

- (Object) index

GET /collecting_events GET /collecting_events.jso



8
9
10
11
# File 'app/controllers/collecting_events_controller.rb', line 8

def index
  @recent_objects = CollectingEvent.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



74
75
76
# File 'app/controllers/collecting_events_controller.rb', line 74

def list
  @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id).order(:id).page(params[:page])
end

- (Object) new

GET /collecting_events/new



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

def new
  @collecting_event = CollectingEvent.new
end

- (Object) preview_castor_batch_load



147
148
149
150
151
152
153
154
155
156
# File 'app/controllers/collecting_events_controller.rb', line 147

def preview_castor_batch_load 
  if params[:file] 
    @result = BatchLoad::Import::CollectingEvents::CastorInterpreter.new(batch_params)
    digest_cookie(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

- (Object) preview_simple_batch_load



121
122
123
124
125
126
127
128
129
130
# File 'app/controllers/collecting_events_controller.rb', line 121

def preview_simple_batch_load
  if params[:file]
    @result = BatchLoad::Import::CollectingEvents.new(batch_params)
    digest_cookie(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

- (Object) search

GET /collecting_events/search



79
80
81
82
83
84
85
# File 'app/controllers/collecting_events_controller.rb', line 79

def search
  if params[:id].blank?
    redirect_to collecting_event_path, notice: '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

- (Object) set_collecting_event (private)

Use callbacks to share common setup or constraints between actions.



176
177
178
179
# File 'app/controllers/collecting_events_controller.rb', line 176

def set_collecting_event
  @collecting_event = CollectingEvent.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object    = @collecting_event
end

- (Object) show

GET /collecting_events/1 GET /collecting_events/1.json



15
16
# File 'app/controllers/collecting_events_controller.rb', line 15

def show
end

- (Object) test



70
71
72
# File 'app/controllers/collecting_events_controller.rb', line 70

def test
  @geo = CollectingEvent.test
end

- (Object) update

PATCH/PUT /collecting_events/1 PATCH/PUT /collecting_events/1.json



44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/collecting_events_controller.rb', line 44

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 { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @collecting_event.errors, status: :unprocessable_entity }
    end
  end
end