Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refacto(api): fix and refacto #51

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 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 @@ -14,6 +14,7 @@ import {
iif,
map,
mergeMap,
startWith,
switchMap,
tap,
} from 'rxjs'
Expand Down Expand Up @@ -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([
Expand All @@ -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 = {
Expand All @@ -125,22 +128,29 @@ 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([])
)
})
)
numberFilteredProduct$ = this.apiQueryUrl$.pipe(
mergeMap((url) => {
return this.getFilteredProduct$(url).pipe(
map((response) => response['totalentries'])
// startWith(0)
)
})
)
Expand Down Expand Up @@ -193,58 +203,52 @@ 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
}
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
}
Expand Down
Loading