Skip to content

Commit

Permalink
feat(filterIgnForm): complet filter bas on record observe #6
Browse files Browse the repository at this point in the history
  • Loading branch information
mmohadIGN committed May 27, 2024
1 parent dba54af commit 5f506bd
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 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 @@ -2,9 +2,7 @@ import {
ChangeDetectionStrategy,
Component,
Input,
OnChanges,
OnInit,
SimpleChanges,
} from '@angular/core'
import { DatasetServiceDistribution } from '@geonetwork-ui/common/domain/model/record'
import {
Expand Down Expand Up @@ -62,9 +60,9 @@ export interface Field {
styleUrls: ['./ign-api-dl.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class IgnApiDlComponent {
export class IgnApiDlComponent implements OnInit {
@Input() set apiLink(value: DatasetServiceDistribution) {
this.apiBaseUrl = value.url.href
this.apiBaseUrl = value ? value.url.href : undefined
console.log(this.apiBaseUrl)
this.resetUrl()
}
Expand All @@ -74,19 +72,27 @@ export class IgnApiDlComponent {
format$ = new BehaviorSubject('')
spatialDatasetIdentifierCode$ = new BehaviorSubject('')

choicesFormat$: Observable<Choice[]> = this.getFields('format')
choicesZone$: Observable<Choice[]> = this.getFields('zone')
choicesEditionDate$: Observable<Choice[]> = this.getFields('editionDate')
choicesSpatialDatasetIdentifierCode$: Observable<Choice[]> = this.getFields(
'spatialDatasetIdentifierCode'
)
choicesFormat$: Observable<Choice[]>
choicesZone$: Observable<Choice[]>
choicesEditionDate$: Observable<Choice[]>
choicesSpatialDatasetIdentifierCode$: Observable<Choice[]>
// listProduit$: Observable<any>
// subProducts$: Observable <Array<string>>

constructor(protected http: HttpClient) {}

isOpen = false
apiBaseUrl: string

ngOnInit(): void {
this.choicesZone$ = this.getFields('zone')
this.choicesFormat$ = this.getFields('format')
this.choicesEditionDate$ = this.getFields('editionDate')
this.choicesSpatialDatasetIdentifierCode$ = this.getFields(
'spatialDatasetIdentifierCode'
)
}

apiQueryUrl$ = combineLatest([
this.zone$,
this.format$,
Expand All @@ -112,7 +118,9 @@ export class IgnApiDlComponent {
url.searchParams.delete(key)
}
}
return url.toString()
let outputUrl = url.toString()
console.log(outputUrl)
return outputUrl
})
)

Expand Down Expand Up @@ -150,42 +158,37 @@ export class IgnApiDlComponent {
this.format$.next(this.choicesFormat$[0])
}

url = 'https://data.geopf.fr/telechargement/capabilities'

getFields(param: string): Observable<FieldAvailableValue[]> {
return this.http
.get('https://data.geopf.fr/telechargement/capabilities')
.pipe(
map(
(response) =>
(response as Field).entry.filter((element) => {
element['id'] == this.apiBaseUrl
})[0]
),
tap((el) => console.log(el)),
switchMap((buckets: FormatProduit) => {
console.log('hellol')

if (
param != 'editionDate' &&
param != 'spatialDatasetIdentifierCode'
) {
console.log('hello bucket', typeof buckets[param])
const bucketPromises = buckets[param].map((bucket) => ({
value: bucket.label,
label: bucket.term || param,
}))
return Promise.all(bucketPromises)
} else {
console.log(typeof buckets[param])
const bucketPromises = [
{
value: buckets[param] || '',
label: buckets[param] || param,
},
]
console.log(bucketPromises)
return Promise.all(bucketPromises)
}
})
)
return this.http.get(this.url).pipe(
map(
(response) =>
(response as Field).entry.filter(
(element) => element['id'] == this.apiBaseUrl
)[0]
),
tap((el) => console.log(el)),
switchMap((buckets: FormatProduit) => {
if (param != 'editionDate' && param != 'spatialDatasetIdentifierCode') {
console.log(typeof buckets[param])
const bucketPromises = buckets[param].map((bucket) => ({
value: bucket.label,
label: bucket.term || param,
}))
return Promise.all(bucketPromises)
} else {
console.log(typeof buckets[param])
const bucketPromises = [
{
value: buckets[param] || '',
label: buckets[param] || param,
},
]
console.log(bucketPromises)
return Promise.all(bucketPromises)
}
})
)
}
}

0 comments on commit 5f506bd

Please sign in to comment.