Class: Tasks::Gis::MatchGeoreferenceController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Tasks::Gis::MatchGeoreferenceController
- Includes:
- TaskControllerConfiguration
- Defined in:
- app/controllers/tasks/gis/match_georeference_controller.rb
Instance Method Summary collapse
- #batch_create_match_georeferences ⇒ Object
-
#ce_render_to_html ⇒ String
Of html for partial.
- #drawn_collecting_events ⇒ Object
-
#drawn_georeferences ⇒ Object
TODO: if kept replace with a Georeferences filter.
- #filtered_collecting_events ⇒ Object
- #filtered_georeferences ⇒ Object
-
#gr_render_to_html ⇒ String
Of html for partial.
- #index ⇒ Object
- #recent_collecting_events ⇒ Object
- #recent_georeferences ⇒ Object
-
#render_ce_select_json(message) ⇒ JSON
With html for collecting events display (table of selectable collecting events).
-
#render_gr_select_json(message) ⇒ JSON
With html for georeferences display (feature collection).
- #tagged_collecting_events ⇒ Object
- #tagged_georeferences ⇒ Object
Methods included from TaskControllerConfiguration
Instance Method Details
#batch_create_match_georeferences ⇒ Object
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 = '' 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? = 'No collecting events were selected.' end html = render_to_string(partial: 'georeference_success', formats: 'html', locals: {georeferences_results: results} ) render json: {message: , html: html } } end end |
#ce_render_to_html ⇒ String
Returns 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_events ⇒ Object
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 = '' 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? = 'no georeferences found' end render_ce_select_json() end |
#drawn_georeferences ⇒ Object
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 = '' 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? = 'no objects contained in drawn shape' end render_gr_select_json() end end |
#filtered_collecting_events ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 11 def filtered_collecting_events = '' @collecting_events = CollectingEvent.with_project_id(sessions_current_project_id).filter_by(params) if @collecting_events.blank? = 'no collecting events selected' end render_ce_select_json() end |
#filtered_georeferences ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/controllers/tasks/gis/match_georeference_controller.rb', line 84 def filtered_georeferences = '' @georeferences = Georeference.with_project_id(sessions_current_project_id).filter_by(params) if @georeferences.blank? = 'no georeferences found' end render_gr_select_json() end |
#gr_render_to_html ⇒ String
Returns 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 |
#index ⇒ Object
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_events ⇒ Object
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 = '' 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? = 'no recent objects selected' end render_ce_select_json() end |
#recent_georeferences ⇒ Object
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 = '' 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? = 'no recent georeferences selected' end render_gr_select_json() end |
#render_ce_select_json(message) ⇒ JSON
Returns 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() # retval = render_to_html render json: {message: , html: ce_render_to_html} end |
#render_gr_select_json(message) ⇒ JSON
Returns 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() render json: {message: , html: gr_render_to_html} end |
#tagged_collecting_events ⇒ Object
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 = '' 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? = 'no tagged objects selected' end render_ce_select_json() end |
#tagged_georeferences ⇒ Object
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 = '' # 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? = 'no tagged objects selected' end render_gr_select_json() end |