Skip to content

Commit

Permalink
fix(ignApi): fix param api limit and page
Browse files Browse the repository at this point in the history
  • Loading branch information
mmohadIGN committed Jul 12, 2024
1 parent 79ac3f3 commit 6f27406
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@ import {
OnInit,
} from '@angular/core'
import { DatasetServiceDistribution } from '@geonetwork-ui/common/domain/model/record'
import {
BehaviorSubject,
Observable,
combineLatest,
filter,
first,
iif,
map,
mergeMap,
startWith,
switchMap,
tap,
} from 'rxjs'
import { fromFetch } from 'rxjs/fetch'
import { BehaviorSubject, Observable, combineLatest, map, mergeMap } from 'rxjs'
import { HttpClient } from '@angular/common/http'
import { Choice, DropdownChoice } from '@geonetwork-ui/ui/inputs'
import { Choice } from '@geonetwork-ui/ui/inputs'
import axios from 'axios'

export interface Label {
Expand Down Expand Up @@ -68,15 +55,15 @@ export interface Field {
export class IgnApiDlComponent implements OnInit {
isOpen = false
collapsed = false
initialPageSize = '200'
initialLimit = '50'
apiBaseUrl: string
editionDate$ = new BehaviorSubject('')
zone$ = new BehaviorSubject('')
format$ = new BehaviorSubject('')
crs$ = new BehaviorSubject('')
pageSize$ = new BehaviorSubject(this.initialPageSize)
page$ = new BehaviorSubject('0')
size$ = new BehaviorSubject(this.initialPageSize)
limit$ = new BehaviorSubject(this.initialLimit)
page$ = new BehaviorSubject('1')
size$ = new BehaviorSubject(this.initialLimit)
// a passer en config
url =
'https://data.geopf.fr/telechargement/capabilities?outputFormat=application/json'
Expand All @@ -103,21 +90,19 @@ export class IgnApiDlComponent implements OnInit {
this.format$,
this.editionDate$,
this.crs$,
this.pageSize$,
this.limit$,
this.page$,
]).pipe(
map(([zone, format, editionDate, crs, pageSize, page]) => {
map(([zone, format, editionDate, crs, limit, 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 = {
zone: zone,
format: format,
editionDate: editionDate,
crs: crs,
pageSize: pageSize,
limit: limit,
page: page,
} // initialisation des paramètres de filtres
for (const [key, value] of Object.entries(params)) {
Expand Down Expand Up @@ -189,11 +174,11 @@ export class IgnApiDlComponent implements OnInit {
this.format$.next('null')
this.crs$.next('null')
this.page$.next('0')
this.size$.next(this.initialPageSize)
this.size$.next(this.initialLimit)
}
moreResult(): void {
const page = Number(this.page$.value) + 1
const size = (page + 1) * Number(this.initialPageSize)
const size = (page + 1) * Number(this.initialLimit)
this.size$.next(String(size))
this.page$.next(String(page))
}
Expand All @@ -208,7 +193,7 @@ export class IgnApiDlComponent implements OnInit {

while (choicesTest === undefined && pageCount > page) {
const response = await axios.get(
this.url.concat(`&pagesize=200&page=${page}`)
this.url.concat(`&limit=200&page=${page}`)
)

choicesTest = response.data.entry.filter(
Expand Down

0 comments on commit 6f27406

Please sign in to comment.