Class: Tasks::CollectingEvents::Parse::Stepwise::LatLongController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#collecting_event_id_paramObject (protected)



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 117

def collecting_event_id_param
  retval = nil
  begin
    retval = params.require(:collecting_event_id)
  rescue ActionController::ParameterMissing
    # nothing provided, get the first possible one
    # return CollectingEvent.with_project_id(sessions_current_project_id).order(:id).limit(1).pluck(:id)[0]
    retval = Queries::CollectingEventLatLongExtractorQuery.new(collecting_event_id: nil,
                                                               filters:             parse_filters(params))
               .all
               .with_project_id(sessions_current_project_id)
               .order(:id)
               .limit(1)
               .pluck(:id)[0]
  end
  retval
end

#collecting_event_paramsObject (protected)



164
165
166
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 164

def collecting_event_params
  params.permit(:verbatim_latitude, :verbatim_longitude)
end

#convertObject

GET



86
87
88
89
90
91
92
93
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 86

def convert
  lat                 = convert_params[:verbatim_latitude]
  long                = convert_params[:verbatim_longitude]
  retval              = {}
  retval[:lat_piece]  = Utilities::Geo.degrees_minutes_seconds_to_decimal_degrees(lat)
  retval[:long_piece] = Utilities::Geo.degrees_minutes_seconds_to_decimal_degrees(long)
  render json: retval
end

#convert_paramsObject (protected)



168
169
170
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 168

def convert_params
  params.permit(:include_values, :verbatim_latitude, :verbatim_longitude, :piece, :lat, :long)
end

#current_collecting_eventObject (protected)



146
147
148
149
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 146

def current_collecting_event
  finding = collecting_event_id_param
  finding.nil? ? CollectingEvent.where(project_id: sessions_current_project_id).first : CollectingEvent.find(finding)
end

#generate_georeference?Boolean (protected)

Returns:

  • (Boolean)


172
173
174
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 172

def generate_georeference?
  params[:generate_georeference].blank? ? false : true
end

#indexObject

GET



5
6
7
8
9
10
11
12
13
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 5

def index
  @filters          = parse_filters(params)
  @collecting_event = current_collecting_event
  if @collecting_event.nil?
    flash['notice'] = 'No collecting events with parsable records found.'
    redirect_to hub_path and return
  end
  @matching_items = []
end

#next_collecting_event_idObject (protected)



135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 135

def next_collecting_event_id
  retval = Queries::CollectingEventLatLongExtractorQuery.new(collecting_event_id: collecting_event_id_param,
                                                             filters:             parse_filters(params))
             .all
             .with_project_id(sessions_current_project_id)
             .order(:id)
             .limit(1)
             .pluck(:id)[0]
  retval
end

#parse_filters(params) ⇒ Object (protected)

default filter set is all filters



156
157
158
159
160
161
162
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 156

def parse_filters(params)
  if params['filters'].blank?
    Utilities::Geo::REGEXP_COORD.keys
  else
    params.permit(filters: [])[:filters].map(&:to_sym)
  end
end

#re_evalObject

GET



23
24
25
26
27
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 23

def re_eval
  # where do we go from here?
  redirect_to collecting_event_lat_long_task_path(collecting_event_id: current_collecting_event.id,
                                                  filters:             parse_filters(params))
end

#save_selectedObject

GET



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 30

def save_selected
  selected = params[:selected]
  next_id  = next_collecting_event_id
  if selected.blank?
    message = 'Nothing to save.'
    success = false
  else
    any_failed = false
    message    = 'Success'
    selected.each { |item_id|
      ce = CollectingEvent.find(item_id)
      unless ce.nil?
        if ce.update(collecting_event_params)
          ce.generate_verbatim_data_georeference(true) if generate_georeference?
        else
          any_failed = true
          message    += 'Failed to update one or more of the collecting events.'
        end
      end
    }
    success = any_failed ? false : true
  end
  if success
    flash['notice'] = 'Updated.'
  else
    flash['alert'] = message
    next_id        = current_collecting_event.id
  end
  # where do we go from here?
  redirect_to collecting_event_lat_long_task_path(collecting_event_id: next_id,
                                                  filters:             parse_filters(params))
end

#similar_labelsObject

GET



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 96

def similar_labels
  retval         = {}
  lat            = similar_params[:lat]
  long           = similar_params[:long]
  piece          = similar_params[:piece]
  include_values = (similar_params[:include_values].nil?) ? false : true
  ce             = CollectingEvent.find(similar_params[:collecting_event_id])
  selected_items = ce.similar_lat_longs(lat, long, sessions_current_project_id, piece, include_values)

  retval[:count] = selected_items.count.to_s
  retval[:table] = render_to_string(partial: 'lat_long_matching_table',
                                    locals:  {
                                      lat:            lat,
                                      long:           long,
                                      selected_items: selected_items
                                    }) #([lat, long], selected_items)
  render(json: retval)
end

#similar_paramsObject (protected)



151
152
153
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 151

def similar_params
  params.permit(:collecting_event_id, :include_values, :piece, :lat, :long)
end

#skipObject

GET



16
17
18
19
20
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 16

def skip
  # where do we go from here?
  redirect_to collecting_event_lat_long_task_path(collecting_event_id: next_collecting_event_id,
                                                  filters:             parse_filters(params))
end

#updateObject

POST



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 64

def update
  next_id = next_collecting_event_id
  ce      = current_collecting_event
  success = false
  if ce.update(collecting_event_params)
    ce.generate_verbatim_data_georeference(true) if generate_georeference?
    success = true
  end
  message = 'Failed to update the collecting event.'

  if success
    flash['notice'] = 'Updated.'
  else
    flash['alert'] = message
    next_id        = current_collecting_event.id
  end
  # where do we go from here?
  redirect_to collecting_event_lat_long_task_path(collecting_event_id: next_id,
                                                  filters:             parse_filters(params))
end