From 8403f171d550a0729af140dc54a9cd0068a3346f Mon Sep 17 00:00:00 2001 From: Xavier ARBEZ Date: Wed, 4 Nov 2020 14:29:31 +0100 Subject: [PATCH] Carte - Popup : Afficher la photo principale `main_photo` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FIX : Affiche la vignette de la photo définie comme principale pour chaque site (champ ``main_photo``). Actuellement, il semble que ce soit la dernière ajoutée sur le site qui s'affiche (en tout cas la dernière appelée dans variable array qui liste les photos du site). --- backend/routes.py | 28 ++++++++++++++++++++++++++++ backend/static/js/sites.js | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/routes.py b/backend/routes.py index 680cc2de..3b4b2370 100755 --- a/backend/routes.py +++ b/backend/routes.py @@ -359,6 +359,34 @@ def sites(): 'township': townships } + photo_ids = [] + sites_without_photo = [] + for site in sites: + photo_id = site.get('main_photo') + if photo_id: + photo_ids.append(site.get('main_photo')) + else: + sites_without_photo.append(str(site.get('id_site'))) + + query_photos = models.TPhoto.query.filter( + models.TPhoto.id_photo.in_(photo_ids) + ) + dump_photos = photo_schema.dump(query_photos).data + + if len(sites_without_photo): + sql_missing_photos_str = "select distinct on (id_site) * from geopaysages.t_photo where id_site IN (" + ",".join(sites_without_photo) + ") order by id_site, filter_date desc" + sql_missing_photos = text(sql_missing_photos_str) + missing_photos_result = db.engine.execute(sql_missing_photos).fetchall() + missing_photos = [dict(row) for row in missing_photos_result] + for missing_photo in missing_photos: + missing_photo['t_site'] = missing_photo.get('id_site') + dump_photos.append(missing_photo) + + for site in sites: + id_site = site.get('id_site') + photo = next(photo for photo in dump_photos if (photo.get('t_site') == id_site)) + site['photo'] = utils.getThumbnail(photo).get('output_url') + def getItem(name, id): return next(item for item in dbs.get(name) if item.get('id') == id) diff --git a/backend/static/js/sites.js b/backend/static/js/sites.js index e84a1b92..954851e3 100644 --- a/backend/static/js/sites.js +++ b/backend/static/js/sites.js @@ -186,7 +186,7 @@ geopsg.initSites = (options) => { if (site.ref_site) { markerText += '
' + '(réf : ' + site.ref_site + ')' } - marker.bindPopup('
' + markerText + '
', { + marker.bindPopup('
' + markerText + '
', { closeButton: false }) marker.on('mouseover', (e) => {