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

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

feat(search): add protection on distance filter for structure in case of search query. Increase search result display
parent b47c6a2e
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 { ...@@ -63,7 +63,7 @@ export class CartoComponent implements OnInit {
} else { } else {
this.structureService.getStructures(filters).subscribe((structures) => { this.structureService.getStructures(filters).subscribe((structures) => {
if (structures) { if (structures) {
this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude); this.updateStructuresdistance(structures, this.userLongitude, this.userLatitude, false);
} else { } else {
this.structures = null; this.structures = null;
} }
...@@ -87,7 +87,19 @@ export class CartoComponent implements OnInit { ...@@ -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( Promise.all(
structures.map((structure) => { structures.map((structure) => {
if (this.geolocation) { if (this.geolocation) {
...@@ -96,7 +108,9 @@ export class CartoComponent implements OnInit { ...@@ -96,7 +108,9 @@ export class CartoComponent implements OnInit {
return this.structureService.updateOpeningStructure(structure); return this.structureService.updateOpeningStructure(structure);
}) })
).then((structureList) => { ).then((structureList) => {
structureList = _.sortBy(structureList, ['distance']); if (sortByDistance) {
structureList = _.sortBy(structureList, ['distance']);
}
this.structures = structureList; 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