Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Affichage des date au format local #584

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading