Project Maps, Trigger usw

This commit is contained in:
jopster 2024-07-08 14:52:24 +02:00
parent 3626b9c8c6
commit 7b2aee7004
24 changed files with 1459 additions and 21 deletions

View File

@ -32,7 +32,6 @@
'views/mainsystem_view.xml',
'views/menu.xml',
'views/company_view.xml',
'views/google_map_templates.xml'
],
'demo': [],
'installable': True,
@ -47,6 +46,7 @@
'web.assets_common': [
'DigitalSignage/static/images/**/*',
'DigitalSignage/static/src/css/dss.css',
'DigitalSignage/static/src/xml/*',
],
'web.assets_qweb': [
'DigitalSignage/static/src/xml/*',

View File

@ -26,12 +26,17 @@ class GoogleMap(http.Controller):
@http.route(['/google_map'], type='http', auth="public", website=True, sitemap=False)
def google_map(self, *arg, **post):
projects = request.env['dss.projects'].sudo().search([('standort_visible', '=', True)])
settings = (request.env['dss.settings'].search([],limit=1))
google_maps_api_key = settings.google_maps_key
_logger.info("Google Maps " + str(projects)+ " and Record : "+str(len(projects)))
projects_data = {
"counter": len(projects),
"projects": []
}
for project in projects.with_context(show_address=True):
projects_data["projects"].append({
'id': project.id,
@ -39,15 +44,10 @@ class GoogleMap(http.Controller):
'latitude': str(project.standort_lati) if project.standort_lati else False,
'longitude': str(project.standort_long) if project.standort_long else False,
})
if 'customers' in post.get('partner_url', ''):
partner_url = '/customers/'
else:
partner_url = '/partners/'
google_maps_api_key = request.website.google_maps_api_key
values = {
'partner_url': partner_url,
'partner_data': scriptsafe.dumps(projects_data),
'google_maps_api_key': google_maps_api_key,
}
return request.render("website_google_map.google_map", values)
return request.render("DigitalSignage.google_map", values)

View File

@ -71,6 +71,7 @@ class dssSettings(models.Model):
tuya_access_id = fields.Char('Tuya Access ID')
tuya_access_key = fields.Char('Tuya Access KEY')
tuya_endpoint = fields.Char('Tuya Access Endpoint')
google_maps_key = fields.Char('Google API Key (Maps)')
def _get_settingvalue(self,valuename):
settings = (self.env['dss.settings'].search([],limit=1))
wert = settings._origin.read([valuename])[0][valuename]

View File

@ -0,0 +1,28 @@
html {
height: 100%;
}
body {
margin: 0;
padding: 0;
height: 100%;
}
#odoo-google-map {
width: 100%;
height: 100%;
}
.marker {
font-size: 13px !important;
}
.marker a {
text-decoration: none;
}
.marker pre {
margin-top: 0;
margin-bottom: 0;
font-family: sans-serif !important;
}

BIN
static/src/img/partners.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

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);

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

1315
static/src/lib/markerclusterer.js Executable file

File diff suppressed because it is too large Load Diff

View File

@ -7,11 +7,11 @@
<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="/website_google_map/static/src/css/website_google_map.css"/>
<link rel="stylesheet" type="text/css" href="/DigitalSignage/static/src/css/website_google_map.css"/>
</head>
<body t-att-data-partner-url="partner_url or None">
<script>
var odoo_partner_data = <t t-out="partner_data"/>;
var odoo_partner_data = <t t-out="projects_data"/>;
</script>
<div id="odoo-google-map"></div>
<t t-if="google_maps_api_key">
@ -20,8 +20,8 @@
<t t-else="1">
<script src="//maps.google.com/maps/api/js"></script>
</t>
<script type="text/javascript" src="/website_google_map/static/src/lib/markerclusterer.js"></script>
<script type="text/javascript" src="/website_google_map/static/src/js/website_google_map.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>
</body>
</html>
</template>

View File

@ -40,12 +40,17 @@
</group>
</div>
<div class="row">
<group>
<group name="Tuya Einstellungen">
<field name="tuya_access_id"/>
<field name="tuya_access_key"/>
<field name="tuya_endpoint"/>
</group>
</div>
<div class="row">
<group name="Google Settings">
<field name="google_maps_key"/>
</group>
</div>
</sheet>
</form>
</field>