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 {
this.initInseeLabel(this._datasetDetailService.datasetData);
}
else {
this._datasetDetailService.retrieveDatasetData().subscribe(() => {
this._datasetDetailService.sampleDataLoaded$.subscribe((data) => {
this.initInseeLabel(this._datasetDetailService.datasetData);
});
}
......
......@@ -60,6 +60,8 @@ export class DatasetDetailComponent implements OnInit, OnDestroy {
this.isLoading = true;
this.initDatasetInfo();
});
this._datasetDetailService.retrieveDatasetData().subscribe();
}
ngOnDestroy() {
......
......@@ -114,17 +114,27 @@ export class ResourceDownloadItemComponent implements OnInit {
this.selectedProjection = this.projectionList[0];
}
// Set the insee property label for this dataset
if (this._datasetDetailService.datasetData[0]) {
const properties = Object.keys(this._datasetDetailService.datasetData[0].properties);
this.inseeLabel = properties.find((prop) => { return prop.includes('insee'); });
this.setInseeProperties();
} else {
this._datasetDetailService.sampleDataLoaded$.subscribe((data) => {
this.setInseeProperties();
});
}
this.communeInseeList.sort((a, b) => (a.commune.localeCompare(b.commune)));
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() {
return this.format ? this.format.name : this.link.formats[0];
......@@ -199,6 +209,7 @@ export class ResourceDownloadItemComponent implements OnInit {
// Set the selected insee and set the queryable parameters
// depending on the resource
setInsee(insee) {
this.selectedInsee = insee;
if (!this.selectedInsee || !this.inseeLabel) {
this.queryableParameters.insee = '';
......
......@@ -63,10 +63,15 @@ export class DatasetTableMapComponent implements OnInit, OnDestroy {
this.searchInput.setValue(this._datasetDetailService.searchString);
if (this.hasTable) {
// If dataset has table then preload some data for the table component
this._datasetDetailService.retrieveDatasetData().subscribe(() => {
if (this._datasetDetailService.datasetData){
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 {
// Set the new sort value in the service
this._datasetDetailService.sortBy(keyType);
// Retrieve date sorted with the new value
this._datasetDetailService.retrieveDatasetData().subscribe(() => {
this.tableWidthModified.emit(true);
});
this.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