Skip to content
Snippets Groups Projects
Commit 9a4cbc69 authored by Jérémie BRISON's avatar Jérémie BRISON
Browse files

fix(map) : show all markers with chunked list structures

parent b0912bba
No related branches found
No related tags found
2 merge requests!31Recette,!26Show all markers on map with chunked results
<div fxLayout="row" class="content-container"> <div fxLayout="row" class="content-container">
<app-structure-list <app-structure-list
(searchEvent)="getStructures($event)" (searchEvent)="getStructures($event)"
(loadMoreStructures)="loadMoreStructures()"
[structureList]="structures" [structureList]="structures"
[location]="currentLocation" [location]="currentLocation"
(displayMapMarkerId)="setMapMarkerId($event)" (displayMapMarkerId)="setMapMarkerId($event)"
......
...@@ -21,9 +21,6 @@ export class HomeComponent implements OnInit { ...@@ -21,9 +21,6 @@ export class HomeComponent implements OnInit {
public selectedMarkerId: number; public selectedMarkerId: number;
public geolocation = false; public geolocation = false;
public currentLocation: GeoJson; public currentLocation: GeoJson;
public pageStructures = 0;
public structuresChunked: Structure[][] = [];
private chunck = 10;
public currentStructure: Structure; public currentStructure: Structure;
constructor(private structureService: StructureService, private geoJsonService: GeojsonService) {} constructor(private structureService: StructureService, private geoJsonService: GeojsonService) {}
...@@ -36,10 +33,6 @@ export class HomeComponent implements OnInit { ...@@ -36,10 +33,6 @@ export class HomeComponent implements OnInit {
} }
public getStructures(filters: Filter[]): void { public getStructures(filters: Filter[]): void {
if (filters) {
this.pageStructures = 0;
this.structuresChunked = [];
}
this.structureService.getStructures(filters).subscribe((structures) => { this.structureService.getStructures(filters).subscribe((structures) => {
filters ? (structures = this.applyFilters(structures, filters)) : structures; filters ? (structures = this.applyFilters(structures, filters)) : structures;
if (structures) { if (structures) {
...@@ -55,12 +48,7 @@ export class HomeComponent implements OnInit { ...@@ -55,12 +48,7 @@ export class HomeComponent implements OnInit {
}) })
).then((structureList) => { ).then((structureList) => {
structureList = _.sortBy(structureList, ['distance']); structureList = _.sortBy(structureList, ['distance']);
if (this.pageStructures == 0) { this.structures = structureList;
for (let i = 0; i < structureList.length; i += this.chunck) {
this.structuresChunked.push(structureList.slice(i, i + this.chunck));
}
}
this.structures = this.structuresChunked[0];
}); });
} else { } else {
this.structures = null; this.structures = null;
...@@ -147,14 +135,6 @@ export class HomeComponent implements OnInit { ...@@ -147,14 +135,6 @@ export class HomeComponent implements OnInit {
this.selectedMarkerId = id; this.selectedMarkerId = id;
} }
public loadMoreStructures(): void {
if (this.pageStructures < this.structuresChunked.length - 1) {
this.pageStructures++;
const newStructures = _.map(this.structuresChunked[this.pageStructures]);
this.structures = [...this.structures, ...newStructures];
}
}
public showDetailStructure(structure: Structure): void { public showDetailStructure(structure: Structure): void {
this.currentStructure = new Structure(structure); this.currentStructure = new Structure(structure);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div (scroll)="onScrollDown($event)" class="listCard" (mouseout)="mouseOut()"> <div (scroll)="onScrollDown($event)" class="listCard" (mouseout)="mouseOut()">
<app-card <app-card
*ngFor="let structure of structureList" *ngFor="let structure of structuresListChunked"
[structure]="structure" [structure]="structure"
(showDetails)="showDetails($event)" (showDetails)="showDetails($event)"
(hover)="handleCardHover($event)" (hover)="handleCardHover($event)"
......
...@@ -2,6 +2,8 @@ import { Component, EventEmitter, Input, OnInit, Output, OnChanges, SimpleChange ...@@ -2,6 +2,8 @@ import { Component, EventEmitter, Input, OnInit, Output, OnChanges, SimpleChange
import { Filter } from './models/filter.model'; import { Filter } from './models/filter.model';
import { Structure } from '../models/structure.model'; import { Structure } from '../models/structure.model';
import { GeoJson } from '../map/models/geojson.model'; import { GeoJson } from '../map/models/geojson.model';
import * as _ from 'lodash';
@Component({ @Component({
selector: 'app-structure-list', selector: 'app-structure-list',
templateUrl: './structure-list.component.html', templateUrl: './structure-list.component.html',
...@@ -15,15 +17,29 @@ export class StructureListComponent implements OnChanges { ...@@ -15,15 +17,29 @@ export class StructureListComponent implements OnChanges {
@Output() public displayMapMarkerId: EventEmitter<Array<number>> = new EventEmitter<Array<number>>(); @Output() public displayMapMarkerId: EventEmitter<Array<number>> = new EventEmitter<Array<number>>();
@Output() public hoverOut: EventEmitter<Array<number>> = new EventEmitter<Array<number>>(); @Output() public hoverOut: EventEmitter<Array<number>> = new EventEmitter<Array<number>>();
@Output() public selectedMarkerId: EventEmitter<number> = new EventEmitter<number>(); @Output() public selectedMarkerId: EventEmitter<number> = new EventEmitter<number>();
@Output() loadMoreStructures = new EventEmitter();
public showStructureDetails = false; public showStructureDetails = false;
public structure: Structure; public structure: Structure;
public structuresListChunked: Structure[];
private pageStructures = 0;
private arrayChunked: Structure[][] = [];
private chunck = 10;
constructor() {} constructor() {}
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
if (changes.selectedStructure && this.selectedStructure) { if (changes.selectedStructure && this.selectedStructure) {
this.showDetails(this.selectedStructure); this.showDetails(this.selectedStructure);
} }
if (changes.structureList) {
this.arrayChunked = [];
this.pageStructures = 0;
if (this.pageStructures == 0) {
for (let i = 0; i < this.structureList.length; i += this.chunck) {
this.arrayChunked.push(this.structureList.slice(i, i + this.chunck));
}
}
this.structuresListChunked = this.arrayChunked[0];
}
} }
public fetchResults(filters: Filter[]): void { public fetchResults(filters: Filter[]): void {
this.searchEvent.emit(filters); this.searchEvent.emit(filters);
...@@ -51,7 +67,14 @@ export class StructureListComponent implements OnChanges { ...@@ -51,7 +67,14 @@ export class StructureListComponent implements OnChanges {
if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight - 100) { if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight - 100) {
} }
if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight - 50) { if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight - 50) {
this.loadMoreStructures.emit(); this.loadMoreStructures();
}
}
private loadMoreStructures(): void {
if (this.pageStructures < this.arrayChunked.length - 1) {
this.pageStructures++;
const newStructures = _.map(this.arrayChunked[this.pageStructures]);
this.structuresListChunked = [...this.structuresListChunked, ...newStructures];
} }
} }
} }
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