mirror of
https://github.com/open-webui/open-webui
synced 2025-05-18 12:21:36 +00:00
refac: admin panel
This commit is contained in:
parent
d9de426fcd
commit
bf8c32f09f
@ -1,13 +1,24 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import fileSaver from 'file-saver';
|
||||||
|
const { saveAs } = fileSaver;
|
||||||
|
|
||||||
import { downloadDatabase } from '$lib/apis/utils';
|
import { downloadDatabase } from '$lib/apis/utils';
|
||||||
import { onMount, getContext } from 'svelte';
|
import { onMount, getContext } from 'svelte';
|
||||||
import { config } from '$lib/stores';
|
import { config, user } from '$lib/stores';
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
|
import { getAllUserChats } from '$lib/apis/chats';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
export let saveHandler: Function;
|
export let saveHandler: Function;
|
||||||
|
|
||||||
|
const exportAllUserChats = async () => {
|
||||||
|
let blob = new Blob([JSON.stringify(await getAllUserChats(localStorage.token))], {
|
||||||
|
type: 'application/json'
|
||||||
|
});
|
||||||
|
saveAs(blob, `all-chats-export-${Date.now()}.json`);
|
||||||
|
};
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
// permissions = await getUserPermissions(localStorage.token);
|
// permissions = await getUserPermissions(localStorage.token);
|
||||||
});
|
});
|
||||||
@ -23,10 +34,10 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class=" mb-2 text-sm font-medium">{$i18n.t('Database')}</div>
|
<div class=" mb-2 text-sm font-medium">{$i18n.t('Database')}</div>
|
||||||
|
|
||||||
|
{#if $config?.admin_export_enabled ?? true}
|
||||||
<div class=" flex w-full justify-between">
|
<div class=" flex w-full justify-between">
|
||||||
<!-- <div class=" self-center text-xs font-medium">{$i18n.t('Allow Chat Deletion')}</div> -->
|
<!-- <div class=" self-center text-xs font-medium">{$i18n.t('Allow Chat Deletion')}</div> -->
|
||||||
|
|
||||||
{#if $config?.admin_export_enabled ?? true}
|
|
||||||
<button
|
<button
|
||||||
class=" flex rounded-md py-1.5 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
class=" flex rounded-md py-1.5 px-3 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
||||||
type="button"
|
type="button"
|
||||||
@ -55,8 +66,36 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class=" self-center text-sm font-medium">{$i18n.t('Download Database')}</div>
|
<div class=" self-center text-sm font-medium">{$i18n.t('Download Database')}</div>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr class=" dark:border-gray-700 my-1" />
|
||||||
|
|
||||||
|
<button
|
||||||
|
class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
||||||
|
on:click={() => {
|
||||||
|
exportAllUserChats();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div class=" self-center mr-3">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
fill="currentColor"
|
||||||
|
class="w-4 h-4"
|
||||||
|
>
|
||||||
|
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM8.75 7.75a.75.75 0 0 0-1.5 0v2.69L6.03 9.22a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l2.5-2.5a.75.75 0 1 0-1.06-1.06l-1.22 1.22V7.75Z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class=" self-center text-sm font-medium">
|
||||||
|
{$i18n.t('Export All Chats (All Users)')}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -68,13 +68,6 @@
|
|||||||
saveAs(blob, `chat-export-${Date.now()}.json`);
|
saveAs(blob, `chat-export-${Date.now()}.json`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const exportAllUserChats = async () => {
|
|
||||||
let blob = new Blob([JSON.stringify(await getAllUserChats(localStorage.token))], {
|
|
||||||
type: 'application/json'
|
|
||||||
});
|
|
||||||
saveAs(blob, `all-chats-export-${Date.now()}.json`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteAllChatsHandler = async () => {
|
const deleteAllChatsHandler = async () => {
|
||||||
await goto('/');
|
await goto('/');
|
||||||
await deleteAllChats(localStorage.token).catch((error) => {
|
await deleteAllChats(localStorage.token).catch((error) => {
|
||||||
@ -300,35 +293,5 @@
|
|||||||
<div class=" self-center text-sm font-medium">{$i18n.t('Delete All Chats')}</div>
|
<div class=" self-center text-sm font-medium">{$i18n.t('Delete All Chats')}</div>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $user?.role === 'admin' && ($config?.admin_export_enabled ?? true)}
|
|
||||||
<hr class=" dark:border-gray-700" />
|
|
||||||
|
|
||||||
<button
|
|
||||||
class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
|
|
||||||
on:click={() => {
|
|
||||||
exportAllUserChats();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div class=" self-center mr-3">
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
fill="currentColor"
|
|
||||||
class="w-4 h-4"
|
|
||||||
>
|
|
||||||
<path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z" />
|
|
||||||
<path
|
|
||||||
fill-rule="evenodd"
|
|
||||||
d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM8.75 7.75a.75.75 0 0 0-1.5 0v2.69L6.03 9.22a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l2.5-2.5a.75.75 0 1 0-1.06-1.06l-1.22 1.22V7.75Z"
|
|
||||||
clip-rule="evenodd"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div class=" self-center text-sm font-medium">
|
|
||||||
{$i18n.t('Export All Chats (All Users)')}
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
78
src/routes/(app)/admin/+layout.svelte
Normal file
78
src/routes/(app)/admin/+layout.svelte
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount, getContext } from 'svelte';
|
||||||
|
|
||||||
|
import { WEBUI_NAME, showSidebar } from '$lib/stores';
|
||||||
|
import MenuLines from '$lib/components/icons/MenuLines.svelte';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
|
||||||
|
const i18n = getContext('i18n');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>
|
||||||
|
{$i18n.t('Admin Panel')} | {$WEBUI_NAME}
|
||||||
|
</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<div class=" flex flex-col w-full min-h-screen max-h-screen">
|
||||||
|
<div class=" px-4 pt-3 mt-0.5 mb-1">
|
||||||
|
<div class=" flex items-center gap-1">
|
||||||
|
<div class="{$showSidebar ? 'md:hidden' : ''} mr-1 self-start flex flex-none items-center">
|
||||||
|
<button
|
||||||
|
id="sidebar-toggle-button"
|
||||||
|
class="cursor-pointer p-1 flex rounded-xl hover:bg-gray-100 dark:hover:bg-gray-850 transition"
|
||||||
|
on:click={() => {
|
||||||
|
showSidebar.set(!$showSidebar);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div class=" m-auto self-center">
|
||||||
|
<MenuLines />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center text-xl font-semibold">{$i18n.t('Workspace')}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- <div class="px-4 my-1">
|
||||||
|
<div
|
||||||
|
class="flex scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium rounded-xl bg-transparent/10 p-1"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes('/workspace/models')
|
||||||
|
? 'bg-gray-50 dark:bg-gray-850'
|
||||||
|
: ''} transition"
|
||||||
|
href="/workspace/models">{$i18n.t('Models')}</a
|
||||||
|
>
|
||||||
|
|
||||||
|
<a
|
||||||
|
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes('/workspace/prompts')
|
||||||
|
? 'bg-gray-50 dark:bg-gray-850'
|
||||||
|
: ''} transition"
|
||||||
|
href="/workspace/prompts">{$i18n.t('Prompts')}</a
|
||||||
|
>
|
||||||
|
|
||||||
|
<a
|
||||||
|
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes('/workspace/documents')
|
||||||
|
? 'bg-gray-50 dark:bg-gray-850'
|
||||||
|
: ''} transition"
|
||||||
|
href="/workspace/documents"
|
||||||
|
>
|
||||||
|
{$i18n.t('Documents')}
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a
|
||||||
|
class="min-w-fit rounded-lg p-1.5 px-3 {$page.url.pathname.includes('/workspace/playground')
|
||||||
|
? 'bg-gray-50 dark:bg-gray-850'
|
||||||
|
: ''} transition"
|
||||||
|
href="/workspace/playground">{$i18n.t('Playground')}</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div> -->
|
||||||
|
|
||||||
|
<hr class=" my-2 dark:border-gray-850" />
|
||||||
|
|
||||||
|
<div class=" py-1 px-5 flex-1 max-h-full overflow-y-auto">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -82,10 +82,6 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>{$i18n.t('Admin Panel')} | {$WEBUI_NAME}</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
{#key selectedUser}
|
{#key selectedUser}
|
||||||
<EditUserModal
|
<EditUserModal
|
||||||
bind:show={showEditUserModal}
|
bind:show={showEditUserModal}
|
||||||
@ -106,46 +102,7 @@
|
|||||||
<UserChatsModal bind:show={showUserChatsModal} user={selectedUser} />
|
<UserChatsModal bind:show={showUserChatsModal} user={selectedUser} />
|
||||||
<SettingsModal bind:show={showSettingsModal} />
|
<SettingsModal bind:show={showSettingsModal} />
|
||||||
|
|
||||||
<div class=" flex flex-col w-full min-h-screen">
|
{#if loaded}
|
||||||
{#if loaded}
|
|
||||||
<div class="px-4 pt-3 mt-0.5 mb-1">
|
|
||||||
<div class=" flex items-center gap-1">
|
|
||||||
<div class="{$showSidebar ? 'md:hidden' : ''} mr-1 self-start flex flex-none items-center">
|
|
||||||
<button
|
|
||||||
id="sidebar-toggle-button"
|
|
||||||
class="cursor-pointer p-1 flex rounded-xl hover:bg-gray-100 dark:hover:bg-gray-850 transition"
|
|
||||||
on:click={() => {
|
|
||||||
showSidebar.set(!$showSidebar);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div class=" m-auto self-center">
|
|
||||||
<MenuLines />
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center text-xl font-semibold">{$i18n.t('Dashboard')}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- <div class="px-4 my-1">
|
|
||||||
<div
|
|
||||||
class="flex scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium rounded-xl bg-transparent/10 p-1"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
class="min-w-fit rounded-lg p-1.5 px-3 {tab === ''
|
|
||||||
? 'bg-gray-50 dark:bg-gray-850'
|
|
||||||
: ''} transition"
|
|
||||||
type="button"
|
|
||||||
on:click={() => {
|
|
||||||
tab = '';
|
|
||||||
}}>{$i18n.t('Overview')}</button
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
<hr class=" my-2 dark:border-gray-850" />
|
|
||||||
|
|
||||||
<div class="px-6">
|
|
||||||
<div class="mt-0.5 mb-3 gap-1 flex flex-col md:flex-row justify-between">
|
<div class="mt-0.5 mb-3 gap-1 flex flex-col md:flex-row justify-between">
|
||||||
<div class="flex md:self-center text-lg font-medium px-0.5">
|
<div class="flex md:self-center text-lg font-medium px-0.5">
|
||||||
{$i18n.t('All Users')}
|
{$i18n.t('All Users')}
|
||||||
@ -206,11 +163,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="scrollbar-hidden relative overflow-x-auto whitespace-nowrap">
|
<div class="scrollbar-hidden relative whitespace-nowrap overflow-x-auto max-w-full">
|
||||||
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 table-auto">
|
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 table-auto max-w-full">
|
||||||
<thead
|
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-850 dark:text-gray-400">
|
||||||
class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-850 dark:text-gray-400"
|
|
||||||
>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="px-3 py-2"> {$i18n.t('Role')} </th>
|
<th scope="col" class="px-3 py-2"> {$i18n.t('Role')} </th>
|
||||||
<th scope="col" class="px-3 py-2"> {$i18n.t('Name')} </th>
|
<th scope="col" class="px-3 py-2"> {$i18n.t('Name')} </th>
|
||||||
@ -362,9 +317,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Pagination bind:page count={users.length} />
|
<Pagination bind:page count={users.length} />
|
||||||
</div>
|
{/if}
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.font-mona {
|
.font-mona {
|
||||||
|
Loading…
Reference in New Issue
Block a user