Google Maps

This commit is contained in:
jopster 2024-07-09 11:28:54 +02:00
parent 7b2aee7004
commit e7ae0f6481
24 changed files with 1512 additions and 13 deletions

View File

@ -18,8 +18,10 @@
'views/dss_systemtypen.xml', 'views/dss_systemtypen.xml',
'views/dss_mediarelations.xml', 'views/dss_mediarelations.xml',
'views/dss_advertisementfields.xml', 'views/dss_advertisementfields.xml',
'views/dss_projects.xml','views/dss_import.xml', 'views/dss_projects.xml',
'views/dss_ads.xml','views/dss_settings.xml', 'views/dss_import.xml',
'views/dss_ads.xml',
'views/dss_settings.xml',
'views/dss_mediafiles.xml', 'views/dss_mediafiles.xml',
'views/dss_addstructures.xml', 'views/dss_addstructures.xml',
'views/dss_geraetetypen.xml', 'views/dss_geraetetypen.xml',
@ -32,6 +34,7 @@
'views/mainsystem_view.xml', 'views/mainsystem_view.xml',
'views/menu.xml', 'views/menu.xml',
'views/company_view.xml', 'views/company_view.xml',
'views/google_map.xml',
], ],
'demo': [], 'demo': [],
'installable': True, 'installable': True,
@ -40,16 +43,15 @@
'auto_install': False, 'auto_install': False,
'assets': { 'assets': {
'web.assets_backend': [ 'web.assets_backend': [
'DigitalSignage/static/src/**/*', 'DigitalSignage/static/src/img/*',
'DigitalSignage/static/src/xml/screenDesignerView.xml', 'DigitalSignage/static/src/xml/screenDesignerView.xml',
], ],
'web.assets_common': [ 'web.assets_common': [
'DigitalSignage/static/images/**/*', 'DigitalSignage/static/images/**/*',
'DigitalSignage/static/src/js/screenDesignerView.js',
'DigitalSignage/static/src/css/dss.css', 'DigitalSignage/static/src/css/dss.css',
'DigitalSignage/static/src/xml/*',
], ],
'web.assets_qweb': [ 'web.assets_qweb': [
'DigitalSignage/static/src/xml/*',
], ],
}, },
'license': 'LGPL-3', 'license': 'LGPL-3',

View File

@ -44,10 +44,12 @@ class GoogleMap(http.Controller):
'latitude': str(project.standort_lati) if project.standort_lati else False, 'latitude': str(project.standort_lati) if project.standort_lati else False,
'longitude': str(project.standort_long) if project.standort_long else False, 'longitude': str(project.standort_long) if project.standort_long else False,
}) })
partner_url = ""
values = { values = {
'partner_url': partner_url, 'project_url': partner_url,
'partner_data': scriptsafe.dumps(projects_data), 'address': project.standort_strasse,
'projects_data': scriptsafe.dumps(projects_data),
'google_maps_api_key': google_maps_api_key, 'google_maps_api_key': google_maps_api_key,
} }
return request.render("DigitalSignage.google_map", values) return request.render("DigitalSignage.google_map", values)

View File

@ -705,7 +705,7 @@ class dssprojects(models.Model):
'target':'current', 'target':'current',
'context':'{"default_project":'+str(self.id)+',"show_project_update":True}', 'context':'{"default_project":'+str(self.id)+',"show_project_update":True}',
'res_id':self.id, 'res_id':self.id,
'display_name' : self.projektname, 'display_name' : self.name,
'domain':'[("project","=",'+str(self.id)+')]' 'domain':'[("project","=",'+str(self.id)+')]'
} }
# context = ast.literal_eval(context) # context = ast.literal_eval(context)

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<odoo> <odoo>
<template id="google_map"> <template id="google_map" name="Google Maps">
&lt;!DOCTYPE html&gt; &lt;!DOCTYPE html&gt;
<html> <html>
<head> <head>
@ -9,7 +9,7 @@
<title>World Map</title> <title>World Map</title>
<link rel="stylesheet" type="text/css" href="/DigitalSignage/static/src/css/website_google_map.css"/> <link rel="stylesheet" type="text/css" href="/DigitalSignage/static/src/css/website_google_map.css"/>
</head> </head>
<body t-att-data-partner-url="partner_url or None"> <body t-att-data-partner-url="project_url or None">
<script> <script>
var odoo_partner_data = <t t-out="projects_data"/>; var odoo_partner_data = <t t-out="projects_data"/>;
</script> </script>
@ -23,6 +23,7 @@
<script type="text/javascript" src="/DigitalSignage/static/src/lib/markerclusterer.js"></script> <script type="text/javascript" src="/DigitalSignage/static/src/lib/markerclusterer.js"></script>
<script type="text/javascript" src="/DigitalSignage/static/src/js/website_google_map.js"></script> <script type="text/javascript" src="/DigitalSignage/static/src/js/website_google_map.js"></script>
</body> </body>
</html>
</html>
</template> </template>
</odoo> </odoo>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,61 @@
odoo.define('dss.screenDesigner', function (require) {
"use strict";
var AbstractAction = require('web.AbstractAction');
var core = require('web.core');
var field_utils = require('web.field_utils');
var QWeb = core.qweb;
var web_client = require('web.web_client');
var ajax = require('web.ajax');
var _t = core._t;
var rpc = require('web.rpc');
var self = this;
var session = require('web.session');
var screenDesigner = AbstractAction.extend({
contentTemplate: 'dssscreenDesignerView',
init: function(parent, context) {
this._super(parent, context);
this.dashboard_templates = ['MainSection'];
},
start: function() {
var self = this;
this.set("title", 'Dashboard');
return this._super().then(function() {
self.render_dashboards();
});
},
willStart: function(){
var self = this;
return this._super()
},
render_dashboards: function() {
var self = this;
this.fetch_data()
var templates = []
var templates = ['MainSection'];
_.each(templates, function(template) {
self.$('.o_hr_dashboard').append(QWeb.render(template, {widget: self}))
});
},
fetch_data: function() {
var self = this
// fetch data to the tiles
var def1 = this._rpc({
model: 'dss.screendesign',
method: "get_data",
})
.then(function (result) {
$('#product_templates').append('<span>' + result.uuid + '</span>');
$('#variants_count').append('<span>' + result.uuid + '</span>');
$('#products_storable').append('<span>' + result.uuid + '</span>');
$('#product_consumable').append('<span>' + result.uuid + '</span>');
});
},
});
core.action_registry.add('dss_screenDesigner_js_action', screenDesigner);
return screenDesigner;
});

View File

@ -0,0 +1,89 @@
/* global MarkerClusterer, google */
function initialize_map() {
'use strict';
// MAP CONFIG AND LOADING
var map = new google.maps.Map(document.getElementById('odoo-google-map'), {
zoom: 1,
center: {lat: 0.0, lng: 0.0},
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// ENABLE ADDRESS GEOCODING
var Geocoder = new google.maps.Geocoder();
// INFO BUBBLES
var infoWindow = new google.maps.InfoWindow();
var partners = new google.maps.MarkerImage('/website_google_map/static/src/img/partners.png', new google.maps.Size(25, 25));
var partner_url = document.body.getAttribute('data-partner-url') || '';
var markers = [];
var options = {
imagePath: '/website_google_map/static/src/lib/images/m'
};
google.maps.event.addListener(map, 'click', function() {
infoWindow.close();
});
// Display the bubble once clicked
var onMarkerClick = function() {
var marker = this;
var p = marker.partner;
infoWindow.setContent(
'<div class="marker">'+
(partner_url.length ? '<a target="_top" href="'+partner_url+p.id+'"><b>'+p.name +'</b></a>' : '<b>'+p.name+'</b>' )+
(p.type ? ' <b>' + p.type + '</b>' : '')+
' <pre>' + p.address + '</pre>'+
'</div>'
);
infoWindow.open(map, marker);
};
// Create a bubble for a partner
var set_marker = function(partner) {
// If no lat & long, geocode address
// TODO: a server cronjob that will store these coordinates in database instead of resolving them on-the-fly
if (!partner.latitude && !partner.longitude) {
Geocoder.geocode({'address': partner.address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
partner.latitude = location.ob;
partner.longitude = location.pb;
var marker = new google.maps.Marker({
partner: partner,
map: map,
icon: partners,
position: location
});
google.maps.event.addListener(marker, 'click', onMarkerClick);
markers.push(marker);
} else {
console.debug('Geocode was not successful for the following reason: ' + status);
}
});
} else {
var latLng = new google.maps.LatLng(partner.latitude, partner.longitude);
var marker = new google.maps.Marker({
partner: partner,
icon: partners,
map: map,
position: latLng
});
google.maps.event.addListener(marker, 'click', onMarkerClick);
markers.push(marker);
}
};
/* eslint-disable no-undef */
// Create the markers and cluster them on the map
if (odoo_partner_data){ /* odoo_partner_data special variable should have been defined in google_map.xml */
for (var i = 0; i < odoo_partner_data.counter; i++) {
set_marker(odoo_partner_data.partners[i]);
}
new MarkerClusterer(map, markers, options);
}
/* eslint-enable no-undef */
}
// Initialize map once the DOM has been loaded
google.maps.event.addDomListener(window, 'load', initialize_map);

29
views/google_map.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="google_map" name="Google Maps">
&lt;!DOCTYPE html&gt;
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>World Map</title>
<link rel="stylesheet" type="text/css" href="/DigitalSignage/static/src/css/website_google_map.css"/>
</head>
<body t-att-data-partner-url="project_url or None">
<script>
var odoo_projects_data = <t t-out="projects_data"/>;
</script>
<div id="odoo-google-map"></div>
<t t-if="google_maps_api_key">
<script t-attf-src="//maps.google.com/maps/api/js?key=#{google_maps_api_key}"></script>
</t>
<t t-else="1">
<script src="//maps.google.com/maps/api/js"></script>
</t>
<script type="text/javascript" src="/DigitalSignage/static/src/lib/markerclusterer.js"></script>
<script type="text/javascript" src="/DigitalSignage/static/src/js/dss_google_map.js"></script>
</body>
</html>
</template>
</odoo>