Skip to content
Snippets Groups Projects
Commit f6b63d41 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

Merge branch 'feat/structure-distance-filter' into 'dev'

feat(search): add protection on distance filter for structure in case of...

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_client!127
parents b47c6a2e ff69b22a
No related branches found
No related tags found
3 merge requests!178release V1.10.0,!135Dev,!127feat(search): add protection on distance filter for structure in case of...
......@@ -63,7 +63,7 @@ export class CartoComponent implements OnInit {
} else {
this.structureService.getStructures(filters).subscribe((structures) => {
if (structures) {
this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude);
this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude, false);
} else {
this.structures = null;
}
......@@ -87,7 +87,19 @@ export class CartoComponent implements OnInit {
});
}
private updateStructuresdistance(structures: Structure[], lon: number, lat: number): void {
/**
* Update structure distance according to user actual position.
* @param structures structures data to update
* @param lon user longitude
* @param lat user latitde
* @param sortByDistance if set to `true`, structures data is sort by distance. Default value is `true`
*/
private updateStructuresdistance(
structures: Structure[],
lon: number,
lat: number,
sortByDistance: boolean = true
): void {
Promise.all(
structures.map((structure) => {
if (this.geolocation) {
......@@ -96,7 +108,9 @@ export class CartoComponent implements OnInit {
return this.structureService.updateOpeningStructure(structure);
})
).then((structureList) => {
structureList = _.sortBy(structureList, ['distance']);
if (sortByDistance) {
structureList = _.sortBy(structureList, ['distance']);
}
this.structures = structureList;
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment