enh: admin models
This commit is contained in:
1 parent
fa84ff5e12
commit
96a9696383
2 files changed
+166
-14
No files matched your search
@@ -40,6 +40,10 @@
|
|||||||
import Eye from '$lib/components/icons/Eye.svelte';
|
import Eye from '$lib/components/icons/Eye.svelte';
|
||||||
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
import { DropdownMenu } from 'bits-ui';
|
||||||
|
import { flyAndScale } from '$lib/utils/transitions';
|
||||||
|
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
||||||
|
import AdminViewSelector from './Models/AdminViewSelector.svelte';
|
||||||
|
|
||||||
let shiftKey = false;
|
let shiftKey = false;
|
||||||
|
|
||||||
@@ -58,21 +62,43 @@
|
|||||||
let showConfigModal = false;
|
let showConfigModal = false;
|
||||||
let showManageModal = false;
|
let showManageModal = false;
|
||||||
|
|
||||||
|
let viewOption = ''; // '' = All, 'enabled', 'disabled', 'visible', 'hidden'
|
||||||
|
|
||||||
$: if (models) {
|
$: if (models) {
|
||||||
filteredModels = models
|
filteredModels = models
|
||||||
.filter((m) => searchValue === '' || m.name.toLowerCase().includes(searchValue.toLowerCase()))
|
.filter((m) => searchValue === '' || m.name.toLowerCase().includes(searchValue.toLowerCase()))
|
||||||
|
.filter((m) => {
|
||||||
|
if (viewOption === 'enabled') return m?.is_active ?? true;
|
||||||
|
if (viewOption === 'disabled') return !(m?.is_active ?? true);
|
||||||
|
if (viewOption === 'visible') return !(m?.meta?.hidden ?? false);
|
||||||
|
if (viewOption === 'hidden') return m?.meta?.hidden === true;
|
||||||
|
return true; // All
|
||||||
|
})
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
// // Check if either model is inactive and push them to the bottom
|
|
||||||
// if ((a.is_active ?? true) !== (b.is_active ?? true)) {
|
|
||||||
// return (b.is_active ?? true) - (a.is_active ?? true);
|
|
||||||
// }
|
|
||||||
// If both models' active states are the same, sort alphabetically
|
|
||||||
return (a?.name ?? a?.id ?? '').localeCompare(b?.name ?? b?.id ?? '');
|
return (a?.name ?? a?.id ?? '').localeCompare(b?.name ?? b?.id ?? '');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let searchValue = '';
|
let searchValue = '';
|
||||||
|
|
||||||
|
const enableAllHandler = async () => {
|
||||||
|
const modelsToEnable = filteredModels.filter((m) => !(m.is_active ?? true));
|
||||||
|
// Optimistic UI update
|
||||||
|
modelsToEnable.forEach((m) => (m.is_active = true));
|
||||||
|
models = models;
|
||||||
|
// Sync with server
|
||||||
|
await Promise.all(modelsToEnable.map((model) => toggleModelById(localStorage.token, model.id)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const disableAllHandler = async () => {
|
||||||
|
const modelsToDisable = filteredModels.filter((m) => m.is_active ?? true);
|
||||||
|
// Optimistic UI update
|
||||||
|
modelsToDisable.forEach((m) => (m.is_active = false));
|
||||||
|
models = models;
|
||||||
|
// Sync with server
|
||||||
|
await Promise.all(modelsToDisable.map((model) => toggleModelById(localStorage.token, model.id)));
|
||||||
|
};
|
||||||
|
|
||||||
const downloadModels = async (models) => {
|
const downloadModels = async (models) => {
|
||||||
let blob = new Blob([JSON.stringify(models)], {
|
let blob = new Blob([JSON.stringify(models)], {
|
||||||
type: 'application/json'
|
type: 'application/json'
|
||||||
@@ -308,8 +334,12 @@
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class=" flex flex-1 items-center w-full space-x-2">
|
<div
|
||||||
|
class="py-2 bg-white dark:bg-gray-900 rounded-3xl border border-gray-100/30 dark:border-gray-850/30"
|
||||||
|
>
|
||||||
|
<div class="px-3.5 flex flex-1 items-center w-full space-x-2 py-0.5 pb-2">
|
||||||
<div class="flex flex-1 items-center">
|
<div class="flex flex-1 items-center">
|
||||||
<div class=" self-center ml-1 mr-3">
|
<div class=" self-center ml-1 mr-3">
|
||||||
<Search className="size-3.5" />
|
<Search className="size-3.5" />
|
||||||
@@ -333,13 +363,63 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="px-3 flex w-full items-center bg-transparent overflow-x-auto scrollbar-none">
|
||||||
|
<div
|
||||||
|
class="flex gap-0.5 w-fit text-center text-sm rounded-full bg-transparent whitespace-nowrap"
|
||||||
|
>
|
||||||
|
<AdminViewSelector bind:value={viewOption} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class=" my-2 mb-5" id="model-list">
|
<div class="flex-1"></div>
|
||||||
{#if models.length > 0}
|
|
||||||
|
<Dropdown>
|
||||||
|
<Tooltip content={$i18n.t('Actions')}>
|
||||||
|
<button
|
||||||
|
class="p-1 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<EllipsisHorizontal className="size-4" />
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<div slot="content">
|
||||||
|
<DropdownMenu.Content
|
||||||
|
class="w-full max-w-[170px] rounded-xl p-1 border border-gray-100 dark:border-gray-800 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-sm"
|
||||||
|
sideOffset={-2}
|
||||||
|
side="bottom"
|
||||||
|
align="end"
|
||||||
|
transition={flyAndScale}
|
||||||
|
>
|
||||||
|
<DropdownMenu.Item
|
||||||
|
class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
||||||
|
on:click={() => {
|
||||||
|
enableAllHandler();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Eye className="size-4" />
|
||||||
|
<div class="flex items-center">{$i18n.t('Enable All')}</div>
|
||||||
|
</DropdownMenu.Item>
|
||||||
|
|
||||||
|
<DropdownMenu.Item
|
||||||
|
class="flex gap-2 items-center px-3 py-1.5 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
||||||
|
on:click={() => {
|
||||||
|
disableAllHandler();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<EyeSlash className="size-4" />
|
||||||
|
<div class="flex items-center">{$i18n.t('Disable All')}</div>
|
||||||
|
</DropdownMenu.Item>
|
||||||
|
</DropdownMenu.Content>
|
||||||
|
</div>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="px-3 my-2" id="model-list">
|
||||||
|
{#if filteredModels.length > 0}
|
||||||
{#each filteredModels as model, modelIdx (`${model.id}-${modelIdx}`)}
|
{#each filteredModels as model, modelIdx (`${model.id}-${modelIdx}`)}
|
||||||
<div
|
<div
|
||||||
class=" flex space-x-4 cursor-pointer w-full px-3 py-2 dark:hover:bg-white/5 hover:bg-black/5 rounded-lg transition {model
|
class=" flex space-x-4 cursor-pointer w-full px-3 py-2 dark:hover:bg-white/5 hover:bg-black/5 rounded-xl transition {model
|
||||||
?.meta?.hidden
|
?.meta?.hidden
|
||||||
? 'opacity-50 dark:opacity-50'
|
? 'opacity-50 dark:opacity-50'
|
||||||
: ''}"
|
: ''}"
|
||||||
@@ -366,7 +446,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class=" flex-1 self-center {(model?.is_active ?? true) ? '' : 'text-gray-500'}">
|
<div
|
||||||
|
class=" flex-1 self-center {(model?.is_active ?? true) ? '' : 'text-gray-500'}"
|
||||||
|
>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={marked.parse(
|
content={marked.parse(
|
||||||
!!model?.meta?.description
|
!!model?.meta?.description
|
||||||
@@ -462,7 +544,9 @@
|
|||||||
|
|
||||||
<div class="ml-1">
|
<div class="ml-1">
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={(model?.is_active ?? true) ? $i18n.t('Enabled') : $i18n.t('Disabled')}
|
content={(model?.is_active ?? true)
|
||||||
|
? $i18n.t('Enabled')
|
||||||
|
: $i18n.t('Disabled')}
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
bind:state={model.is_active}
|
bind:state={model.is_active}
|
||||||
@@ -477,13 +561,18 @@
|
|||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
<div class="flex flex-col items-center justify-center w-full h-20">
|
<div class=" w-full h-full flex flex-col justify-center items-center my-16 mb-24">
|
||||||
<div class="text-gray-500 dark:text-gray-400 text-xs">
|
<div class="max-w-md text-center">
|
||||||
{$i18n.t('No models found')}
|
<div class=" text-3xl mb-3">😕</div>
|
||||||
|
<div class=" text-lg font-medium mb-1">{$i18n.t('No models found')}</div>
|
||||||
|
<div class=" text-gray-500 text-center text-xs">
|
||||||
|
{$i18n.t('Try adjusting your search or filter to find what you are looking for.')}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{#if $user?.role === 'admin'}
|
{#if $user?.role === 'admin'}
|
||||||
<div class=" flex justify-end w-full mb-3">
|
<div class=" flex justify-end w-full mb-3">
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Select } from 'bits-ui';
|
||||||
|
import { getContext } from 'svelte';
|
||||||
|
|
||||||
|
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
|
||||||
|
import Check from '$lib/components/icons/Check.svelte';
|
||||||
|
|
||||||
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
export let value = '';
|
||||||
|
export let placeholder = $i18n.t('Select view');
|
||||||
|
export let onChange: (value: string) => void = () => {};
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
{ value: '', label: $i18n.t('All') },
|
||||||
|
{ value: 'enabled', label: $i18n.t('Enabled') },
|
||||||
|
{ value: 'disabled', label: $i18n.t('Disabled') },
|
||||||
|
{ value: 'visible', label: $i18n.t('Visible') },
|
||||||
|
{ value: 'hidden', label: $i18n.t('Hidden') }
|
||||||
|
];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Select.Root
|
||||||
|
selected={items.find((item) => item.value === value)}
|
||||||
|
{items}
|
||||||
|
onSelectedChange={(selectedItem) => {
|
||||||
|
value = selectedItem.value;
|
||||||
|
onChange(value);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Select.Trigger
|
||||||
|
class="relative w-full flex items-center gap-0.5 px-2.5 py-1.5 bg-gray-50 dark:bg-gray-850 rounded-xl"
|
||||||
|
aria-label={placeholder}
|
||||||
|
>
|
||||||
|
<Select.Value
|
||||||
|
class="inline-flex h-input px-0.5 w-full outline-hidden bg-transparent truncate placeholder-gray-400 focus:outline-hidden"
|
||||||
|
{placeholder}
|
||||||
|
/>
|
||||||
|
<ChevronDown className="size-3.5" strokeWidth="2.5" />
|
||||||
|
</Select.Trigger>
|
||||||
|
|
||||||
|
<Select.Content
|
||||||
|
class="rounded-2xl min-w-[170px] p-1 border border-gray-100 dark:border-gray-800 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-lg"
|
||||||
|
sameWidth={false}
|
||||||
|
align="start"
|
||||||
|
>
|
||||||
|
{#each items as item}
|
||||||
|
<Select.Item
|
||||||
|
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
|
||||||
|
value={item.value}
|
||||||
|
label={item.label}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
|
||||||
|
{#if value === item.value}
|
||||||
|
<div class="ml-auto">
|
||||||
|
<Check />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</Select.Item>
|
||||||
|
{/each}
|
||||||
|
</Select.Content>
|
||||||
|
</Select.Root>
|
||||||
Reference in new issue
Block a user