open-webui/src/lib/components/admin/Evaluations.svelte

97 lines
3.2 KiB
Svelte
Raw Normal View History

2024-11-13 07:14:25 +00:00
<script>
import { getContext, tick, onMount } from 'svelte';
2024-10-24 07:00:49 +00:00
import { toast } from 'svelte-sonner';
2024-11-13 07:14:25 +00:00
import Leaderboard from './Evaluations/Leaderboard.svelte';
import Feedbacks from './Evaluations/Feedbacks.svelte';
2024-10-22 10:16:48 +00:00
2024-11-13 07:14:25 +00:00
import { getAllFeedbacks } from '$lib/apis/evaluations';
2024-10-23 03:14:10 +00:00
2024-11-13 07:14:25 +00:00
const i18n = getContext('i18n');
2024-10-23 07:51:27 +00:00
2024-11-13 07:14:25 +00:00
let selectedTab = 'leaderboard';
2024-10-24 05:35:12 +00:00
let loaded = false;
2024-11-13 07:14:25 +00:00
let feedbacks = [];
2024-10-26 04:17:47 +00:00
onMount(async () => {
feedbacks = await getAllFeedbacks(localStorage.token);
loaded = true;
2024-10-23 08:05:45 +00:00
2024-11-13 07:14:25 +00:00
const containerElement = document.getElementById('users-tabs-container');
if (containerElement) {
containerElement.addEventListener('wheel', function (event) {
if (event.deltaY !== 0) {
// Adjust horizontal scroll position based on vertical scroll
containerElement.scrollLeft += event.deltaY;
}
});
}
2024-10-22 10:16:48 +00:00
});
</script>
{#if loaded}
2024-11-13 07:14:25 +00:00
<div class="flex flex-col lg:flex-row w-full h-full -mt-0.5 pb-2 lg:space-x-4">
<div
id="users-tabs-container"
class="tabs flex flex-row overflow-x-auto gap-2.5 max-w-full lg:gap-1 lg:flex-col lg:flex-none lg:w-40 dark:text-gray-200 text-sm font-medium text-left scrollbar-none"
>
<button
class="px-0.5 py-1 min-w-fit rounded-lg lg:flex-none flex text-right transition {selectedTab ===
'leaderboard'
? ''
: ' text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'}"
on:click={() => {
selectedTab = 'leaderboard';
}}
2024-10-23 03:14:10 +00:00
>
2024-11-13 07:14:25 +00:00
<div class=" self-center mr-2">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="size-4"
>
<path
d="M8.5 4.5a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0ZM10.9 12.006c.11.542-.348.994-.9.994H2c-.553 0-1.01-.452-.902-.994a5.002 5.002 0 0 1 9.803 0ZM14.002 12h-1.59a2.556 2.556 0 0 0-.04-.29 6.476 6.476 0 0 0-1.167-2.603 3.002 3.002 0 0 1 3.633 1.911c.18.522-.283.982-.836.982ZM12 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z"
/>
</svg>
</div>
2024-11-13 07:14:25 +00:00
<div class=" self-center">{$i18n.t('Leaderboard')}</div>
</button>
<button
class="px-0.5 py-1 min-w-fit rounded-lg lg:flex-none flex text-right transition {selectedTab ===
'feedbacks'
? ''
: ' text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'}"
on:click={() => {
selectedTab = 'feedbacks';
}}
2024-10-23 03:14:10 +00:00
>
2024-11-13 07:14:25 +00:00
<div class=" self-center mr-2">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="size-4"
2024-10-26 04:17:47 +00:00
>
2024-11-13 07:14:25 +00:00
<path
d="M8 8a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM3.156 11.763c.16-.629.44-1.21.813-1.72a2.5 2.5 0 0 0-2.725 1.377c-.136.287.102.58.418.58h1.449c.01-.077.025-.156.045-.237ZM12.847 11.763c.02.08.036.16.046.237h1.446c.316 0 .554-.293.417-.579a2.5 2.5 0 0 0-2.722-1.378c.374.51.653 1.09.813 1.72ZM14 7.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM3.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM5 13c-.552 0-1.013-.455-.876-.99a4.002 4.002 0 0 1 7.753 0c.136.535-.324.99-.877.99H5Z"
/>
</svg>
</div>
<div class=" self-center">{$i18n.t('Feedbacks')}</div>
</button>
2024-10-26 04:17:47 +00:00
</div>
2024-10-23 06:24:49 +00:00
2024-11-13 07:14:25 +00:00
<div class="flex-1 mt-1 lg:mt-0 overflow-y-scroll">
{#if selectedTab === 'leaderboard'}
<Leaderboard {feedbacks} />
{:else if selectedTab === 'feedbacks'}
<Feedbacks {feedbacks} />
{/if}
2024-10-24 07:00:49 +00:00
</div>
2024-11-13 07:14:25 +00:00
</div>
2024-10-22 10:16:48 +00:00
{/if}