Skip to content
Snippets Groups Projects
Unverified Commit abcd1f49 authored by Arnaud Levy's avatar Arnaud Levy Committed by GitHub
Browse files

Fix #2372 (#2373)

parent 8538dc02
No related branches found
No related tags found
No related merge requests found
class GeocodingJob < ApplicationJob
queue_as :mice
def perform(object)
object.geocode
object.save
end
end
\ No newline at end of file
......@@ -4,7 +4,7 @@ module WithGeolocation
included do
geocoded_by :full_street_address
after_validation :geocode, if: -> (geocodable) { geocodable.full_street_address_present? && geocodable.full_street_address_changed? }
after_save_commit :geocode_in_background_if_necessary
end
def full_street_address
......@@ -26,6 +26,11 @@ module WithGeolocation
latitude.present? && longitude.present?
end
def geocode_in_background_if_necessary
return unless geocodable? && needs_new_geocoding?
GeocodingJob.perform_later(self)
end
def latlong
@latlong ||= [latitude, longitude]
end
......@@ -36,11 +41,16 @@ module WithGeolocation
protected
def full_street_address_present?
address.present? || zipcode.present? || city.present?
def geocodable?
address.present? ||
zipcode.present? ||
city.present?
end
def full_street_address_changed?
address_changed? || zipcode_changed? || city_changed? || country_changed?
def needs_new_geocoding?
saved_change_to_address? ||
saved_change_to_zipcode? ||
saved_change_to_city? ||
saved_change_to_country?
end
end
......@@ -9,8 +9,8 @@ hide_blank ||= false
title = object.class.human_attribute_name(property)
%>
<% unless hide_blank && is_blank %>
<%= osuny_label title %>
<div>
<div class="mb-4">
<%= osuny_label title %><br>
<%
if source
# source is a l10n
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment