From 478bb7e23a6087a40fbfc596442535b86ababc6c Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 20 May 2022 11:04:42 +0200 Subject: [PATCH 1/9] feat: initialized new pagination component (WIP) --- src/lib/components/pagination.svelte | 130 ++++++++++++------ .../console/[project]/users/index.svelte | 4 +- 2 files changed, 89 insertions(+), 45 deletions(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index 921d6f2418..f5ba08911d 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -1,54 +1,98 @@ -{#if sum >= limit} - -{/if} + Next + + + diff --git a/src/routes/console/[project]/users/index.svelte b/src/routes/console/[project]/users/index.svelte index f1d113d382..c5fd4b87a4 100644 --- a/src/routes/console/[project]/users/index.svelte +++ b/src/routes/console/[project]/users/index.svelte @@ -24,7 +24,7 @@ let search = ''; let showCreate = false; let offset = 0; - const limit = 25; + const limit = 1; const project = $page.params.project; const getAvatar = (name: string) => sdkForProject.avatars.getInitials(name, 30, 30).toString(); @@ -81,7 +81,7 @@ {/each} - + {:else if search} Date: Fri, 20 May 2022 12:41:26 +0200 Subject: [PATCH 2/9] fix: fixed pagination problem --- src/lib/components/pagination.svelte | 10 ++++++---- src/routes/console/[project]/users/index.svelte | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index f5ba08911d..da3cd06df6 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -6,11 +6,13 @@ export let offset: number; const totalPages = Math.ceil(totalItems / pageSize); - let currentPage = offset / pageSize + 1; + let currentPage = Math.floor(offset / pageSize + 1); + console.log(currentPage); function handleOptionClick(page) { if (currentPage !== page) { - offset = pageSize * page - 1; + offset = pageSize * (page - 1); + console.log(offset); currentPage = page; dispatch('change'); } @@ -18,11 +20,11 @@ function handleButtonPage(direction) { if (direction === 'next' && currentPage < totalPages) { currentPage += 1; - offset = pageSize * currentPage - 1; + offset = pageSize * (currentPage - 1); dispatch('change'); } else if (direction === 'prev' && currentPage > 1) { currentPage -= 1; - offset = pageSize * currentPage - 1; + offset = pageSize * (currentPage - 1); dispatch('change'); } } diff --git a/src/routes/console/[project]/users/index.svelte b/src/routes/console/[project]/users/index.svelte index c5fd4b87a4..0ffce9c58a 100644 --- a/src/routes/console/[project]/users/index.svelte +++ b/src/routes/console/[project]/users/index.svelte @@ -24,7 +24,7 @@ let search = ''; let showCreate = false; let offset = 0; - const limit = 1; + const limit = 5; const project = $page.params.project; const getAvatar = (name: string) => sdkForProject.avatars.getInitials(name, 30, 30).toString(); From 4c2be3ca4a2cd428a70cb6dd0e25a0f187601437 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 20 May 2022 13:30:26 +0200 Subject: [PATCH 3/9] fix: pagination small css, html & type fixes --- src/lib/components/pagination.svelte | 44 +++++++++++++--------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index da3cd06df6..5c42fe9e32 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -7,17 +7,15 @@ const totalPages = Math.ceil(totalItems / pageSize); let currentPage = Math.floor(offset / pageSize + 1); - console.log(currentPage); - function handleOptionClick(page) { + function handleOptionClick(page: number) { if (currentPage !== page) { offset = pageSize * (page - 1); - console.log(offset); currentPage = page; dispatch('change'); } } - function handleButtonPage(direction) { + function handleButtonPage(direction: string) { if (direction === 'next' && currentPage < totalPages) { currentPage += 1; offset = pageSize * (currentPage - 1); @@ -31,7 +29,7 @@ let pages = pagination(currentPage, totalPages); - function pagination(current, total) { + function pagination(current: number, total: number) { let delta = 2, left = current - delta, right = current + delta + 1, @@ -56,28 +54,28 @@ rangeWithDots.push(i); l = i; } - return rangeWithDots; } From 3edfa31fe14ab8c6333da3d40b6be4815c6f9b4c Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 20 May 2022 14:57:06 +0200 Subject: [PATCH 4/9] Update src/lib/components/pagination.svelte Co-authored-by: Torsten Dittmann --- src/lib/components/pagination.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index 5c42fe9e32..1432830aab 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -81,7 +81,7 @@ {:else} -
  • +
  • ...
  • {/if} From 6fe4a1623d00c46613fb114db610ad6a22e8e736 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 20 May 2022 15:02:13 +0200 Subject: [PATCH 5/9] fix: restored old variables names to avoid errors --- src/lib/components/pagination.svelte | 95 ++++++++++--------- .../console/[project]/users/index.svelte | 2 +- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index 1432830aab..f1b1d319be 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -1,28 +1,29 @@ - +{#if totalPages > 1} + +{/if} diff --git a/src/routes/console/[project]/users/index.svelte b/src/routes/console/[project]/users/index.svelte index 0ee3cd2048..1c23e43a3f 100644 --- a/src/routes/console/[project]/users/index.svelte +++ b/src/routes/console/[project]/users/index.svelte @@ -90,7 +90,7 @@

    Total results: {response.total}

    - +
    {:else if search} From 9c68e72cbf7084372307791ba78c45ce1150c356 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 20 May 2022 15:28:19 +0200 Subject: [PATCH 6/9] fix: refactored pagination function --- src/lib/components/pagination.svelte | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index f1b1d319be..8079e22cb0 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -35,8 +35,7 @@ left = current - delta, right = current + delta + 1, range = [], - rangeWithDots = [], - l; + rangeWithDots = []; for (let i = 1; i <= total; i++) { if (i == 1 || i == total || (i >= left && i < right)) { @@ -44,17 +43,13 @@ } } - for (let i of range) { - if (l) { - if (i - l === 2) { - rangeWithDots.push(l + 1); - } else if (i - l !== 1) { - rangeWithDots.push('...'); - } + rangeWithDots = range.reduce((prev, current, index) => { + if (current - prev[index - 1] > delta) { + prev.push('...'); } - rangeWithDots.push(i); - l = i; - } + prev.push(current); + return prev; + }, []); return rangeWithDots; } From 1685b9a5fd3cfefbabe5dfa1d42084f69ad3eb23 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 20 May 2022 15:49:19 +0200 Subject: [PATCH 7/9] Update src/lib/components/pagination.svelte Co-authored-by: Torsten Dittmann --- src/lib/components/pagination.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/pagination.svelte b/src/lib/components/pagination.svelte index 8079e22cb0..e685167c34 100644 --- a/src/lib/components/pagination.svelte +++ b/src/lib/components/pagination.svelte @@ -59,7 +59,7 @@ handleButtonPage('prev')} class:is-disabled={currentPage <= 1} - class="button is-text " + class="button is-text" aria-label="prev page">