Skip to content

Commit

Permalink
Affichage des date au format local (#584)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
amandine-sahl and geobrun authored Nov 6, 2024
1 parent dec1c21 commit cef0a80
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions atlas/modeles/repositories/vmObservationsRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
97 changes: 45 additions & 52 deletions atlas/static/mapGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<b>Date: </b> ${formatDate(date)}
</br><b>Altitude: </b> ${feature.properties.altitude_retenue}
${observersTxt(feature)}`

// verifie si le champs effectif est rempli
if (feature.properties.effectif_total != undefined) {
popupContent = `${popupContent} </br><b>Effectif: </b>${feature.properties.effectif_total}`
}

// S'il faut lier à une fiche espèce
if (linkSpecies == true) {
popupContent = `<b>Espèce: </b> ${feature.properties.taxon} </br>
${popupContent}
</br>
<a href='${configuration.URL_APPLICATION}${language}/espece/${feature.properties.cd_ref}'> Fiche espèce </a>
`
}
return popupContent
}


function generateMap(zoomHomeButton) {
// Map initialization
firstMapTile = L.tileLayer(configuration.MAP.FIRST_MAP.url, {
Expand Down Expand Up @@ -153,24 +191,9 @@ function observersTxt(feature) {
//****** Fonction fiche espècce ***********

// Popup Point
function onEachFeaturePoint(feature, layer) {
popupContent =
"<b>Date: </b>" +
feature.properties.dateobs +
"</br><b>Altitude: </b>" +
feature.properties.altitude_retenue +
observersTxt(feature)

// verifie si le champs effectif est rempli
if (feature.properties.effectif_total != undefined) {
layer.bindPopup(
popupContent +
"</br><b>Effectif: </b>" +
feature.properties.effectif_total
);
} else {
layer.bindPopup(popupContent);
}
function onEachFeaturePoint(feature, layer) {
popupContent = generateObservationPopup(feature, false);
layer.bindPopup(popupContent);
}

// popup Maille
Expand Down Expand Up @@ -425,43 +448,13 @@ function displayMarkerLayerFicheEspece(
/* *** Point ****/

function onEachFeaturePointLastObs(feature, layer) {
popupContent =
"<b>Espèce: </b>" +
feature.properties.taxon +
"</br><b>Date: </b>" +
feature.properties.dateobs +
"</br><b>Altitude: </b>" +
feature.properties.altitude_retenue;

layer.bindPopup(
popupContent +
"</br> <a href='" +
configuration.URL_APPLICATION +
language +
"/espece/" +
feature.properties.cd_ref +
"'> Fiche espèce </a>"
);
popupContent = generateObservationPopup(feature, true);
layer.bindPopup(popupContent);
}

function onEachFeaturePointCommune(feature, layer) {
popupContent =
"<b>Espèce: </b>" +
feature.properties.taxon +
"</br><b>Date: </b>" +
feature.properties.dateobs +
"</br><b>Altitude: </b>" +
feature.properties.altitude_retenue +
observersTxt(feature)

layer.bindPopup(
popupContent +
"</br> <a href='" +
configuration.URL_APPLICATION +
"/espece/" +
feature.properties.cd_ref +
"'> Fiche espèce </a>"
);
popupContent = generateObservationPopup(feature, true);
layer.bindPopup(popupContent);
}

function generateGeojsonPointLastObs(observationsPoint) {
Expand Down
2 changes: 1 addition & 1 deletion atlas/templates/home/lastObs.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3 class="card-title"><i class="fas fa-binoculars icon-color-title"></i>
</a>
</span>
<p class="singleTaxon name" cdref="{{ obs.cd_ref }}">{{ obs.taxon|safe }}<br />
{{ obs.dateobs }} </p>
{{obs.dateobs | dateformat("short")}} </p>
<span class="hidden" hidden="true">{{ obs.cd_ref }}</span>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion atlas/templates/home/newSpecies.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h3 class="card-title title-spaced">

</div>
<div class="card-footer center text-muted">
{{species.date}}
{{species.date | dateformat("short")}}
</div>
</div>
</div>
Expand Down

0 comments on commit cef0a80

Please sign in to comment.