diff --git a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts index ec0060591b..a817a1ed35 100644 --- a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts +++ b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts @@ -14,6 +14,7 @@ import { iif, map, mergeMap, + startWith, switchMap, tap, } from 'rxjs' @@ -91,10 +92,10 @@ export class IgnApiDlComponent implements OnInit { } ngOnInit(): void { - this.getFields() this.bucketPromisesZone = [{ value: '', label: 'ZONE' }] this.bucketPromisesFormat = [{ value: '', label: 'FORMAT' }] this.bucketPromisesCrs = [{ value: '', label: 'CRS' }] + this.getFields() } apiQueryUrl$ = combineLatest([ @@ -107,6 +108,8 @@ export class IgnApiDlComponent implements OnInit { ]).pipe( map(([zone, format, editionDate, crs, pageSize, page]) => { let outputUrl + console.log(zone, format, editionDate, crs, pageSize, page) + if (this.apiBaseUrl) { const url = new URL(this.apiBaseUrl) // initialisation de l'url avec l'url de base const params = { @@ -125,15 +128,21 @@ export class IgnApiDlComponent implements OnInit { } } outputUrl = url.toString() + } else { + console.error('erreur apibaseUrl null') } return outputUrl }) + // startWith(() => this.apiBaseUrl) ) listFilteredProduct$ = this.apiQueryUrl$.pipe( mergeMap((url) => { + console.log(url) + return this.getFilteredProduct$(url).pipe( map((response) => response['entry']) + // startWith([]) ) }) ) @@ -141,6 +150,7 @@ export class IgnApiDlComponent implements OnInit { mergeMap((url) => { return this.getFilteredProduct$(url).pipe( map((response) => response['totalentries']) + // startWith(0) ) }) ) @@ -193,31 +203,19 @@ export class IgnApiDlComponent implements OnInit { async getCapabilities() { let page = 0 - let choicesTest = null - let [response] = await Promise.all([ - axios.get(this.url.concat(`&pageSize=200&page=${page}`)), - ]) - choicesTest = response.data.entry.filter( - (element) => element['id'] == this.apiBaseUrl - )[0] - - if (choicesTest) { - return choicesTest - } else { - console.log(page) - - while (choicesTest === undefined || response.data.pageCount > page) { - console.log(choicesTest) - ;[response] = await Promise.all([ - axios.get(this.url.concat(`&pageSize=200&page=${page}`)), - ]) - console.log(response.data.entry) - - choicesTest = response.data.entry.filter( - (element) => element['id'] == this.apiBaseUrl - )[0] - page += 1 - } + let choicesTest = undefined + let pageCount = 1 + + while (choicesTest === undefined && pageCount > page) { + const response = await axios.get( + this.url.concat(`&pagesize=200&page=${page}`) + ) + + choicesTest = response.data.entry.filter( + (element) => element['id'] == this.apiBaseUrl + )[0] + page += 1 + pageCount = response.data.pagecount } return choicesTest @@ -225,26 +223,32 @@ export class IgnApiDlComponent implements OnInit { async getFields() { this.choices = await this.getCapabilities() - this.bucketPromisesZone = this.choices.zone.map((bucket) => ({ + const tempZone = this.choices.zone.map((bucket) => ({ value: bucket.label, label: bucket.term, })) - this.bucketPromisesZone.sort((a, b) => (a.label > b.label ? 1 : -1)) - this.bucketPromisesZone.unshift({ value: 'null', label: 'ZONE' }) + tempZone.sort((a, b) => (a.label > b.label ? 1 : -1)) + tempZone.unshift({ value: 'null', label: 'ZONE' }) + + this.bucketPromisesZone = tempZone - this.bucketPromisesFormat = this.choices.format.map((bucket) => ({ + const tempFormat = this.choices.format.map((bucket) => ({ value: bucket.label, label: bucket.term, })) - this.bucketPromisesFormat.sort((a, b) => (a.label > b.label ? 1 : -1)) - this.bucketPromisesFormat.unshift({ value: 'null', label: 'FORMAT' }) + tempFormat.sort((a, b) => (a.label > b.label ? 1 : -1)) + tempFormat.unshift({ value: 'null', label: 'FORMAT' }) - this.bucketPromisesCrs = this.choices.category.map((bucket) => ({ + this.bucketPromisesFormat = tempFormat + + const tempCrs = this.choices.category.map((bucket) => ({ value: bucket.label, - label: bucket.term, + label: bucket.label, })) - this.bucketPromisesCrs.sort((a, b) => (a.label > b.label ? 1 : -1)) - this.bucketPromisesCrs.unshift({ value: 'null', label: 'CRS' }) + tempCrs.sort((a, b) => (a.label > b.label ? 1 : -1)) + tempCrs.unshift({ value: 'null', label: 'CRS' }) + + this.bucketPromisesCrs = tempCrs // eslint-disable-next-line @typescript-eslint/no-non-null-assertion }