From cef0a805fdf5985aaea68347d97abdcfed6bacb3 Mon Sep 17 00:00:00 2001
From: Amandine
Date: Wed, 6 Nov 2024 13:47:23 +0100
Subject: [PATCH] Affichage des date au format local (#584)
* Update mapGenerator.js
* Update vmObservationsRepository.py
* Update newSpecies.html
* Update lastObs.html
* Update vmObservationsMaillesRepository.py
* Factorisation popup
* Use short date
---------
Co-authored-by: Geoffrey Brun <68049696+geobrun@users.noreply.github.com>
---
.../vmObservationsMaillesRepository.py | 2 +-
.../repositories/vmObservationsRepository.py | 6 +-
atlas/static/mapGenerator.js | 97 +++++++++----------
atlas/templates/home/lastObs.html | 2 +-
atlas/templates/home/newSpecies.html | 2 +-
5 files changed, 51 insertions(+), 58 deletions(-)
diff --git a/atlas/modeles/repositories/vmObservationsMaillesRepository.py b/atlas/modeles/repositories/vmObservationsMaillesRepository.py
index c6385515e..3628ed93e 100644
--- a/atlas/modeles/repositories/vmObservationsMaillesRepository.py
+++ b/atlas/modeles/repositories/vmObservationsMaillesRepository.py
@@ -83,7 +83,7 @@ def lastObservationsMailles(connection, mylimit, idPhoto):
"id_observation": o.id_observation,
"id_maille": o.id_maille,
"cd_ref": o.cd_ref,
- "dateobs": str(o.dateobs),
+ "dateobs": o.dateobs,
"altitude_retenue": o.altitude_retenue,
"taxon": taxon,
"geojson_maille": json.loads(o.geojson_maille),
diff --git a/atlas/modeles/repositories/vmObservationsRepository.py b/atlas/modeles/repositories/vmObservationsRepository.py
index 95c7cde77..cf17c55ce 100644
--- a/atlas/modeles/repositories/vmObservationsRepository.py
+++ b/atlas/modeles/repositories/vmObservationsRepository.py
@@ -95,7 +95,7 @@ def lastObservations(connection, mylimit, idPhoto):
temp = dict(o)
temp.pop("the_geom_point", None)
temp["geojson_point"] = json.loads(o.geojson_point or "{}")
- temp["dateobs"] = str(o.dateobs)
+ temp["dateobs"] = o.dateobs
temp["group2_inpn"] = utils.deleteAccent(o.group2_inpn)
temp["pathImg"] = utils.findPath(o)
obsList.append(temp)
@@ -122,7 +122,7 @@ def lastObservationsCommune(connection, mylimit, insee):
temp = dict(o)
temp.pop("the_geom_point", None)
temp["geojson_point"] = json.loads(o.geojson_point or "{}")
- temp["dateobs"] = str(o.dateobs)
+ temp["dateobs"] = o.dateobs
obsList.append(temp)
return obsList
@@ -150,7 +150,7 @@ def getObservationTaxonCommune(connection, insee, cd_ref):
temp = dict(o)
temp.pop("the_geom_point", None)
temp["geojson_point"] = json.loads(o.geojson_point or "{}")
- temp["dateobs"] = str(o.dateobs)
+ temp["dateobs"] = o.dateobs
obsList.append(temp)
return obsList
diff --git a/atlas/static/mapGenerator.js b/atlas/static/mapGenerator.js
index 54cc30863..c1df79768 100644
--- a/atlas/static/mapGenerator.js
+++ b/atlas/static/mapGenerator.js
@@ -19,6 +19,44 @@ const areaBorderColor = String(
)
);
+function formatDate(date) {
+ const date_options = {
+ year: 'numeric',
+ month: 'numeric',
+ day: 'numeric',
+ };
+ return date.toLocaleDateString(undefined, date_options);
+}
+
+function generateObservationPopup(feature, linkSpecies = false) {
+ /*
+ Génération popup des observations
+ linkSpecies : indique s'il faut ou non rajouter un lien vers la fiche espèce
+ (cas des fiches communes ; home page)
+ */
+ date = new Date(feature.properties.dateobs);
+ popupContent = `
+ Date: ${formatDate(date)}
+ Altitude: ${feature.properties.altitude_retenue}
+ ${observersTxt(feature)}`
+
+ // verifie si le champs effectif est rempli
+ if (feature.properties.effectif_total != undefined) {
+ popupContent = `${popupContent} Effectif: ${feature.properties.effectif_total}`
+ }
+
+ // S'il faut lier à une fiche espèce
+ if (linkSpecies == true) {
+ popupContent = `Espèce: ${feature.properties.taxon}
+ ${popupContent}
+
+ Fiche espèce
+ `
+ }
+ return popupContent
+}
+
+
function generateMap(zoomHomeButton) {
// Map initialization
firstMapTile = L.tileLayer(configuration.MAP.FIRST_MAP.url, {
@@ -153,24 +191,9 @@ function observersTxt(feature) {
//****** Fonction fiche espècce ***********
// Popup Point
-function onEachFeaturePoint(feature, layer) {
- popupContent =
- "Date: " +
- feature.properties.dateobs +
- "Altitude: " +
- feature.properties.altitude_retenue +
- observersTxt(feature)
-
- // verifie si le champs effectif est rempli
- if (feature.properties.effectif_total != undefined) {
- layer.bindPopup(
- popupContent +
- "Effectif: " +
- feature.properties.effectif_total
- );
- } else {
- layer.bindPopup(popupContent);
- }
+function onEachFeaturePoint(feature, layer) {
+ popupContent = generateObservationPopup(feature, false);
+ layer.bindPopup(popupContent);
}
// popup Maille
@@ -425,43 +448,13 @@ function displayMarkerLayerFicheEspece(
/* *** Point ****/
function onEachFeaturePointLastObs(feature, layer) {
- popupContent =
- "Espèce: " +
- feature.properties.taxon +
- "Date: " +
- feature.properties.dateobs +
- "Altitude: " +
- feature.properties.altitude_retenue;
-
- layer.bindPopup(
- popupContent +
- " Fiche espèce "
- );
+ popupContent = generateObservationPopup(feature, true);
+ layer.bindPopup(popupContent);
}
function onEachFeaturePointCommune(feature, layer) {
- popupContent =
- "Espèce: " +
- feature.properties.taxon +
- "Date: " +
- feature.properties.dateobs +
- "Altitude: " +
- feature.properties.altitude_retenue +
- observersTxt(feature)
-
- layer.bindPopup(
- popupContent +
- " Fiche espèce "
- );
+ popupContent = generateObservationPopup(feature, true);
+ layer.bindPopup(popupContent);
}
function generateGeojsonPointLastObs(observationsPoint) {
diff --git a/atlas/templates/home/lastObs.html b/atlas/templates/home/lastObs.html
index 216b39748..7ce5be3ea 100644
--- a/atlas/templates/home/lastObs.html
+++ b/atlas/templates/home/lastObs.html
@@ -45,7 +45,7 @@
{{ obs.taxon|safe }}
- {{ obs.dateobs }}
+ {{obs.dateobs | dateformat("short")}}
{{ obs.cd_ref }}
{% endfor %}
diff --git a/atlas/templates/home/newSpecies.html b/atlas/templates/home/newSpecies.html
index 72f349f1c..69f732aef 100644
--- a/atlas/templates/home/newSpecies.html
+++ b/atlas/templates/home/newSpecies.html
@@ -47,7 +47,7 @@