Commit 8a8268e7 authored by Matthieu Benoist's avatar Matthieu Benoist
Browse files

Refactoring the code to corrects multiple useless data calls.

parent adb684ea
...@@ -160,7 +160,7 @@ export class ResourceQueryableComponent implements OnInit { ...@@ -160,7 +160,7 @@ export class ResourceQueryableComponent implements OnInit {
this.initInseeLabel(this._datasetDetailService.datasetData); this.initInseeLabel(this._datasetDetailService.datasetData);
} }
else { else {
this._datasetDetailService.retrieveDatasetData().subscribe(() => { this._datasetDetailService.sampleDataLoaded$.subscribe((data) => {
this.initInseeLabel(this._datasetDetailService.datasetData); this.initInseeLabel(this._datasetDetailService.datasetData);
}); });
} }
......
...@@ -60,6 +60,8 @@ export class DatasetDetailComponent implements OnInit, OnDestroy { ...@@ -60,6 +60,8 @@ export class DatasetDetailComponent implements OnInit, OnDestroy {
this.isLoading = true; this.isLoading = true;
this.initDatasetInfo(); this.initDatasetInfo();
}); });
this._datasetDetailService.retrieveDatasetData().subscribe();
} }
ngOnDestroy() { ngOnDestroy() {
......
...@@ -114,17 +114,27 @@ export class ResourceDownloadItemComponent implements OnInit { ...@@ -114,17 +114,27 @@ export class ResourceDownloadItemComponent implements OnInit {
this.selectedProjection = this.projectionList[0]; this.selectedProjection = this.projectionList[0];
} }
// Set the insee property label for this dataset // Set the insee property label for this dataset
if (this._datasetDetailService.datasetData[0]) { if (this._datasetDetailService.datasetData[0]) {
const properties = Object.keys(this._datasetDetailService.datasetData[0].properties); this.setInseeProperties();
this.inseeLabel = properties.find((prop) => { return prop.includes('insee'); }); } else {
this._datasetDetailService.sampleDataLoaded$.subscribe((data) => {
this.setInseeProperties();
});
} }
this.communeInseeList.sort((a, b) => (a.commune.localeCompare(b.commune)));
this.setProjection(this.selectedProjection); this.setProjection(this.selectedProjection);
} }
} }
setInseeProperties ()
{
const properties = Object.keys(this._datasetDetailService.datasetData[0].properties);
this.inseeLabel = properties.find((prop) => { return prop.includes('insee'); });
this.communeInseeList.sort((a, b) => (a.commune.localeCompare(b.commune)));
}
getFormatName() { getFormatName() {
return this.format ? this.format.name : this.link.formats[0]; return this.format ? this.format.name : this.link.formats[0];
...@@ -199,6 +209,7 @@ export class ResourceDownloadItemComponent implements OnInit { ...@@ -199,6 +209,7 @@ export class ResourceDownloadItemComponent implements OnInit {
// Set the selected insee and set the queryable parameters // Set the selected insee and set the queryable parameters
// depending on the resource // depending on the resource
setInsee(insee) { setInsee(insee) {
this.selectedInsee = insee; this.selectedInsee = insee;
if (!this.selectedInsee || !this.inseeLabel) { if (!this.selectedInsee || !this.inseeLabel) {
this.queryableParameters.insee = ''; this.queryableParameters.insee = '';
......
...@@ -63,10 +63,15 @@ export class DatasetTableMapComponent implements OnInit, OnDestroy { ...@@ -63,10 +63,15 @@ export class DatasetTableMapComponent implements OnInit, OnDestroy {
this.searchInput.setValue(this._datasetDetailService.searchString); this.searchInput.setValue(this._datasetDetailService.searchString);
if (this.hasTable) { if (this.hasTable) {
// If dataset has table then preload some data for the table component if (this._datasetDetailService.datasetData){
this._datasetDetailService.retrieveDatasetData().subscribe(() => {
this.dataLoaded = true; this.dataLoaded = true;
}); }
else {
// If dataset has table then preload some data for the table component
this._datasetDetailService.sampleDataLoaded$.subscribe((data) => {
this.dataLoaded = true;
}).unsubscribe();
}
} }
} }
......
...@@ -100,9 +100,7 @@ export class DatasetTableComponent implements OnInit, OnDestroy { ...@@ -100,9 +100,7 @@ export class DatasetTableComponent implements OnInit, OnDestroy {
// Set the new sort value in the service // Set the new sort value in the service
this._datasetDetailService.sortBy(keyType); this._datasetDetailService.sortBy(keyType);
// Retrieve date sorted with the new value // Retrieve date sorted with the new value
this._datasetDetailService.retrieveDatasetData().subscribe(() => { this.getSearchResults();
this.tableWidthModified.emit(true);
});
} }
getSearchResults() { getSearchResults() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment