Class: Tasks::Gis::MatchGeoreferenceController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/gis/match_georeference_controller.rb

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#batch_create_match_georeferencesObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 156

def batch_create_match_georeferences
  message = ''
  respond_to do |format|
    format.json {
      # we want to repackage the checkmarks we get from the client side into an array of ids with which
      # to feed Georeference.
      keys = params.keys
      checked_ids = []
      arguments = {}
      keys.each { |key|
        if /check\d+/ =~ key
          checked_ids.push(params[key].to_i)
        end
      }

      arguments[:georeference_id] = params['georeference_id']
      arguments[:checked_ids] = checked_ids

      results = Georeference.with_project_id(sessions_current_project_id)
        .batch_create_from_georeference_matcher(arguments)

      if results.blank?
        message = 'No collecting events were selected.'
      end

      html = render_to_string(partial: 'georeference_success', formats: 'html',
                              locals: {georeferences_results: results}
                             )

      render json: {message: message,
                    html: html
      }
    }
  end
end

#ce_render_to_htmlString

Returns of html for partial.

Returns:

  • (String)

    of html for partial



206
207
208
209
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 206

def ce_render_to_html
  render_to_string(partial: 'tasks/gis/match_georeference/collecting_event_selections',
                   locals: {collecting_events: @collecting_events})
end

#drawn_collecting_eventsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 53

def drawn_collecting_events
  message = ''
  value = params['ce_geographic_item_attributes_shape']
  if value.blank?
    @collecting_events = CollectingEvent.where('false')
  else
    feature = RGeo::GeoJSON.decode(value, json_parser: :json)
    # isolate the WKT
    geometry = feature.geometry
    this_type = geometry.geometry_type.to_s.downcase
    geometry = geometry.as_text
    radius = feature['radius']
    case this_type
    when 'point'
      @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
        .joins(:geographic_items)
        .where(GeographicItem.intersecting_radius_of_wkt_sql(geometry, radius)) # !! probably want within_radius_of_wkt_sql
    when 'polygon'
      @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
        .joins(:geographic_items)
        .where(GeographicItem.contained_by_wkt_sql(geometry))
    else
    end
  end

  if @collecting_events.blank?
    message = 'no georeferences found'
  end
  render_ce_select_json(message)
end

#drawn_georeferencesObject

TODO: if kept replace with a Georeferences filter



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 125

def drawn_georeferences
  message = ''
  value = params['gr_geographic_item_attributes_shape']
  if value.blank?
    @georeferences = Georeference.where('false')
  else
    feature = RGeo::GeoJSON.decode(value, json_parser: :json)
    # isolate the WKT
    geometry = feature.geometry
    this_type = geometry.geometry_type.to_s.downcase
    geometry = geometry.as_text

    radius = feature['radius']
    case this_type
    when 'point'
      @georeferences = Georeference.with_project_id(sessions_current_project_id)
        .joins(:geographic_item)
        .where(GeographicItem.intersecting_radius_of_wkt_sql(geometry, radius)) # TODO: likely want within_radius_of_wkt_sql
    when 'polygon'
      @georeferences = Georeference.with_project_id(sessions_current_project_id)
        .joins(:geographic_item)
        .where(GeographicItem.contained_by_wkt_sql(geometry))
    else
    end
    if @georeferences.blank?
      message = 'no objects contained in drawn shape'
    end
    render_gr_select_json(message)
  end
end

#filtered_collecting_eventsObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 11

def filtered_collecting_events
  message = ''
  @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id).filter_by(params)

  if @collecting_events.blank?
    message = 'no collecting events selected'
  end
  render_ce_select_json(message)
end

#filtered_georeferencesObject



84
85
86
87
88
89
90
91
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 84

def filtered_georeferences
  message = ''
  @georeferences = Georeference.with_project_id(sessions_current_project_id).filter_by(params)
  if @georeferences.blank?
    message = 'no georeferences found'
  end
  render_gr_select_json(message)
end

#gr_render_to_htmlString

Returns of html for partial.

Returns:

  • (String)

    of html for partial



212
213
214
215
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 212

def gr_render_to_html
  render_to_string(partial: 'tasks/gis/match_georeference/georeferences_selections_form',
                   locals: {georeferences: @georeferences})
end

#indexObject



4
5
6
7
8
9
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 4

def index
  @collecting_event = CollectingEvent.new
  @georeference = Georeference.new
  @collecting_events = []
  @georeferences = []
end

#recent_collecting_eventsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 21

def recent_collecting_events
  message = ''
  how_many = params['how_many']
  @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
    .order(updated_at: :desc)
    .limit(how_many.to_i)

  if @collecting_events.blank?
    message = 'no recent objects selected'
  end

  render_ce_select_json(message)
end

#recent_georeferencesObject



93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 93

def recent_georeferences
  message = ''
  how_many = params['how_many']
  @georeferences = Georeference.with_project_id(sessions_current_project_id)
    .order(updated_at: :desc)
    .limit(how_many.to_i)
  if @georeferences.blank?
    message = 'no recent georeferences selected'
  end
  render_gr_select_json(message)
end

#render_ce_select_json(message) ⇒ JSON

Returns with html for collecting events display (table of selectable collecting events).

Parameters:

  • message (String)

    to be conveyed to client side

Returns:

  • (JSON)

    with html for collecting events display (table of selectable collecting events)



194
195
196
197
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 194

def render_ce_select_json(message)
  # retval = render_to_html
  render json: {message: message, html: ce_render_to_html}
end

#render_gr_select_json(message) ⇒ JSON

Returns with html for georeferences display (feature collection).

Parameters:

  • message (String)

    to be conveyed to client side

Returns:

  • (JSON)

    with html for georeferences display (feature collection)



201
202
203
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 201

def render_gr_select_json(message)
  render json: {message: message, html: gr_render_to_html}
end

#tagged_collecting_eventsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 35

def tagged_collecting_events
  message = ''
  if params[:keyword_id].blank?
    # Bad search request; return not a list but back to the form
    @collecting_events = CollectingEvent.where('false')
  else
    keyword = Keyword.find(params[:keyword_id])
    @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id)
      .order(updated_at: :desc)
      .tagged_with_keyword(keyword)
  end

  if @collecting_events.blank?
    message = 'no tagged objects selected'
  end
  render_ce_select_json(message)
end

#tagged_georeferencesObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 105

def tagged_georeferences
  message = ''

  # todo: this needs to be rationalized, but works, after a fashion.
  if params[:keyword_id].blank?
    # render json: {html: 'Empty set'} #and return
    @georeferences = Georeference.where('false')
  else
    keyword = Keyword.find(params[:keyword_id])
    @georeferences = Georeference.with_project_id(sessions_current_project_id)
      .order(updated_at: :desc)
      .tagged_with_keyword(keyword)
  end
  if @georeferences.blank?
    message = 'no tagged objects selected'
  end
  render_gr_select_json(message)
end