This is an automated email from the ASF dual-hosted git repository.

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

commit 7778b7692db43d34967bdd80c89c6fb104e01966
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
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...
    
    Conflicts handled by hand
      framework/common/config/general.properties
---
 framework/common/config/CommonUiLabels.xml            |  4 ++++
 framework/common/config/general.properties            |  9 ++++++---
 themes/common-theme/template/includes/GeoLocation.ftl | 18 +++++++++++-------
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/framework/common/config/CommonUiLabels.xml 
b/framework/common/config/CommonUiLabels.xml
index 97df8b7..e0cdccd 100644
--- a/framework/common/config/CommonUiLabels.xml
+++ b/framework/common/config/CommonUiLabels.xml
@@ -7559,6 +7559,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 40976b5..37e3db5 100644
--- a/framework/common/config/general.properties
+++ b/framework/common/config/general.properties
@@ -77,7 +77,7 @@ usps.address.match=(^.*?p[\\. ]*o[\\. 
]*box.*$)|(^.*?post.*?office.*?box.*$)|((^
 defaultFromEmailAddress=ofbizt...@example.com
 
 # -- 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,8 +131,11 @@ mail.spam.value=YES
 # -- 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
+
+# -- Google API key, by default none, this is not free
+googleApiKey=
\ No newline at end of file
diff --git a/themes/common-theme/template/includes/GeoLocation.ftl 
b/themes/common-theme/template/includes/GeoLocation.ftl
index 33d98cf..e840487 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">
@@ -178,3 +178,7 @@ under the License.
 <#else>
   <h2>${uiLabelMap.CommonNoGeolocationAvailable}</h2>
 </#if>
+
+<#if !googleApiKey?has_content>
+  <h2>${uiLabelMap.CommonNoGoogleAPIkeyAvailable}</h2>
+</#if>

Reply via email to