diff --git a/atlas/modeles/repositories/vmObservationsMaillesRepository.py b/atlas/modeles/repositories/vmObservationsMaillesRepository.py index c6385515..3628ed93 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 95c7cde7..cf17c55c 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 54cc3086..c1df7976 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 216b3974..7ce5be3e 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")}}

{% endfor %} diff --git a/atlas/templates/home/newSpecies.html b/atlas/templates/home/newSpecies.html index 72f349f1..69f732ae 100644 --- a/atlas/templates/home/newSpecies.html +++ b/atlas/templates/home/newSpecies.html @@ -47,7 +47,7 @@