Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
6238495d
Unverified
Commit
6238495d
authored
Apr 14, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Apr 14, 2024
Browse files
Merge pull request #1395 from 7a6ac0/admin_pagination
feat: admin panel user list pagination
parents
1fa3bf67
0708a3d7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
9 deletions
+88
-9
src/lib/components/common/Pagination.svelte
src/lib/components/common/Pagination.svelte
+42
-0
src/lib/components/icons/ChevronLeft.svelte
src/lib/components/icons/ChevronLeft.svelte
+15
-0
src/lib/components/icons/ChevronRight.svelte
src/lib/components/icons/ChevronRight.svelte
+15
-0
src/routes/(app)/admin/+page.svelte
src/routes/(app)/admin/+page.svelte
+16
-9
No files found.
src/lib/components/common/Pagination.svelte
0 → 100644
View file @
6238495d
<script lang="ts">
import { Pagination } from 'bits-ui';
import { createEventDispatcher } from 'svelte';
import ChevronLeft from '../icons/ChevronLeft.svelte';
import ChevronRight from '../icons/ChevronRight.svelte';
export let page = 0;
export let count = 0;
export let perPage = 20;
</script>
<div class="flex justify-center">
<Pagination.Root bind:page {count} {perPage} let:pages>
<div class="my-2 flex items-center">
<Pagination.PrevButton
class="mr-[25px] inline-flex size-8 items-center justify-center rounded-[9px] bg-transparent hover:bg-gray-100 dark:hover:bg-gray-800 active:scale-98 disabled:cursor-not-allowed disabled:text-gray-400 dark:disabled:text-gray-700 hover:disabled:bg-transparent dark:hover:disabled:bg-transparent"
>
<ChevronLeft className="size-4" strokeWidth="2" />
</Pagination.PrevButton>
<div class="flex items-center gap-2.5">
{#each pages as page (page.key)}
{#if page.type === 'ellipsis'}
<div class="text-sm font-medium text-foreground-alt">...</div>
{:else}
<Pagination.Page
{page}
class="inline-flex size-8 items-center justify-center rounded-[9px] bg-transparent hover:bg-gray-100 dark:hover:bg-gray-800 text-sm font-medium hover:bg-dark-10 active:scale-98 disabled:cursor-not-allowed disabled:opacity-50 hover:disabled:bg-transparent data-[selected]:bg-black data-[selected]:text-gray-100 data-[selected]:hover:bg-black dark:data-[selected]:bg-white dark:data-[selected]:text-gray-900 dark:data-[selected]:hover:bg-white"
>
{page.value}
</Pagination.Page>
{/if}
{/each}
</div>
<Pagination.NextButton
class="ml-[25px] inline-flex size-8 items-center justify-center rounded-[9px] bg-transparent hover:bg-gray-100 dark:hover:bg-gray-800 active:scale-98 disabled:cursor-not-allowed disabled:text-gray-400 dark:disabled:text-gray-700 hover:disabled:bg-transparent dark:hover:disabled:bg-transparent"
>
<ChevronRight className="size-4" strokeWidth="2" />
</Pagination.NextButton>
</div>
</Pagination.Root>
</div>
src/lib/components/icons/ChevronLeft.svelte
0 → 100644
View file @
6238495d
<script lang="ts">
export let className = 'w-4 h-4';
export let strokeWidth = '1.5';
</script>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width={strokeWidth}
stroke="currentColor"
class={className}
>
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
</svg>
src/lib/components/icons/ChevronRight.svelte
0 → 100644
View file @
6238495d
<script lang="ts">
export let className = 'w-4 h-4';
export let strokeWidth = '1.5';
</script>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width={strokeWidth}
stroke="currentColor"
class={className}
>
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
</svg>
src/routes/(app)/admin/+page.svelte
View file @
6238495d
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths';
import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths';
import EditUserModal from '$lib/components/admin/EditUserModal.svelte';
import EditUserModal from '$lib/components/admin/EditUserModal.svelte';
import SettingsModal from '$lib/components/admin/SettingsModal.svelte';
import SettingsModal from '$lib/components/admin/SettingsModal.svelte';
import Pagination from '$lib/components/common/Pagination.svelte';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
...
@@ -21,6 +22,8 @@
...
@@ -21,6 +22,8 @@
let search = '';
let search = '';
let selectedUser = null;
let selectedUser = null;
let page = 1;
let showSettingsModal = false;
let showSettingsModal = false;
let showEditUserModal = false;
let showEditUserModal = false;
...
@@ -159,15 +162,17 @@
...
@@ -159,15 +162,17 @@
</tr>
</tr>
</thead>
</thead>
<tbody>
<tbody>
{#each users.filter((user) => {
{#each users
if (search === '') {
.filter((user) => {
return true;
if (search === '') {
} else {
return true;
let name = user.name.toLowerCase();
} else {
const query = search.toLowerCase();
let name = user.name.toLowerCase();
return name.includes(query);
const query = search.toLowerCase();
}
return name.includes(query);
}) as user}
}
})
.slice((page - 1) * 20, page * 20) as user}
<tr class="bg-white border-b dark:bg-gray-900 dark:border-gray-700 text-xs">
<tr class="bg-white border-b dark:bg-gray-900 dark:border-gray-700 text-xs">
<td class="px-3 py-2 min-w-[7rem] w-28">
<td class="px-3 py-2 min-w-[7rem] w-28">
<button
<button
...
@@ -270,6 +275,8 @@
...
@@ -270,6 +275,8 @@
<div class=" text-gray-500 text-xs mt-2 text-right">
<div class=" text-gray-500 text-xs mt-2 text-right">
ⓘ {$i18n.t("Click on the user role button to change a user's role.")}
ⓘ {$i18n.t("Click on the user role button to change a user's role.")}
</div>
</div>
<Pagination bind:page count={users.length} />
</div>
</div>
</div>
</div>
</div>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment