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

feat(formapi): Ajout d'un système de page dans le formulaire #29 #48

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
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
79 changes: 47 additions & 32 deletions libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,53 @@
</div>
</div>
<div class="bg-white rounded-lg h-min">
<div
*ngIf="numberFilteredProduct$ | async as numberFilteredProduct"
class="py-2 pr-2 text-xl border-b border-slate-200 dark:border-slate-400/20"
>
<div *ngIf="size$.value < numberFilteredProduct">
Produits ({{ size$.value }}/{{ numberFilteredProduct$ | async }}):
</div>
<div *ngIf="size$.value > numberFilteredProduct">
Produits ({{ numberFilteredProduct$ | async }}/{{
numberFilteredProduct$ | async
}}):
</div>
</div>
<div class="overflow-scroll bg-white-300 m-2" style="height: 380px">
<div *ngFor="let link of listFilteredProduct$ | async">
<div class="mb-2 sm:mb-3">
<gn-ui-ign-api-produit
[link]="link"
color="rgb(124 45 18)"
[format]="getLinkFormat(link)"
[isFromWfs]="true"
></gn-ui-ign-api-produit>
</div>
</div>

<button
*ngIf="size$.value < (numberFilteredProduct$ | async)"
(click)="moreResult()"
class="bg-primary-opacity-50 inline-flex items-center justify-center px-2 py-1 text-13 font-medium leading-none text-white rounded capitalize text-primary-lightest hover:bg-primary transition-colors"
>
<p class="text-[13px] uppercase" translate>results.showMore</p>
</button>
<div class="overflow-auto h-60 w-65 bg-white-300 m-2">
<table class="w-full text-left border-collapse">
<tbody class="align-baseline">
<tr>
<div *ngFor="let link of listFilteredProduct$ | async">
<div class="mb-2 sm:mb-3">
<gn-ui-ign-api-produit
[link]="link"
color="rgb(124 45 18)"
[format]="getLinkFormat(link)"
[isFromWfs]="true"
></gn-ui-ign-api-produit>
</div>
</div>
</tr>
<tr class="flex items-center justify-between">
<div class="w-1/3">
<button
*ngIf="page$.value > 1"
(click)="lessResult()"
class="bg-primary-opacity-50 inline-flex items-center justify-center px-2 py-1 text-13 font-medium leading-none text-white rounded capitalize text-primary-lightest hover:bg-primary transition-colors float-left"
>
<p class="text-[13px] uppercase" translate>Page précédente</p>
</button>
<div *ngIf="page$.value <= 1"></div>
</div>
<div class="w-1/3 flex items-center justify-center">
<div
*ngIf="(pageMax$ | async) !== 1"
class="sticky z-10 leading-6 font-semibold"
>
{{ page$.value }}/{{ pageMax$ | async }}
</div>
</div>
<div class="w-1/3">
<button
*ngIf="page$.value < (pageMax$ | async)"
(click)="moreResult()"
class="bg-primary-opacity-50 inline-flex items-center justify-center px-2 py-1 text-13 font-medium leading-none text-white rounded capitalize text-primary-lightest hover:bg-primary transition-colors float-right"
>
<p class="text-[13px] uppercase" translate>Page suivante</p>
</button>
<div *ngIf="page$.value >= (pageMax$ | async)"></div>
</div>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Expand Down
35 changes: 17 additions & 18 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 @@ -55,15 +55,13 @@ export interface Field {
export class IgnApiDlComponent implements OnInit {
isOpen = false
collapsed = false
initialLimit = '50'
initialLimit = 50
apiBaseUrl: string
editionDate$ = new BehaviorSubject('')
zone$ = new BehaviorSubject('')
format$ = new BehaviorSubject('')
crs$ = new BehaviorSubject('')
limit$ = new BehaviorSubject(this.initialLimit)
page$ = new BehaviorSubject('1')
size$ = new BehaviorSubject(this.initialLimit)
page$ = new BehaviorSubject(1)
// a passer en config
url =
'https://data.geopf.fr/telechargement/capabilities?outputFormat=application/json'
Expand All @@ -90,10 +88,9 @@ export class IgnApiDlComponent implements OnInit {
this.format$,
this.editionDate$,
this.crs$,
this.limit$,
this.page$,
]).pipe(
map(([zone, format, editionDate, crs, limit, page]) => {
map(([zone, format, editionDate, crs, page]) => {
let outputUrl
if (this.apiBaseUrl) {
const url = new URL(this.apiBaseUrl) // initialisation de l'url avec l'url de base
Expand All @@ -102,12 +99,11 @@ export class IgnApiDlComponent implements OnInit {
format: format,
editionDate: editionDate,
crs: crs,
limit: limit,
page: page,
} // initialisation des paramètres de filtres
for (const [key, value] of Object.entries(params)) {
if (value && value !== 'null') {
url.searchParams.set(key, value)
url.searchParams.set(key, String(value))
} else {
url.searchParams.delete(key)
}
Expand All @@ -131,11 +127,13 @@ export class IgnApiDlComponent implements OnInit {
)
})
)
numberFilteredProduct$ = this.apiQueryUrl$.pipe(

pageMax$ = this.apiQueryUrl$.pipe(
mergeMap((url) => {
return this.getFilteredProduct$(url).pipe(
map((response) => response['totalentries'])
// startWith(0)
map((response) =>
Math.ceil(response['totalentries'] / Number(this.initialLimit))
)
)
})
)
Expand Down Expand Up @@ -183,17 +181,18 @@ export class IgnApiDlComponent implements OnInit {
this.zone$.next('null')
this.format$.next('null')
this.crs$.next('null')
this.page$.next('0')
this.size$.next(this.initialLimit)
this.page$.next(1)
}
moreResult(): void {
const page = Number(this.page$.value) + 1
const size = (page + 1) * Number(this.initialLimit)
this.size$.next(String(size))
this.page$.next(String(page))
this.page$.next(this.page$.value + 1)
}

lessResult(): void {
this.page$.next(this.page$.value - 1)
}

resetPage(): void {
this.page$.next('0')
this.page$.next(1)
}

async getCapabilities() {
Expand Down
Loading