From bd2310f88e16b3b08feee92cc8cc13e307ea2e7e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 6 Aug 2013 15:31:27 +0200 Subject: [PATCH] Converted to config option, thanks to Roy! --- app/models/observer/user/geo.rb | 8 +++++-- config/application.rb | 2 +- db/migrate/20130806000001_update_geo.rb | 29 +++++++++++++++++++++++++ db/seeds.rb | 23 +++++++++++++++++++- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20130806000001_update_geo.rb diff --git a/app/models/observer/user/geo.rb b/app/models/observer/user/geo.rb index 0c7aa5ab4..0d6053204 100644 --- a/app/models/observer/user/geo.rb +++ b/app/models/observer/user/geo.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ -require 'gmaps' class Observer::User::Geo < ActiveRecord::Observer observe 'user' @@ -54,8 +53,13 @@ class Observer::User::Geo < ActiveRecord::Observer # return if no address is given return if address == '' + # load adapter + adapter = Setting.get('geo_backend') + return if !adapter + adapter_module = Object.const_get(adapter) + # db lookup - latlng = Gmaps.geocode(address) + latlng = adapter_module.geocode(address) return if !latlng # store data diff --git a/config/application.rb b/config/application.rb index 506e6a9ab..5054a5295 100644 --- a/config/application.rb +++ b/config/application.rb @@ -40,9 +40,9 @@ module Zammad 'observer::_ticket::_article::_communicate_facebook', 'observer::_ticket::_article::_communicate_twitter', 'observer::_ticket::_notification', - 'observer::_tag::_ticket_history', 'observer::_ticket::_reset_new_state', 'observer::_ticket::_escalation_calculation', + 'observer::_tag::_ticket_history', 'observer::_user::_geo' diff --git a/db/migrate/20130806000001_update_geo.rb b/db/migrate/20130806000001_update_geo.rb new file mode 100644 index 000000000..dd3bad9ca --- /dev/null +++ b/db/migrate/20130806000001_update_geo.rb @@ -0,0 +1,29 @@ +class UpdateGeo < ActiveRecord::Migration + def up + Setting.create_if_not_exists( + :title => 'Geo Location Backend', + :name => 'geo_backend', + :area => 'System::Geo', + :description => 'Defines the backend for geo location lookups.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'geo_backend', + :tag => 'select', + :options => { + '' => '-', + 'Gmaps' => 'Google Maps', + }, + }, + ], + }, + :state => 'Gmaps', + :frontend => true + ) + end + def down + end +end + diff --git a/db/seeds.rb b/db/seeds.rb index 7590c9a42..ed4f5e25b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -133,7 +133,28 @@ Setting.create_if_not_exists( :state => 'DB', :frontend => false ) - +Setting.create_if_not_exists( + :title => 'Geo Location Backend', + :name => 'geo_backend', + :area => 'System::Geo', + :description => 'Defines the backend for geo location lookups.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'geo_backend', + :tag => 'select', + :options => { + '' => '-', + 'Gmaps' => 'Google Maps', + }, + }, + ], + }, + :state => 'Gmaps', + :frontend => true +) Setting.create_if_not_exists( :title => 'New User Accounts',