Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[base_google_map](base_google_map/) | 19.0.1.0.0 | <a href='https://github.com/gityopie'><img src='https://github.com/gityopie.png' width='32' height='32' style='border-radius:50%;' alt='gityopie'/></a> <a href='https://github.com/wolfhall'><img src='https://github.com/wolfhall.png' width='32' height='32' style='border-radius:50%;' alt='wolfhall'/></a> | View modes and widgets to integrate Google Maps in your UI
[web_view_google_map](web_view_google_map/) | 19.0.1.0.0 | <a href='https://github.com/gityopie'><img src='https://github.com/gityopie.png' width='32' height='32' style='border-radius:50%;' alt='gityopie'/></a> <a href='https://github.com/wolfhall'><img src='https://github.com/wolfhall.png' width='32' height='32' style='border-radius:50%;' alt='wolfhall'/></a> | Add a Google Map view type to the Odoo web client
[web_view_google_map](web_view_google_map/) | 19.0.1.0.2 | <a href='https://github.com/gityopie'><img src='https://github.com/gityopie.png' width='32' height='32' style='border-radius:50%;' alt='gityopie'/></a> <a href='https://github.com/wolfhall'><img src='https://github.com/wolfhall.png' width='32' height='32' style='border-radius:50%;' alt='wolfhall'/></a> | Add a Google Map view type to the Odoo web client

[//]: # (end addons)

Expand Down
2 changes: 1 addition & 1 deletion web_view_google_map/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Google Map View
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e3204ed739e2c2f17e8303da58167c42e5549fe7c6e2ac0959fb3fdac82bb9a1
!! source digest: sha256:247a050c0bbf71a4ea225999772a9e018f353b64e164a16e90c6371051440788
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion web_view_google_map/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Google Map View",
"summary": "Add a Google Map view type to the Odoo web client",
"version": "19.0.1.0.0",
"version": "19.0.1.0.2",
"author": "Open Source Integrators, Gray Matter Logic, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/geospatial",
Expand Down
21 changes: 21 additions & 0 deletions web_view_google_map/i18n/web_view_google_map.pot
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ msgstr ""
msgid "Action Window View"
msgstr ""

#. module: web_view_google_map
#. odoo-javascript
#: code:addons/web_view_google_map/static/src/views/google_map/google_map_renderer.xml:0
msgid "Configure API key"
msgstr ""

#. module: web_view_google_map
#: model:ir.model.fields,field_description:web_view_google_map.field_ir_actions_act_window_view__display_name
#: model:ir.model.fields,field_description:web_view_google_map.field_ir_ui_view__display_name
Expand All @@ -35,6 +41,12 @@ msgstr ""
msgid "Google Maps"
msgstr ""

#. module: web_view_google_map
#. odoo-javascript
#: code:addons/web_view_google_map/static/src/views/google_map/google_map_renderer.xml:0
msgid "Google Maps API key required"
msgstr ""

#. module: web_view_google_map
#. odoo-javascript
#: code:addons/web_view_google_map/static/src/fields/gplaces_address_form.esm.js:0
Expand All @@ -59,6 +71,15 @@ msgstr ""
msgid "New"
msgstr ""

#. module: web_view_google_map
#. odoo-javascript
#: code:addons/web_view_google_map/static/src/views/google_map/google_map_renderer.xml:0
msgid ""
"Set a valid Google Maps API key to display this map.\n"
" Enable the Maps JavaScript API for your key in Google Cloud\n"
" Console."
msgstr ""

#. module: web_view_google_map
#: model:ir.model,name:web_view_google_map.model_ir_ui_view
msgid "View"
Expand Down
2 changes: 1 addition & 1 deletion web_view_google_map/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ <h1>Google Map View</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e3204ed739e2c2f17e8303da58167c42e5549fe7c6e2ac0959fb3fdac82bb9a1
!! source digest: sha256:247a050c0bbf71a4ea225999772a9e018f353b64e164a16e90c6371051440788
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/geospatial/tree/19.0/web_view_google_map"><img alt="OCA/geospatial" src="https://img.shields.io/badge/github-OCA%2Fgeospatial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/geospatial-19-0/geospatial-19-0-web_view_google_map"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/geospatial&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a Google Maps view type and Places autocomplete field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class GoogleMapRenderer extends Component {
this.infoWindow = null;
this.records = [];
this.theme = "default";
this.missingApiKey = false;

const archEl = normalizeArch(this.props.archInfo?.arch || this.props.arch);
const attrs = archEl.attributes || {};
Expand All @@ -80,12 +81,19 @@ export class GoogleMapRenderer extends Component {
);

onWillStart(async () => {
await loadGoogleMaps(this.orm);
const maps = await loadGoogleMaps(this.orm);
if (!maps) {
this.missingApiKey = true;
return;
}
await this.loadTheme();
await this.loadRecords();
});

onMounted(() => {
if (this.missingApiKey) {
return;
}
this.initMap();
this.renderMarkers();
});
Expand All @@ -97,6 +105,16 @@ export class GoogleMapRenderer extends Component {
});
}

openGoogleMapsSettings() {
this.action.doAction({
type: "ir.actions.act_window",
res_model: "res.config.settings",
views: [[false, "form"]],
target: "current",
context: {module: "base_google_map"},
});
}

async loadTheme() {
try {
const data = await rpc("/web/map_theme");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@
margin-bottom: 0.25rem;
}
}

.o_google_map_missing_key {
display: flex;
align-items: center;
justify-content: center;
min-height: 400px;
height: 100%;
text-align: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@
<templates xml:space="preserve">
<t t-name="web_view_google_map.GoogleMapRenderer">
<div class="o_google_map_view h-100" t-ref="root">
<div t-ref="mapContainer" class="o_google_map_container h-100" />
<div t-if="missingApiKey" class="o_view_nocontent o_google_map_missing_key">
<div class="o_nocontent_help">
<p class="o_view_nocontent_smiling_face">
Google Maps API key required
</p>
<p>
Set a valid Google Maps API key to display this map.
Enable the Maps JavaScript API for your key in Google Cloud
Console.
</p>
<button
type="button"
class="btn btn-primary"
t-on-click="openGoogleMapsSettings"
>
Configure API key
</button>
</div>
</div>
<div t-else="" t-ref="mapContainer" class="o_google_map_container h-100" />
</div>
</t>
</templates>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ import {loadJS} from "@web/core/assets";

let googleMapsPromise = null;

/** Demo / unset values that must not be sent to Google. */
const UNUSABLE_API_KEYS = new Set(["", "YOUR_GOOGLE_MAPS_API_KEY"]);

/**
* @param {String|false|null|undefined} apiKey
* @returns {Boolean}
*/
export function isUsableGoogleMapsApiKey(apiKey) {
return !UNUSABLE_API_KEYS.has(String(apiKey || "").trim());
}

/**
* Load the Google Maps JS API using keys/libraries from ir.config_parameter.
* Parameters are managed by base_google_map.
* @param {Object} orm - ORM service (`useService("orm")`)
* @returns {Promise<typeof google.maps>}
* @returns {Promise<typeof google.maps|null>} maps API, or null if no usable key
*/
export async function loadGoogleMaps(orm) {
if (window.google?.maps) {
Expand Down Expand Up @@ -35,15 +46,17 @@ export async function loadGoogleMaps(orm) {
]),
]);

if (!isUsableGoogleMapsApiKey(apiKey)) {
return null;
}

const url = new URL("https://maps.googleapis.com/maps/api/js");
url.searchParams.set("v", "quarterly");
url.searchParams.set(
"libraries",
String(libraries || "geometry,places").replace(/^,+|,+$/g, "")
);
if (apiKey) {
url.searchParams.set("key", apiKey);
}
url.searchParams.set("key", String(apiKey).trim());
// Lang/region may already include "&language=xx" from base_google_map
const langCode = String(lang || "").includes("=")
? String(lang).split("=").pop()
Expand Down