From 1c432eb75314f1767d848acdf14f4bc5c8f02e95 Mon Sep 17 00:00:00 2001 From: Ronan Date: Thu, 4 Jul 2024 10:57:33 +0200 Subject: [PATCH 1/2] =?UTF-8?q?feat(formapi):=20Ajout=20d'un=20syst=C3=A8m?= =?UTF-8?q?e=20de=20page=20dans=20le=20formulaire=20#29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/ign-api-dl/ign-api-dl.component.html | 14 ++++++++++---- .../src/lib/ign-api-dl/ign-api-dl.component.ts | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html index 9828be4a75..9604718a27 100644 --- a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html +++ b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html @@ -93,12 +93,18 @@ + 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 c6e6ebbc83..f560ef55c4 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 @@ -189,6 +189,13 @@ export class IgnApiDlComponent implements OnInit { this.size$.next(String(size)) this.page$.next(String(page)) } + + lessResult(): void { + const page = Number(this.page$.value) - 1 + const size = (page + 1) * Number(this.initialPageSize) + this.size$.next(String(size)) + this.page$.next(String(page)) + } resetPage(): void { this.page$.next('0') } From 97b3707659c77bdde666f082abead5f37cc925ee Mon Sep 17 00:00:00 2001 From: Ronan Date: Thu, 22 Aug 2024 14:55:36 +0200 Subject: [PATCH 2/2] =?UTF-8?q?feat(formapi):=20Am=C3=A9lioration=20du=20s?= =?UTF-8?q?yst=C3=A8me=20de=20pagination=20#29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/ign-api-dl/ign-api-dl.component.html | 65 +++++++++---------- .../lib/ign-api-dl/ign-api-dl.component.ts | 36 ++++------ 2 files changed, 43 insertions(+), 58 deletions(-) diff --git a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html index e929b29119..3dc41b5f21 100644 --- a/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html +++ b/libs/feature/record/src/lib/ign-api-dl/ign-api-dl.component.html @@ -57,27 +57,6 @@
- - -
-
- Produits ({{ size$.value }}/{{ - numberFilteredProduct$ | async - }}): -
-
- Produits ({{ numberFilteredProduct$ | async }}/{{ - numberFilteredProduct$ | async - }}): -
-
- -
@@ -91,21 +70,35 @@
- - - + +
+ +
+
+
+
+ {{ page$.value }}/{{ pageMax$ | async }} +
+
+
+ +
+
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 80f6ccadbe..a741abd5ec 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 @@ -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' @@ -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 @@ -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) } @@ -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)) + ) ) }) ) @@ -183,24 +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 { - const page = Number(this.page$.value) - 1 - const size = (page + 1) * Number(this.initialPageSize) - this.size$.next(String(size)) - this.page$.next(String(page)) + this.page$.next(this.page$.value - 1) } + resetPage(): void { - this.page$.next('0') + this.page$.next(1) } async getCapabilities() {