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

- (Object) collecting_event_id_param (protected)



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

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

- (Object) collecting_event_params (protected)



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

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

- (Object) convert

GET



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

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

- (Object) convert_params (protected)



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

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

- (Object) current_collecting_event (protected)



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

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

- (Boolean) generate_georeference? (protected)

Returns:

  • (Boolean)


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

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

- (Object) index

GET



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

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

- (Object) next_collecting_event_id (protected)



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

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

- (Object) parse_filters(params) (protected)

default filter set is all filters



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

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

- (Object) re_eval

GET



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

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

- (Object) save_selected

GET



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
62
# File 'app/controllers/tasks/collecting_events/parse/stepwise/lat_long_controller.rb', line 31

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_attributes(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

- (Object) similar_labels

GET



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

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, 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

- (Object) similar_params (protected)



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

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

- (Object) skip

GET



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

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

- (Object) update

POST



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

def update
  next_id = next_collecting_event_id
  ce      = current_collecting_event
  success = false
  if ce.update_attributes(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