[ofbiz-framework] branch trunk updated: Improved: Allow to pass a Google API key for geolocation (OFBIZ-12247)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Allow to pass a Google API key for geolocation (OFBIZ-12247)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new fec6559  Improved: Allow to pass a Google API key for geolocation (OFBIZ-12247)
fec6559 is described below

commit fec6559e7b3f82604514868b0de72a9e47758d7a
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Sat May 29 12:06:16 2021 +0200

    Improved: Allow to pass a Google API key for geolocation (OFBIZ-12247)
   
    This is related to this question from Daniel at
    https://github.com/apache/ofbiz-framework/pull/220
   
    I couldn't figure out how to configure OFBiz with my Google API key so ended up
    temporarily patching
    themes/common-theme/template/includes/GeoLocation.ftl line 44 with my key.
    Line 44 looked similar to:
    <script src="https://maps.googleapis.com/maps/api/js?key=secret_google_api_key" type="application/javascript"></script>
   
    Is there a way to configure ofbiz with the API key?
   
    Disclaimer: w/o a not free "Google API key" I was not able to test, will ask
    Daniel...
---
 framework/common/config/CommonUiLabels.xml            |  4 ++++
 framework/common/config/general.properties            | 11 +++++++----
 themes/common-theme/template/includes/GeoLocation.ftl | 18 +++++++++++-------
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/framework/common/config/CommonUiLabels.xml b/framework/common/config/CommonUiLabels.xml
index edb167f..f29cd55 100644
--- a/framework/common/config/CommonUiLabels.xml
+++ b/framework/common/config/CommonUiLabels.xml
@@ -7692,6 +7692,10 @@
         <value xml:lang="zh">没有可用的地理位置(作为演示,你可以使用演示客户会员资料)</value>
         <value xml:lang="zh-TW">沒有可用的地理位置(若作為Demo,你可以使用 DemoCustomer 團體相關資料)</value>
     </property>
+    <property key="CommonNoGoogleAPIkeyAvailable">
+        <value xml:lang="en">No Google API key Available</value>
+        <value xml:lang="fr">Aucune clef d'API Google disponible</value>
+    </property>
     <property key="CommonNoOptions">
         <value xml:lang="ar">لا يوجد خيار: _NA_</value>
         <value xml:lang="cs">Žádné volby: _NA_</value>
diff --git a/framework/common/config/general.properties b/framework/common/config/general.properties
index e2c8fce..c755f65 100644
--- a/framework/common/config/general.properties
+++ b/framework/common/config/general.properties
@@ -35,7 +35,7 @@ VISUAL_THEME=RAINBOWSTONE_SAPHIR
 #    start getting "resource not found" exceptions, then there are
 #    properties missing in the locale you specified. This property does not
 #    control the default locale - the default locale is set in start.properties.
-#    
+#
 locale.properties.fallback=en
 
 # -- Locales made available, separated by commas. This property controls
@@ -71,7 +71,7 @@ defaultFromEmailAddress=[hidden email]
 defaultFromTelecomAddress=IOFBIZ
 
 # -- The default domainname used in the notification emails links
-# as 'baseUrl' and 'baseSecureUrl' are set in the url.properties file.
+# as 'baseUrl' and 'baseSecureUrl' are set in the url.properties file.
 
 # -- mail notifications enabled (Y|N)
 mail.notifications.enabled=N
@@ -131,11 +131,14 @@ http.upload.max.size=-1
 # -- HTTP JSON settings
 http.json.xssi.prefix=//
 
-# -- Save Entity Sync Remove Info. This is used in the context of Entity Sync, doc currently updated, WIP at OFBIZ-10390...  
-saveEntitySyncRemoveInfo=false
+# -- Save Entity Sync Remove Info. This is used in the context of Entity Sync, doc currently updated, WIP at OFBIZ-10390...
+saveEntitySyncRemoveInfo=false
 
 # -- Y if you want to display the multi-tenant textbox in the login page and install specify components which related to each tenant
 multitenant=N
 
 # -- Default User Documentation website uri
 userDocUri=https://ci.apache.org/projects/ofbiz/site/trunk/ofbizdoc/html5/user-manual.html
+
+# -- Google API key, by default none, this is not free
+googleApiKey=
diff --git a/themes/common-theme/template/includes/GeoLocation.ftl b/themes/common-theme/template/includes/GeoLocation.ftl
index d27b494..e66c5c5 100644
--- a/themes/common-theme/template/includes/GeoLocation.ftl
+++ b/themes/common-theme/template/includes/GeoLocation.ftl
@@ -31,19 +31,19 @@ under the License.
     <#assign center = geoChart.points[0]>
     <#assign zoom = 15> <#-- 0=World, 19=max zoom in -->
   <#else>
-  <#-- hardcoded in GEOPT_ADDRESS_GOOGLE, simpler -->
+    <#-- hardcoded in GEOPT_ADDRESS_GOOGLE, simpler -->
   </#if>
 
 <#-- ================================= Google Maps Init ======================================-->
-  <#if geoChart.dataSourceId?has_content>
+  <#assign googleApiKey = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("general", "googleApiKey", delegator)>
+  <#if geoChart.dataSourceId?has_content && googleApiKey?has_content>
     <#if "GOOGLE" == geoChart.dataSourceId?substring(geoChart.dataSourceId?length-6 , geoChart.dataSourceId?length)>
-    <div id="${id}"
-         style="border:1px solid #979797; background-color:#e5e3df; width:${geoChart.width}; height:${geoChart.height}; margin:2em auto;">
+      <div id="${id}"
+        style="border:1px solid #979797; background-color:#e5e3df; width:${geoChart.width}; height:${geoChart.height}; margin:2em auto;">
         <div style="padding:1em; color:gray;">${uiLabelMap.CommonLoading}</div>
-    </div>
-    <script src="https://maps.googleapis.com/maps/api/js?sensor=false" type="application/javascript"></script>
+      </div>
+      <script src="https://maps.googleapis.com/maps/api/js?key=googleApiKey" type="application/javascript"></script>
     </#if>
-
   <#-- ========================== Here we go with different types of maps renderer ===========================-->
     <#if "GEOPT_GOOGLE" == geoChart.dataSourceId>
     <script type="application/javascript">
@@ -181,3 +181,7 @@ under the License.
 <#else>
   <h2>${uiLabelMap.CommonNoGeolocationAvailable}</h2>
 </#if>
+
+<#if !googleApiKey?has_content>
+  <h2>${uiLabelMap.CommonNoGoogleAPIkeyAvailable}</h2>
+</#if>